Writing to a D3DFMT_R32F render target clamps to 1
- by Mike
I'm currently implementing a picking system.
I render some objects in a frame buffer, which has a render target, which has the D3DFMT_R32F format.
For each mesh, I set an integer constant evaluator, which is its material index.
My shader is simple: I output the position of each vertex, and for each pixel, I cast the material index in float, and assign this value to the Red channel:
int
ObjectIndex;
float4x4
WvpXf : WorldViewProjection< string UIWidget = "None"; >;
struct VS_INPUT
{
float3 Position : POSITION;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
};
struct PS_OUTPUT
{
float4 Color : COLOR0;
};
VS_OUTPUT VSMain( const VS_INPUT input )
{
VS_OUTPUT
output = (VS_OUTPUT)0;
output.Position = mul( float4(input.Position, 1), WvpXf );
return output;
}
PS_OUTPUT PSMain( const VS_OUTPUT input, in float2 vpos : VPOS )
{
PS_OUTPUT
output = (PS_OUTPUT)0;
output.Color.r = float( ObjectIndex );
output.Color.gba = 0.0f;
return output;
}
technique Default
{
pass P0
{
VertexShader = compile vs_3_0 VSMain();
PixelShader = compile ps_3_0 PSMain();
}
}
The problem I have, is that somehow, the values written in the render target are clamped between 0.0f and 1.0f.
I've tried to change the rendertarget format, but I always get clamped values...
I don't know what the root of the problem is.
For information, I have a depth render target attached to the frame buffer.
I disabled the blend in the render state
the stencil is disabled
Any ideas?