vrijdag 4 juli 2008

omni lights


WOW:)
Omni lights are working now,

The biggest problem was that i didnt set up the correct(modelview) matrices for the cubemap, i just 'debugged' the code by drawing the 6 frusta of the omni.
What i am doing now is rendering the squared distances of the light into an floating point cubemap, which i use in turn in the shadow shader to see if the fragment is in shadow or not.
here is the fragment shader, needs to be cleaned up still:

uniform sampler2D tex0; //diffusetex
uniform sampler2D tex1; //normaltex
uniform sampler2D tex2; //depth texture
uniform samplerCube tex3; //shadow tex
uniform vec3 lightPos; //light pos
uniform vec3 lightColor; //light color
uniform float lightRadius; //raidus
uniform mat4 invMat; //inv projmv mat
varying vec3 camPos; //camera position
varying vec2 texCoord;
varying vec4 dir;
uniform float lightScale;


void main()
{
vec4 base = texture2D(tex0, texCoord);
vec3 bump = normalize(texture2D(tex1, texCoord).xyz* 2.0 - 1.0);
float depth = texture2D(tex2, texCoord).r;
vec4 worldPos = invMat * vec4( (texCoord*2.0)-1.0, depth * 2.0 - 1.0, 1.0 );
worldPos.xyz /=worldPos.w;
vec3 lDir =(lightPos - worldPos.xyz);
float distanceSqr = dot(lDir, lDir);
float distance = sqrt(distanceSqr);
float att=max(0.0, 1.0 - distance/lightRadius)*lightScale;
lDir = normalize(lDir);
float shadow = textureCube(tex3, -lDir).r;
float shadowColor = ((distanceSqr)>shadow) ? 1.0 : 0.0;
float diff = max(0.0, dot(lDir, bump));
vec4 final_color = vec4(0.0, 0.0, 0.0, 0.0);
if(diff > 0.0)
{
final_color += base * diff * att * vec4(lightColor, 1.0)*lightScale;
}
//vec4 color =
gl_FragColor = final_color*shadowColor;
}

1 opmerking:

Jaapio zei

Hey,

Dat ziet er goed uit. Wel jammer dat je voor elke shadowing omni light 1 cubemap moet hebben(en meestal dus ook renderren).


Keep up the good work!

- Jaap