[source=cpp]#version 120#extension GL_ARB_draw_buffers : require#extension GL_EXT_gpu_shader4 : requirevarying vec2 texCoord;varying vec3 lightPos;varying vec3 lightColor;varying vec3 spotDir;varying vec4 data;//intensinity,fallof,cosCutoff,metalisticuniform sampler2D normalTex;uniform sampler2D materialTex;uniform sampler2D depthBufferTex;uniform mat4 invMVP;//i m getting inverted value of modelviewmatrix*projmatrixfloat intensity;// = 128.0;float falloff;// = 512.0;float spotCosCutoff;float metalicFilter;void main() { intensity=data[0]; falloff=data[1]; spotCosCutoff=data[2]; metalicFilter=data[3]; vec3 normal = texture2D( normalTex, texCoord).xyz * 2.0 - 1.0; vec4 mat = texture2D( materialTex, texCoord); ///////////////////////HERE starts problem/////////////////////////////////////// float depth=texture2D( depthBufferTex, texCoord).x; vec2 projPosXY = 2. * vec2( texCoord.x, 1. - texCoord.y ) - 1.; vec4 posSS = vec4( projPosXY.x, projPosXY.y, depth, 1. ); vec4 posWS = posSS*invMVP; vec3 position=posWS.xyz/posWS.w; ////////////////////////////END of problem///////////////////////// float dist = distance( lightPos, position); vec3 lightDir = normalize( lightPos - position); float spotEffect = dot(spotDir, -lightDir); if(spotEffect>=spotCosCutoff) { dist = 1.0 / (1.0 + dist * dist * falloff); vec3 dif = max( (dot( lightDir, normal) * dist * intensity),0.0 )*lightColor ; vec3 spec = vec3(0.0); gl_FragColor = vec4( dif*mat.rgb + spec, 1.0); } }
I`d like to get for "position" value like from gl_vertex*gl_modelviewmatrix.
with invMVP i m getting inverted value of modelviewmatrix*projmatrix.
Any ideas whats wrong?