[quote name='Yours3!f' timestamp='1336564479' post='4938643']
Ashaman73 is correct, however you seem to be having trouble with the theory itself.
before reading take a look at this:
http://mynameismjp.w...n-from-depth-3/
namely method #2
Ok so you store the depth like this:
hope this helped I had trouble with reconstructing position so search for it on gamedev.
I've read those lots of times but its very hard to understand the entire thing at once. I need to do it step-by-step.
Yours3!f, in one of the methods in the article frustum corner positions are used to reconstruct the position. I guess
it was used for world space position reconstruction, and you're reconstructing into view space, right?
So, if I go with the same approach, how should I perform lighting calculation? What would be the positions
of the camera and lights. Also regarding the normals, should that be translated? My understand is that in
view space:
camera_position_view_space = [0, 0, 0];
light_position_view_space = view_matrix * light_position_world_space;
light_direction_view_space = view_matrix * light_direction_world_space;
normal_view_space = normalize(view_matrix * normal_world_space);
Ashaman73, Yours3!f, you guys help me a lot with this! I need some time to digest it.
[/quote]
yep I describe the frustum corner method. I made it work in view space, but mjp describes a world space method as well. (so I guess the frustum one doesn't work in worldspace)
The lighting calculation is independent from what space you're using. Or at least I've seen lighting in world space, view space, tangent space... The basic thing is that you have to be consistent. If you're performing lighting in view space then you need to transform everything into view space. Normals, position, light position are the needed parameters. You should also read the lighthouse3d articles about lighting. If you wanna go the deferred way then I think viewspace suits your needs best.
To you viewspace, you just have to export your meshes to object space. The you can use your modelview matrix to transform them instantly into view space, and then the projection matrix to transform them to projection space.
for the normals you need to use a so called "normal matrix". This matrix is either the upper left 3x3 part of your view matrix, or the transpose of the inverse of your modelview matrix. You probably want to do this on the cpu side. In glsl:
mat3 normal_matrix_1 = mat3(view_matrix);
mat3 normal_matrix_2 = mat3(transpose(inverse(modelview_matrix)));