我已经在像素着色器中将UYVY图像转换为RGB,并且渲染到目标的RGB位图纹理在宽度和高度上都损失了一个像素。
我已经尝试过是否是视口问题。渲染视口之前,前四个浮点(TopLeftX,TopLeftY,宽度,高度)为(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 x576。但是图像显示为767 x575。黑色边框的一个像素在向图像渲染以及渲染时在右侧和底部显示。一个像素边框为黑色,因为我最初用黑色清除了目标视图。
如果任何人都可以指出我应该去哪里解决此问题,这将对我有所帮助。
更新:
输入布局:
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;
}
答案 0 :(得分:0)
由于出现半像素问题DirectX 9 needed an offset,因此无法在视口内调整图形。该偏移量是看起来像在DirectX更高版本的DirectX 11 implementation as it's solved中从视口向左右缩放1个像素的原因。因此,背景颜色看起来像一个1像素的边框。如果我们取消应用偏移量,则边框将不再存在。