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

Cube shadowmaps

Started by razor1911 Apr 4, 2011 at 10:17 AM 0 replies 1.7k views
Original Post
razor1911
razor1911
Right,

seems like i just don't get the idea how to lookup this damn cube texture in frag shader.

As in my previous post that was not resolved, i have

- cube depth texture with 6 faces rendered from light position



glGenTextures(1, &tDepthCubeMap);
glBindTexture(GL_TEXTURE_CUBE_MAP, tDepthCubeMap);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, 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);
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_DEPTH_TEXTURE_MODE , GL_LUMINANCE );
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);








- Light view matrix, obtained by:

glGetFloatv(GL_MODELVIEW_MATRIX, mLightViewMatrix);

after doing lookat from light position into the cubemap face direction.




- Light projection matrix, obtained by:



gluPerspective(90, 512/512,10,LightsManager.getLight(0)->radius);
glGetFloatv(GL_PROJECTION_MATRIX, mLightProjectionMatrix);






I am just writing depth when rendering to 6 faces of a cubemap, there is no shader involved - this is made off screen with FBO.

After that, a final scene comes in - and i pass matrices to vert and a uniform samplerCubeShadow shadowMap; to the fragment.




- Vertex shader:



varying vec4 Projection;


vec4 wsvertex= mLightViewMatrix * gl_Vertex;
vec4 wslight= mLightViewMatrix * vec4(lightType[0].position.x,lightType[0].position.y,lightType[0].position.z,1) ;


Projection= normalize( wsvertex - wslight );







- Fragment shader:



uniform samplerCubeShadow shadowMap;

float cDepth=texture( shadowMap, (Projection));
gl_FragColor= vec4(1,0,0,1)* cDepth ; // do it red + shade







Can somebody please take a look, and help me out to project a cube shadow ?

The effect is nothing, i can bet this is because of matrices, as when i mangle with them i get some results sometimes, but they are not correct.

dc6cfbaf.jpg





EDIT:

going with the 'additional shader' that stores the dist in the rgba instead of depth.


will come back with results.

FXACE
FXACE
I know only how to do it manually (without hardware shadows support). If you interest in? Go on read.




1. Create the shader that would generate shadowing cube map. The main line of this is:

gl_FragDepth = length(light_vector) / light_radius+0.0005;

where light_vector is a direction from light to projected vertex of light view, 0.0005 is a shift value to avoid "self-shadowing".




2. Using shadowing cube map:

Set the type of uniform "samplerCubeShadow" -> "samplerCube".

To look up shadow you need only this line:

float shadow = float(textureCube("your sampler", light_vector.xyz).r > length(light_vector)/light_radius);

where light_vector is a direction from light to projected vertex of eye view.


If you want to try this you should disable this code:

glTexParameterf( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );



There are good references (in my opinion) could be found here. (check out GameEngine 2 example on page 2)

-me

Topic Locked

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

Sign in to reply to this topic.