Jump to content

  • Log In with Google      Sign In   
  • Create Account


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();
    }
}

 


In Topic: SlimDX - No depth sorting on a render target

26 October 2010 - 03:29 PM

Thank you for that... It had something to do with my depthStencil,
The veiwport must have been making it for me automatically but the render target wasn't...
Now I'm issuing
device.DepthStencilSurface = Surface.CreateDepthStencil()
Format seems to be very picky here... im using D32.singleLockable and its working on my card..

Interesting thing now is I'm writing directly to openEXR from my depthStencil and its working properly, but now the viewport is having the same problem the render used to have (unsorted)... do I need to make both targets ( gui window and renderTarget) use the same depth, Right now its either one or the other?


Thanks again.

In Topic: Z Depth Error (order vs distance)

22 July 2010 - 12:49 PM

MJP

Thanks for the reply.

I wanted to avoid posting all the code to simplify what others would have to read through, (that and it is pretty ugly code, since i'm just learning :) )

1. zWrites are enabled just omitted from my post
2. This is run just before my draw code so if the renderFrame bool is triggered the renderTarget changes and the frame draws as it would in the viewport, but to the renderSurface.
if (ui.renderFrame)
{
device.SetRenderTarget(0, renderSurface);
}
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, globals.bgColor, 1.0f, 0);
device.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse;
device.SetRenderState(RenderState.ZEnable, true);
device.SetRenderState(RenderState.ZWriteEnable, true);
device.BeginScene();








3. As for #3 i've tried many combination's of formats sampling ect.
I've enabled autoDepthStencil, and AutoDepthStencilFormat. Most modes I've found don't work..(fails on device = () ) the ones that do work however still output the same (wrong) depth.
Instead of Surface.CreateRenderTarget(), I've tried Surface.CreateDepthStencil()
But calling device.setRenderTarget to that surface fails.


I've uploaded a comparison image showing my problem. Print screen from the viewport is on the left, output render is on the right, (color shift is from tone mapping the image to account for the float values).

The ball was made using the sphere primitive from maya > exporting the points position as Vector3[] and generating voxels at those positions. The order in which it is rendering is the same point order as the primitive in maya.
even the grid who's draw call happens first is under all of the voxels with no regard for zdepth.

Viewport vs Render

PARTNERS