GL_ARB_shadow

drawShadowCasters()

The only shadow caster in the scene is a single quad that is rotating to show that the shadow map is working correctly. There is a switch that is passed in to draw with color or not. When we are creating the depth map, we have no need to define any colors as it is just a wasted function call.

void drawShadowCasters(bool color)
{
	glPushMatrix();
	{
		glRotatef(rotation, 0.0, 0.0, 1.0);
		if(color) glColor3f(1.0,0.0,0.0);

		glBegin(GL_QUADS);
		{
			glVertex3f(-1.0, -1.0, 0.5);
			glVertex3f(1.0, -1.0, 0.5);
			glVertex3f(1.0, 1.0, 0.5);
			glVertex3f(-1.0, 1.0, 0.5);
		}
		glEnd();
	}
	glPopMatrix();
}

drawShadowRecievers()

Here is the rest of the scene. This method does not need to be called during the shadow map creation, but needs to be called when rendering the final scene with shadows. It consists of four quads at various locations to show the shadows.

void drawShadowRecievers()
{
	glBegin(GL_QUADS);
	{
		glColor3f(0.0, 0.0 ,1.0);

		glVertex3f(0.0, 0.0, -2.0);
		glVertex3f(-3.0, 0.0, -2.0);
		glVertex3f(-3.0, -3.0, -2.0);
		glVertex3f(0.0, -3.0, -2.0);

		glColor3f(0.0, 1.0 ,1.0);

		glVertex3f(0.0, 0.0, -1.0);
		glVertex3f(3.0, 0.0, -1.0);
		glVertex3f(3.0, -3.0, -1.0);
		glVertex3f(0.0, -3.0, -1.0);

		glColor3f(1.0, 0.0 ,1.0);

		glVertex3f(0.0, 0.0, -1.5);
		glVertex3f(-3.0, 0.0, -1.5);
		glVertex3f(-3.0, 3.0, -1.5);
		glVertex3f(0.0, 3.0, -1.5);

		glColor3f(1.0, 1.0 ,0.0);

		glVertex3f(0.0, 0.0, 0.0);
		glVertex3f(3.0, 0.0, 0.0);
		glVertex3f(3.0, 3.0, 0.0);
		glVertex3f(0.0, 3.0, 0.0);
	}
	glEnd();
}

Pages: 1 2 3 4 5 6

2 Comments »

24

Pingback by BitwiseOR » GL_ARB_shadow_funcs

January 10, 2006 @ 3:10 pm

[...] The GL_ARB_shadow_funcs extension requires GL_ARB_shadow and GL_ARB_depth_texture in order to have any effect. In the GL_ARB_shadow example on this site we use GL_LEQUAL when setting the GL_TEXTURE_COMPARE_FUNC_ARB texture parameter. GL_ARB_shadow allows this comparison function to be GL_GEQUAL as well, but not any of the other comparison functions. [...]

25

Pingback by » OpenGL Transforms and the Inverse Model View

August 14, 2006 @ 9:46 am

[...] It is important to realise that OpenGL’s Model View matrix is actually M * C, so, if we want to get the position of the vertex in world space, we will have to use the modelview matrix to go to camera space, then multiply by C-1 (the inverse of the camera matrix). This gives us V * M * C * C-1 = V * gl_ModelViewMatrix * C-1 = V * M. And world space is exactly what we need to do shadow mapping, refraction, reflectiona and a plethora of other things. OpenGL took care of this for us with the GL_ARB_Shadow extension. By using glTexGen, OpenGL computes the inverse camera matrix and applies it without us having to fuss with inverses. But, now we’ll need to do an inverse ourselves. [...]

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>