Problem with getting pixel pos from depth

Started by
1 comment, last by furrymaster 13 years, 8 months ago
Hi, i`m trying to optimize deferred lighting and i have a problem with getting info about pixel pos from depth. Here`s my spot light fragment code(i selected where i m getting position value):
[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?
If I helped you rate me
Advertisement
This may help you:

topic_id=579762

Sput
It didnt help me because person who answer shows how to store in teksture position value. I dont want to do that. I want get position from depth buffer to have less render targets in deferred lighting(for optimize).

If someone shows me sample code with getting pixel from depth would be nice. Than i can see what am i doing wrong in my shader

[Edited by - furrymaster on August 31, 2010 2:57:48 AM]
If I helped you rate me

This topic is closed to new replies.

Advertisement