HLSL tex add float range problem

Started by
1 comment, last by hardy_dev 13 years, 4 months ago
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;
}
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.
thanks , at last I use D3DFMT_A32B32G32R32F to fix this, before that I use D3DFMT_A8.

This topic is closed to new replies.

Advertisement