Screen Space

Cameras | Sunday 5 October 2008 12:10 pm

The last step of transformations (world to screen) when rendering is to get the rendered objects to screen space. This is a 2D space with the origin in the middle of the screen. After the vertex shader but before the fragment shader the fragments will be normalized device coordinates and will automatically be transformed to screen space. The fragments x,y coordinates will be mapped to the x and y coordinates on the screen (the exact mapping is set by viewportbounds). And the z coordinates will be mapped to the depth buffer (z-buffer) as the following [-1] -> [near clip plane limit] and [1] -> [far clip plane limit].

The viewport mapping is the following [-1,1] in X is mapped to the left to right of the viewport range. The [-1,1] in Y is mapped to the bottom to top of the viewport range

Framents will automatically be transformed to screen space before the fragment shader, you just need to set the viewport mapping with the following OpenGL call.

glViewport(0, screenHeight/2, screenWidth/2, screenHeight/2);

You can access the current fragment depth in a fragment shader with the variable gl_FragDepth which in default is the same as gl_FragCoord.z. The screen coordinates can be accessed in the variable gl_FragCoord.xy.

Information about pixel shaders in DirectX (most is the same in OpenGL):
http://www.gamedev.net/columns/hardcore/dxshader3/

A quick reference guide to GLSL:
http://www.opengl.org/sdk/libs/OpenSceneGraph/glsl_quickref.pdf

Description of the mapping in DirectX:
http://msdn.microsoft.com/en-us/library/bb219690.aspx

Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks

Screen Space Water

Water | Thursday 25 September 2008 9:00 pm

A nice and different approach to create water. It seems to work like a fog between a water plane and the geometry below (sea bottom).

Screen Space Water

And heres a link to the presentation of it

http://www.gamedev.net/community/forums/topic.asp?topic_id=482962&PageSize=25&WhichPage=1

Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks

Rendering normals in eye space

Rendering Methods | Thursday 25 September 2008 12:46 am

Here’s a simple shader for rendering the normals in a scene in eye space. This shader can be useful for debugging or then you want to do SSAO or edge detection. Below is a rendering of the normals of a sphere in eye space.

Normals in screen space

Vertex shader:

varying vec3 normal;
void main()
{
   gl_Position = ftransform();
   normal = gl_NormalMatrix * gl_Normal;
}

Fragment shader:

varying vec3 normal;
void main()
{
   gl_FragColor.rgb = normal;
}

If you want to save it in a RGB texture then you need to convert the normal to the 0..1 range with the following normal = (normal + 1.0) / 2.0 .

The same shader can be used to render the tangent or binormal in screen space too. Just switch the gl_Normal to your other input.

Please share:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Current
  • LinkedIn
  • Live
  • MySpace
  • Netvibes
  • StumbleUpon
  • Twitter
  • Reddit
  • Technorati
  • Yahoo! Bookmarks
« Previous Page