Vexator

04-24-2007, 11:25 AM

having read several tutorials and papers on the topic, i decided to give it a try.

i render my geometry twice, the first time in the lower half of the texture, the second time in the upper half, incrementing 'u_Pass'.

code:

vertex shader:

uniform int u_Pass;

uniform vec3 u_LightPosition;

uniform mat4 u_ViewMatrix;

uniform mat4 u_ProjectionMatrix;

varying vec3 v_Position;

void main()

{

gl_Position = u_ViewMatrix*gl_Vertex-vec4( u_LightPosition, 0.0 );

float Length = length( gl_Position.xyz );

gl_Position /= -Length;

gl_Position.y *=-1.0;

gl_Position.x *=-1.0;

if( u_Pass > 0 )

{

gl_Position.z *=-1.0;

}

gl_Position.z += 1.0;

gl_Position.xy /= gl_Position.z;

if( gl_Position.z >= 0.01 )

{

gl_Position.z = Length/20.0*1.02;

gl_Position.w = 1.0;

}

else

{

gl_Position.z = -1.0;

gl_Position.w = -1.0;

}

gl_Position.z = 2.0*gl_Position.z-1.0;

v_Position = gl_Position.xyz;

}

fragment shader:

varying vec3 v_Position;

void main()

{

if( length(v_Position.xy) > 1.005 )

{

discard;

}

}resulting depth map:

http://www.vexator.net/paraboloid.jpg

- does all this make sense?

- atm i send u_LightPosition as the plain translation vector. is this correct or should i multiply it by the view matrix before?

- and finally: how to access the depth map in my lighting shader, i.e. how to get the correct uv coordinates?!

thanks!

i render my geometry twice, the first time in the lower half of the texture, the second time in the upper half, incrementing 'u_Pass'.

code:

vertex shader:

uniform int u_Pass;

uniform vec3 u_LightPosition;

uniform mat4 u_ViewMatrix;

uniform mat4 u_ProjectionMatrix;

varying vec3 v_Position;

void main()

{

gl_Position = u_ViewMatrix*gl_Vertex-vec4( u_LightPosition, 0.0 );

float Length = length( gl_Position.xyz );

gl_Position /= -Length;

gl_Position.y *=-1.0;

gl_Position.x *=-1.0;

if( u_Pass > 0 )

{

gl_Position.z *=-1.0;

}

gl_Position.z += 1.0;

gl_Position.xy /= gl_Position.z;

if( gl_Position.z >= 0.01 )

{

gl_Position.z = Length/20.0*1.02;

gl_Position.w = 1.0;

}

else

{

gl_Position.z = -1.0;

gl_Position.w = -1.0;

}

gl_Position.z = 2.0*gl_Position.z-1.0;

v_Position = gl_Position.xyz;

}

fragment shader:

varying vec3 v_Position;

void main()

{

if( length(v_Position.xy) > 1.005 )

{

discard;

}

}resulting depth map:

http://www.vexator.net/paraboloid.jpg

- does all this make sense?

- atm i send u_LightPosition as the plain translation vector. is this correct or should i multiply it by the view matrix before?

- and finally: how to access the depth map in my lighting shader, i.e. how to get the correct uv coordinates?!

thanks!