opengl - Deferred rendering position recontruct -


i made first step of deferred rendering, fbo wit color, normal, position , depth texture. when im lighting positions moving , rotating me. first pass vertex:

void main(){     gl_position=gl_modelviewprojectionmatrix*gl_vertex;     vec4 positiontotexture = gl_modelviewprojectionmartix*gl_vertex; } 

so how can original position?

i assume positiontotexture go fragment shader , saved in texture.

when doing first pass have view position, not viewprojection. can use:

vec4 positiontotexture = gl_modelviewmartix*gl_vertex; 

in second pass can use:

vec3 position = texture(texpos, vvaryingtexcoord0.xy).rgb; 

the previous way quite simple (yet when learning) require lot of memory (you have store 3 element vector). better way recreate view-position screen position/depth: link article. such techniques used in modern engines. (thanks andon-m-coleman suggestion)

here repo basic deferred: https://github.com/fenbf/efg_deferred/tree/master/code/shaders


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -