Jump to content
  • Advertisement
Sign in to follow this  
furrymaster

Problem with getting pixel pos from depth

This topic is 2970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 : require

varying vec2 texCoord;
varying vec3 lightPos;
varying vec3 lightColor;
varying vec3 spotDir;
varying vec4 data;//intensinity,fallof,cosCutoff,metalistic

uniform sampler2D normalTex;
uniform sampler2D materialTex;
uniform sampler2D depthBufferTex;

uniform mat4 invMVP;//i m getting inverted value of modelviewmatrix*projmatrix

float 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?

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!