Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

dssannyasi

Member Since 22 Jul 2010
Offline Last Active Jan 16 2013 02:51 AM
-----

Posts I've Made

In Topic: Vertex Shader Clamps 0-1... Need float!

15 January 2013 - 08:39 PM

Thanks for the responses... I was writing this up and found the issue and have resolved it... still not certain why its an issue.. maybe the clamping issue you spoke of "Dancin Fool"... I've included the shaders I was using incase anyone is able to give me any more insight.


While writing this post I saw the differences in my shaders in the use of the depth : TEXCOORD0 parameter in the struct and being used in the poly shader.
For the point clouds I figured since I only need points I shouldn't use a pixel shader thats why the 2nd shader only uses a vertexShader.

I've switch the struct used to the one in the poly shader and added the same pixelShader and now I have proper depth.

As a test I also tried switching the poly shader to write to color.w in the vertex shader and left out the color.w = depth from the pixelShader, and sure enough even the polys were then clamped at 1.

Any one know why this extra step is necessary?, Why can't a vertex Shader write floating values to the screen? And does the VertexFormat used while passing the draw codes matter once the data is pushed to the gfxCard? (I would think not since my VertexFormat Struct in Slimdx doesn't even have texture coordinates in the first place)

Thanks



Here is the Pixel shader (This works on polys).

float4x4 WVP;
float4 camPos;
float near;
float far;

/////// STRUCTS ////////////////////////////////////////////

struct VS_INPUT
{
float4 Color : COLOR0;
float4 Position : POSITION0;
};


struct VS_OUTPUT
{
float4 Color : COLOR0;
float4 Position : POSITION0;
float Depth : TEXCOORD0;
};


//// SHADER  ///////////////////////////////////////////////

VS_OUTPUT VS( VS_INPUT Input )
{
    VS_OUTPUT Output;

    Output.Position = mul( Input.Position, WVP );
    Output.Color = Input.Color;
    Output.Depth = distance(Input.Position, camPos);
    return( Output );
}

float4 PS(VS_OUTPUT input) : COLOR0
{
    float4 Color = input.Color;
    Color.w = input.Depth;
    return (Color);
}


////// Techniques   /////////////////////////////////////////

technique depthRaw
{
    pass Pass0
    {   
        VertexShader = compile vs_2_0 VS();
        PixelShader  = compile ps_2_0 PS();
    }
}

 


Here's the Vertex Shader... (clamps 0-1)

 

 

float4x4 WVP;
float4 camPos;
float near;
float far;

/////// STRUCTS ////////////////////////////////////////////

struct VS_INPUT
{
    float4 Color : COLOR0;
    float4 Position : POSITION0;
};


struct VS_OUTPUT
{
    float4 Color : COLOR0;
    float4 Position : POSITION0;
};


//// SHADERS  //////////////////////////////////////////////




VS_OUTPUT VS( VS_INPUT Input)
{
    VS_OUTPUT Output;


    Output.Position = mul( Input.Position, WVP );

    Output.Color = Input.Color;
    //Output.Color.w = distance(Input.Position, camPos);               // NEED THIS TO WORK
    Output.Color.w = (distance(Input.Position, camPos) - near) / far;  // THIS IS WORKAROUND
    return(Output);
}

////// Techniques   /////////////////////////////////////////


technique pointDepth
{
    pass Pass0
    {   
        VertexShader = compile vs_2_0 VS();
    }
}

 


PARTNERS