Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

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

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.