glitch

Started by
2 comments, last by experiment 14 years, 8 months ago
Just finished implementing shadow mapping from a tutorial, and this glitch starts showing up.. image I remember seeing this before.. Banged my head to the wall for a while, but still can't remember. Can somebody tell what's causing it? If helps, this is the initialization code:

bool aux_init(void)
{
	//Check for necessary extensions
	if(!GLEE_ARB_depth_texture || !GLEE_ARB_shadow)
	{
		printf("I require ARB_depth_texture and ARB_shadow extensionsn\n");
		return false;
	}
	
	//Load identity modelview
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//Shading states
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	//Depth states
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);

	//glEnable(GL_CULL_FACE);

	//We use glScale when drawing the scene
	glEnable(GL_NORMALIZE);

	//Create the shadow map texture
	glGenTextures(1, &shadowMapTexture);
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0,
					GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	//Use the color as the ambient and diffuse material
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);
	
	//White specular material color, shininess 16
	glMaterialfv(GL_FRONT, GL_SPECULAR, white);
	glMaterialf(GL_FRONT, GL_SHININESS, 16.0f);

	return true;
}

Advertisement
The reason is the precision problems with depth buffer, so one solution is to add a value to it by using for example glPolygonOffset(1,8.0) when rendering the shadow map, I'm not sure if it's platform independent, so maybe try to alter the bias matrix:
float biasMatrix[16] = {	0.5f, 0.0f, 0.0f, 0.0f,				0.0f, 0.5f, 0.0f, 0.0f,				0.0f, 0.0f, 0.5f, 0.0f,				0.5f, 0.5f, another value, 1.0f};

Haven't tried the last one.
Or an other solution: if all your objects are closed, and maybe they aren't intersect each other, draw the backfaces only (culling) when rendering the shadow map.
It has to do something with same plane being drawn twice.

I turned the culling back on, and it seems to work for most.
There are still some parts having the same problem.. going to look into this a little bit more.
okay, got it!

image


I messed up face culling by playing smart, and some planes were getting drawn over each other.

This topic is closed to new replies.

Advertisement