Sign in to follow this  
hardy_dev

HLSL tex add float range problem

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this