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 implemented a simple deferred shading renderer. I use 3 G-Buffer for storing position (R32F), normal (G16R16F) and albedo (ARGB8). I use sphere map algorithm to store normals in world space. Currently I use inverse of view * projection matrix to calculate the position of each pixel from stored depth value.

  1. First I want to avoid per pixel matrix multiplication for calculating the position. Is there another way to store and calculate position in G-Buffer without the need of matrix multiplication
  2. Store the normal in view space

Every lighting in my engine is in world space and I want do the lighting in view space to speed up my lighting pass.

I want an optimized lighting pass for my deferred engine.

share|improve this question
    
I don't actually see a question here... store the positions and normals in view space and you're done? If you store the position in a separate buffer, I don't see why you would need a matrix multiplication? You can save a lot of memory band width by reconstructing the position from fragment coords and the depth buffer (at least if you use OpenGL, not sure what version of DirectX you need to be able to read the depth buffer as a texture). –  ccxvii Nov 19 '12 at 15:18
add comment

1 Answer 1

up vote 1 down vote accepted

For pixel positions, as mentioned in the comments, it's generally considered best to use the depth buffer and the pixel's 2D position on screen to calculate its view space or world space position. If you're using an older D3D/OpenGL API version you may need to store an extra copy of the depth in an R32F buffer (it's unclear to me if this is what you're doing now); but in more recent APIs you can read the actual depth buffer directly, saving yourself one G-buffer slot.

In any case, most of the position reconstruction math can be moved into the vertex shader or the CPU, with only a reciprocal and a madd in the fragment shader (the reciprocal is not needed if you're using a linear depth buffer). The details of how to do this are in this blog post.

share|improve this answer
    
Thanks for the link finally I store the camera ray distant in my depth map and every thing works fine now. –  kochol Dec 18 '12 at 12:54
    
Could you give me a keyword to find out how to read the depth buffer directly in newer OpenGL? I want to do that but couldn't find the needed functions. –  danijar May 14 '13 at 8:53
    
I'm not an OpenGL expert, but I think you might need to create an FBO and attach a texture created using one of the depth formats. –  Nathan Reed May 14 '13 at 17:10
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.