• Advertisement
Sign in to follow this  

HLSL pixel shader works with magic number (0.3333) but not with (1 / 3) why?

This topic is 1877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello,

trying to make a simple effect on a fullscreen triangle (triangle generated on the vertex shader using SV_VertexID) and on the pixel shader im trying color the triangle depending on its text coords (that is also generated on the vertex shader).

when i compare uv.x or uv.y with a magic number (like 0.3333 for example) it works just fine but when i use generic values (like 1 / 3 instead of using 0.3333) it doesnt work.

this is a simple example that shows the problem:

[CODE]
struct VSOutput
{
float4 position : SV_POSITION; // screen space
float2 uv : TEXCOORD; // [0,1] coords
};


PSOutput PS(VSOutput input)
{
PSOutput output = (PSOutput)0;
float oneThird = 1 / 3;
float twoThird = 2 / 3;
float x = input.uv.x;

if(x < oneThird)
output.diffuse = float4(1.0, 0.0, 0.0, 1.0);
else if(x > twoThird)
output.diffuse = float4(0.0, 0.0, 1.0, 1.0);
else
output.diffuse = float4(0.0, 1.0, 0.0, 1.0);

return output;
}
[/CODE]

this outputs blue for the entire fullscreen triangle (meaning that only the "else if(x > twoThird)" test works) BUT if i change from "x < oneThird" and "x > twoThird" to "x < 0.3333" and "x > 0.6666" it outputs 3 color stripes and eveything works great.

conclusion: using 0.3333 instead of 1 / 3 and using 0.6666 instead of 2 / 3 works great, the other way around it doesnt work. is there something im missing?

thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
wow i cant believe i fell for that.. well thanks a lot for the help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement