locked
Why isn't TEXCOORD normalized to [0,1] range

    Question

  • I use the following pixel shader hlsl code to display the TEXCOORD range.

    The result shows that the TEXCOORD is wrapping from 0 to 1 then 0 to 1 .... over and over. Is it supposed to be normalized to [0,1] range? (take x for example, 0 is the left edge and 1 is the right edge.) If TEXCOORD is supposed to be rotating this way, what's the best way to decide the center of the image in the pixel shader?

    The test is done on windows 8. I reported in another thread but I think it's worth starting a new one.

    Thanks for your help in advance!

        float4 main(
        float4 pos      : SV_POSITION,
        float4 posScene : SCENE_POSITION,
    		float4 uv0 : TEXCOORD0
    	) : SV_Target
        {
           float4 color = float4(uv0.x, uv0.y, 0, 1);
    		return color;
        }
    (a screenshot is not allowed, you can see it on my avatar or my blog http://yingxiongblog.wordpress.com/2012/10/27/why-isnt-texcoord-normalized-to-01/ )




    • Edited by ying.xiong Friday, October 26, 2012 11:24 PM
    Friday, October 26, 2012 5:14 PM

Answers

All replies

  • Hi,

    No. Of course textures coordinates does not have be normalized between [0, 1]. 

    It is the sampler that set the coordinates between [0,1]  (using warp, clamp, mirror or border) to get a texel.

    Sunday, October 28, 2012 10:04 AM
  • Léna, Thanks for the information. But I still don't understand how this works. I guess that a big bitmap source input is cut into smaller tiles when sampling, so texture coordinates is only normalized for each small tile.

    If this is the case, many examples I found on the web make no sense.

    For example, I see a HLSL example using (0.5,0.5) as the center of the image to calculate the distance-to-center when rendering the vignette effect. If (0.5,0.5) isn't the center, how would I decide the position of the  "center" ?

    Another example is scaling. If you want to double the image size by using something like below, black gaps are seen on the edge of each tiles.

    color = InputTexture.Sample(InputSampler, uv0/2);


    Another question is: In the official example, uv0.zw is used. What does uv0.zw mean in pixel shader code? 

    float2 uv2 = uv0.xy + (wave.x * falloff * amplitude) * direction * uv0.zw;

    Thanks a lot.

    Monday, October 29, 2012 10:29 AM
  • (1) TEXCOORDS are in 'u-v' space. The meaning of values larger than 1.0 or less than 0.0 depends on your the Sampler mode as noted above. You probably want to read these (older) MSDN articles

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb206245(v=vs.85).aspx

    http://msdn.microsoft.com/en-us/library/windows/desktop/cc308049(v=vs.85).aspx

    (2) That's the HLSL 'swizzle' syntax.

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb219869(v=vs.85).aspx

    Wednesday, October 31, 2012 1:21 AM
  • Thanks for sharing these helpful links!
    Thursday, November 1, 2012 9:35 AM