Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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

share|improve this question
Have you tried changing your math to accommodate 0 being the minimum and 1 being the maximum? – UnderscoreZero Jun 28 '13 at 17:44

Why are the values clamped to 0-1? Because in non HDR rendering all pixel values are 0-1. If you want values outside that range, you need HDR rendering. That will, of course, scale the values across the whole render to fit 0-1 using fancy math, which lets the brightest brights be brighter than their surroundings without being clipped (e.g. an area being solid white or black with no definition).

In the end though, pixel values must be between 0 and 1 (inclusive) because that's the maximum displayable value.

share|improve this answer
Do you even have the slightest clue what he's talking about? He's not trying to display the image. It's just a data table that contains 32-bit floats. There is nothing at all wrong with what he's doing conceptually. Pixel values do not have to be between 0 and 1 because pixel values do not have to be displayed. – Nicol Bolas Dec 14 '15 at 20:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.