• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
dssannyasi

Vertex Shader Clamps 0-1... Need float!

4 posts in this topic

I have written a point cloud viewer using slimdx and directx 9.

We use it to visualize and render images from some content creation software we're building here.

Currently my renderer can display points and polys. The main purpose is to render EXR files with color and zDepth (floating point values > 1) information in the alpha.

 

My render target is 32bit float, and I dump the framebuffer to an exr file.

When rendering polys it works perfectly, I just calculate the color of the pixel shader like this (hlsl).    

 

color = Input.color;
color.w = distance(Input.Position, cameraPosition),

 

    and I get values in real world units away from the camera. So if a object is 1000 units away the alpha of the exr shows 1000 for that pixel's raw value;

 

 

 

Now I'm trying to render just the vertices of point clouds using a vertex shader with the same calculation as above. But my depth values clamp themselves to a value of 1.

 

If I change the above code to    

 

color = Input.color;
color.w = (distance(Input.Position, cameraPosition) - near) / far;

(near and far are my camera clipping distances)    This scales the depth values into the 0-1 range and they output this way, but I need greater precision and real world units!

 

Is there a limitation on vertex shaders that won't allow these kinds of floating point operations?

 

Thanks

0

Share this post


Link to post
Share on other sites

[quote name='dssannyasi' timestamp='1358296478' post='5021984']
Is there a limitation on vertex shaders that won't allow these kinds of floating point operations?
[/quote]No.

What kind of variable is color in your vertex shader?

0

Share this post


Link to post
Share on other sites

If you're using the color semantic, try switching it to TexCoord. On certain cards the color gets clamped from 0-1.

0

Share this post


Link to post
Share on other sites

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

 

0

Share this post


Link to post
Share on other sites

From shader-model 3.0 an onwards, you can't just use a vertex-shader by itself, it always needs to be paired with a pixel shader.

In your case, where you're not supplying your own pixel shader (and using shader-model 2.0), you're asking the driver to automatically write one for you and I wouldn't trust it to do the right thing, especially when it comes to advanced features like floating-point render targets.

 

Anyway, as Dancin_Fool said, the issue is that you're trying to pass your floating-point value through a colour register. As this page says: "Color registers ... have lower precision than most registers, guaranteed to have 8 bits of unsigned data in the range (0, +1)."

 

You should be using a tex-coord register to pass your floating point value to the pixel shader.

Edited by Hodgman
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0