3

I have YUV to RGB conversion shader.

struct Pixel_INPUT
{
    float4 pos  : SV_POSITION;
    float2 tex  : TEXCOORD0;
};

Texture2D textureY : register(t0);
Texture2D textureU : register(t1);
Texture2D textureV : register(t2);

SamplerState samstate
{
    MinFilter     = Anisotropic;
    MagFilter     = Anisotropic;
AddressU = Clamp;
AddressV = Clamp;
};

float4 PS(Pixel_INPUT input) : SV_Target
{
    float y = (1.1643f * textureY.Sample(samstate,input.tex) - 0.0625f);
    float u = textureU.Sample(samstate,input.tex) - 0.5f;
    float v = textureV.Sample(samstate,input.tex) - 0.5f;

   float r = y + 1.5958f * v;
   float g = y - 0.39173f * u - 0.81290f * v;
   float b = y + 2.017f * u;

   return float4(r,g,b,1);
}

But I have a green line at right side of image like that: enter image description here

I use Clamp address mode and image is more yellow color than the original.

mrvux
  • 8,523
  • 1
  • 27
  • 61
Alatriste
  • 527
  • 2
  • 6
  • 21
  • Aren't pixel centres 0,0 in D3D? – Robinson Mar 22 '15 at 17:33
  • in D3D10 are 0.5 , 0.5 https://msdn.microsoft.com/en-us/library/windows/desktop/cc308049%28v=vs.85%29.aspx – Alatriste Mar 22 '15 at 17:37
  • do you have any idea? – Alatriste Mar 22 '15 at 18:34
  • Perhaps more info needed. Why is your picture a picture of the desktop? – Robinson Mar 22 '15 at 19:05
  • I converted this image by some RGB to YUV tool and now I want to check my YUV to RGB shader. do you see any mistake in my pixel shader? – Alatriste Mar 22 '15 at 19:55
  • 1
    This is clearly HLSL, what's with all the tags? – Andon M. Coleman Mar 22 '15 at 20:17
  • can you answer on my question? – Alatriste Mar 22 '15 at 20:19
  • No, you have not given enough information. While it is true that the coordinate range **[0.0, 1.0]** will sample off texel centers and that will mess with texture interpolation, it should actually be less of an issue at the edges than elsewhere given the clamp address mode. It's very unlikely that switching to point sampling, or correctly adjusting your texture coordinates will change anything (unless your Y, U and V resolution are different). – Andon M. Coleman Mar 22 '15 at 20:25
  • The problem is indeed unlikely to be in the shader. Please show the code that uses the shader (with position and texture coordinates) – Bahbar Mar 22 '15 at 20:34
  • As a side note for yuv->rgb you don't need a sampler, Load with allow you to do get exact pixel coordinate instead. Also since Y is twice the resolution, and you use input.tex everywhere, you are likely also to sample in the wrong locations. – mrvux Apr 15 '15 at 15:58

2 Answers2

1

I have sampler state

  samplerDesc.Filter   = D3D10_FILTER_ANISOTROPIC;
  samplerDesc.AddressU  = D3D10_TEXTURE_ADDRESS_MIRROR;
  samplerDesc.AddressV   = D3D10_TEXTURE_ADDRESS_MIRROR;
  samplerDesc.AddressW    = D3D10_TEXTURE_ADDRESS_MIRROR;
  samplerDesc.MaxAnisotropy = 8;
  samplerDesc.ComparisonFunc = D3D10_COMPARISON_NEVER;


   pDevice->CreateSamplerState(&samplerDesc,&SampState);

About Y U and V textures resolution: U and V textures resolutions always are half of Y resolution.

Alatriste
  • 527
  • 2
  • 6
  • 21
0

I'll assume (since you use a tri planar version for YUV) that your FourCC is I420 as described here

Since SV_Position gives you the exact pixel coordinates, you can avoid using a Sampler (which should technically be in Point mode for this type of operations).

Here is a simple example to load your data in you use case (please note I only provide the loading code, not the conversion itself).

struct Pixel_INPUT
{
    float4 pos  : SV_POSITION;
    float2 tex  : TEXCOORD0;
};

Texture2D textureY : register(t0);
Texture2D textureU : register(t1);
Texture2D textureV : register(t2);

float4 PS(Pixel_INPUT input) : SV_Target
{
    int3 pixelLocation = int3(input.pos.xy, 0)); //0 is miplevel

    //Get y component
    float y = textureY.Load(pixelLocation).r;

    //now since u and v are half resolution, we need to divide location by 2
    pixelLocation.xy /= 2;

    //Load our u and v components
    float u = textureU.Load(pixelLocation).r;
    float v = textureV.Load(pixelLocation).r;

    //Perform your conversion and return
}
mrvux
  • 8,523
  • 1
  • 27
  • 61