I made the first step of deferred rendering, the FBO with color, normal, position and depth texture. But when I do the lighting the positions are moving and rotating with me.
First pass vertex:
void main(){
gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;
vec4 positiontotexture = gl_ModelViewProjectionMartix*gl_Vertex;
}
So how can I get the original position?
I assume that
positiontotexture
will go to the fragment shader and then be saved in the texture.When doing first pass it would be good to have View position, not ViewProjection. You can use:
in the second pass you can then use:
The previous way is quite simple (yet it is good when learning) but require lot of memory (you have to store 3 element vector). Better way is to recreate view-position from screen position/depth: link to article. Such techniques are used in modern engines. (Thanks andon-m-coleman for the suggestion)
Here is my repo with some basic deferred: https://github.com/fenbf/efg_deferred/tree/master/code/shaders