Jump to content
  • Advertisement
Sign in to follow this  
hardy_dev

HLSL tex add float range problem

This topic is 2922 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

I want make a texture add a small value from black until white.
but I found a float problem, if the add value is above 0.0021 , like 0.0022 , it will add to white, if less or equl 0.0021f , it will not add, it seams be to zero.

float4 reducePS(QuadVertexOutput IN
) : COLOR
{

float4 cur = tex2D(PaintSamp,IN.UV.xy);
cur = cur + 0.0021f;
return cur;
}

pass dispear <
string Script =
"RenderColorTarget0=PaintTex;"
"RenderDepthStencilTarget=DepthStencilTarget;"
"Draw=Buffer;";
> {
VertexShader = compile vs_1_1 ScreenQuadVS();
PixelShader = compile ps_3_0 reducePS();
AlphaBlendEnable = false;
ZEnable = false;
}

Share this post


Link to post
Share on other sites
Advertisement
In most cases your pixel shader output will be converted to the render target format before being blended. This means for 8-bit fixed point formats (A8R8G8B8) the value will be converted to [0, 1] range and quantized (multiplied by 255). So in your case 0.0021 * 255 is less than one, which means when quantized it will come out to 0.0022 is probably just high enough for the hardware to convert it to 1.

Also you should know that it's invalid to use vs_1_1 or vs_2_0 vertex shaders with ps_3_0 pixel shaders. Some drivers allow it, some don't. Either way the debug runtimes will complain.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!