【问题标题】:My rendered image and render to texture loses exactly one pixel in both width and height我的渲染图像和渲染到纹理在宽度和高度上都损失了一个像素
【发布时间】:2019-08-31 13:24:39
【问题描述】:

我已经在像素着色器中将 UYVY 图像转换为 RGB,并且渲染目标到 RGB 位图的纹理在宽度和高度上都丢失了一个像素。

我试过是否是视口问题。在渲染视口之前,前四个浮动 (TopLeftX, TopLeftY, Width, Height)(0.0f, 0.0f, 768.0f, 576.0f)。我已经在着色器中检查了从 UYVY 到 RGB 的转换算法。如果着色器算法出现问题,图像将显示错误的像素像素数据,而事实并非如此。 但我担心我使用的采样器描述。我的采样器描述如下:

const D3D11_SAMPLER_DESC samplerDesc = {
            D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR,
            D3D11_TEXTURE_ADDRESS_WRAP, 
            D3D11_TEXTURE_ADDRESS_WRAP, 
            D3D11_TEXTURE_ADDRESS_WRAP,
            0, 1, D3D11_COMPARISON_NEVER,
            {0.0f, 0.0f, 0.0f, 0.0f}, 0, FLT_MAX };

我正在丢失一个像素宽度和一个像素高度。我转换后的图像目标为 768 x 576。但图像显示为 767 x 575。黑色边框的一个像素在渲染到图像和渲染时显示在右侧和底部。一个像素的边框是黑色的,因为我最初清除了黑色的目标视图。

如果有人能指出我应该在哪里解决这个问题,这对我会有帮助。

更新:

输入布局:

const std::array<D3D11_INPUT_ELEMENT_DESC, 2> PosTexMixVideoLayout =
{
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    }
};

输入结构:

struct VSPosTextOverlay
{
    float4 position : POSITION0;
    float2 texOverlay : TEXCOORD0;
    float2 texImage : TEXCOORD1;
};

struct VSPosVideoTexture
{
    float4 position : POSITION0;
    float2 texOverlay : TEXCOORD0;
    float2 texImage : TEXCOORD1;
};

像素着色器中的 UYVY 到 RGB 转换:

/// <summary>Function to convert Uyvy to Rgb.</summary>
/// <param name="texImage">The tex image.</param>
/// <returns>A float4 value of RGB.</returns>
/// <remarks>
/// This function converts the Uyvy data contained in the input X8R8G8B8 texture
/// to Rgb. For even pixels the luminance value .g ist used, for odd pixels .a.
///
///      Formula for color values in the range 0-255:
///      R = 1.164(Y-16) + 1.596(Cr-128)
///      G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
///      B = 1.164(Y-16) + 2.018(Cb-128)
///      Note that the color values returned from the texture sampler are
///      in the range 0-1.
/// </remarks>
static inline float4 Uyvy2Rgb(in float2 texImage)
{
    // check whether we render an odd or even pixel
    // odd == 0.0 for even and odd == 1.0 for odd pixels
    float odd = step(frac(texImage.x * halfWidth), 0.5f);

    float4 uyvyColor = float4(uyvyImageTexture.Sample(uyvyImageSampler, texImage));

    float y = lerp(uyvyColor.a, uyvyColor.g, odd);

    y = 1.164f * (y - 0.0625f);
    uyvyColor.r -= 0.5f;
    uyvyColor.b -= 0.5f;
    uyvyColor.r *= saturation;
    uyvyColor.b *= saturation;

    float4 rgbColor;
    rgbColor.a = 1.0f;
    rgbColor.r = y + 1.596f * uyvyColor.r;
    rgbColor.g = y - 0.813f * uyvyColor.r - 0.391f * uyvyColor.b;
    rgbColor.b = y + 2.018f * uyvyColor.b;
    return rgbColor;
}

【问题讨论】:

  • 为什么是黑色边框?你有黑色背景吗?
  • ...位图格式本质上是cstring数组吗?还是用 memcpy 构建的?
  • @Liton 在渲染之前我已经清除了黑色的目标。这就是为什么它是黑色的。
  • @l.k 位图数据是 BYTE 数组和像素位格式 32 BPP
  • 我的意思是几何体是用偏移量渲染的。

标签: c++ directx-11 render-to-texture


【解决方案1】:

由于半像素问题DirectX 9 needed an offset 调整视口内的绘图。该偏移量是在 DirectX 更高版本中从 DirectX 11 implementation as it's solved 中的视口向右和向左丢失 1 个像素的原因。因此,它看起来像一个 1 像素的背景色边框。如果我们取消应用偏移 - 边界将不再存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2022-01-13
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    相关资源
    最近更新 更多