Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL - cube shadows - projecting

Started by razor1911 Mar 30, 2011 at 3:13 PM 1 replies 1.7k views
Original Post
razor1911
razor1911
Hello again !


Let me start from the fact I've tried searching for almost 5 days now to find a solution how to project the shadow map by using a CubeShadow in the shaders, and guess what - couldn't find anything.. really.


Here's the deal - i am trying to implement a omnidirectional shadowmap with cubemaps.




i generate a Cube texture 512x512:






glGenTextures(1, &tDepthCubeMap);
glBindTexture(GL_TEXTURE_CUBE_MAP, tDepthCubeMap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
glTexParameterf( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

for (int face = 0; face < 6; face++)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_DEPTH_COMPONENT32F , 512, 512, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);




And bind it to my Framebuffer with GL_DEPTH_ATTACHMENT.





I render from light position to all 6 faces of Cube starting GL_TEXTURE_CUBE_MAP_POSITIVE_X and iterating 6 times.


Of course i :







glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);



//

Switch fov to 90

gluPerspective(90, 512/512,1,200);






And render the geometry, results stored in cube depth map:




EDITOR SHOT, SO YOU CAN SEE THE LIGHT POSITION


cdbc8122.jpg

NORMAL RENDERING WITHOUT SHADOWS APPLIED



e419d21c.jpg


GDEBUGGER - SHOWING CONTENTS OF CUBE TEXTURE

43fd12eb.jpg




Now, time to 'project' that as a shadow in the shader..

I pass my cube texture to the fragment shader with:




uniform samplerCubeShadow shadowMap;




How do i project that as a shadowmap in the shader?




Can i ask you please to help me out with that?
i couldn't find anything related to samplerCubeShadow on the net...
razor1911
razor1911
Just for an update, tried sampling with lightDirection as per below in fragment shader:



//vertexshader

...

lightDir[0]=tbnMatrix * ( (gl_LightSource[0].position.xyz - vertexPos) / gl_LightSource[0].spotExponent); // i pass radius for omnis as spotExponents

...








vec4 a=vec4(lightDir[0].x,lightDir[0].y,lightDir[0].z,1.0);
vec4 sat=shadowCube( shadowMap, a) ;

gl_FragColor=light(0)*sat;







Results below




21d190d1.jpg




Applied light-shadow to visualize




e7c9cddf.jpg:




Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.