1
votes

I'm new to hlsl. I'm trying to write a pixel shader that converts from RGB space to YIQ space (NTSC). The conversion process is fine, but I cannot seem to get the sampler and tex2D to return any colour besides that in the upper left of the texture. I know it has to be a stupid mistake, but googling has just made me more confused.

I have tried declaring a texture and linking it to the sampler2D with sampler_state, but that didn't seem to change anything. I'm using Ventuz, which runs DirectX 9 and Pixel Shader 3.0. I have a simple plane object with an image texture. I just want to be able to see the texture untouched after going through the shader so I can then try the conversion steps.

float4x4 WorldViewProjection : WORLDVIEWPROJECTION;

sampler2D TextureSampler : register( s0 );

float4 VS( float4 Position : POSITION ){
    return float4( mul( Position, WorldViewProjection ) );
}

float4 PS( float2 uv : TEXCOORD ) : COLOR
{
    float4 Colour = tex2D( TextureSampler, uv.xy );

    /* Perform colour space conversion steps */

    return YIQA;
}

technique Tech1
{
    pass pass0
    {
        vertexshader = compile vs_3_0 VS();
        pixelshader = compile ps_3_0 PS();
    }
}

What am I doing wrong?

1

1 Answers

3
votes

Your Vertex Shader doesn't output a "TEXCOORD" attribute, so the input to the Pixel Shader will be (0,0) for the 'uv' parameter, which is why you're only getting the top left hand corner sampled.

Try outputting a "float2 uv : TEXCOORD" and set the UV coordinates to be (0,0), (1,0), (1,1), (0,1) for the four corners of your screen quad in a clockwise direction from the top left hand corner.