# Why does writing to a D3DFMT_R32F render target clamp to 1?

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?

• Have you tried changing your math to accommodate 0 being the minimum and 1 being the maximum? – UnderscoreZero Jun 28 '13 at 17:44
• This is lost in an old no-longer-available DX SDK - it's because you're using the COLOR0 output semantic which automatically clamps in the 0 to 1 range. – Maximus Minimus Aug 28 '16 at 4:54