PDA

View Full Version : shadow mapping stuff...



manilee
04-07-2002, 07:02 PM
Hello.

I writed shadow program by shadow mapping.

I konw PolygonOffset is for correcting the different sampling point and low precision of depth value.

I wonder why shadow map and identity map value are not exactly same in case of the same projection Matrix and view and light position,... etc.

if this result from low precision of depth value, why the lighted loop appeared repeatedly on object according to distance from view point(no PolygonOffset, 8bit shadow map)

code is following

1-pass making shadow map(tex0)
2-pass no specular and 0.4 diffuse
3-pass

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture (GL_TEXTURE_2D, 3);

// env mode
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
// RGB portion : arg0
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
// arg0 =
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

// alpha portion :arg0
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
// arg0 = alpha(tex0)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);

glEnable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture (GL_TEXTURE_1D, 2);

// env mode setup
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
// arg0 =
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

// alpha portion : arg0 + arg1 - 0.5
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_ADD_SIGNED_EXT);
// arg0 = alpha(tex0)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
// arg1 = 1 - alpha(tex1)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA);

glEnable(GL_TEXTURE_1D);


glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GEQUAL, 0.5); // same value -> unshadowed
glDepthFunc(GL_EQUAL);


captured scene(repeatedly ring) is followed
http://user.chollian.net/~manilee/shadow.jpg

if follow lines is included or modified,
glPolygonOffset(1.2, 8.0); // 1-pass

glAlphaFunc(GL_GEQUAL, 0.50); -> glAlphaFunc(GL_GEQUAL, 0.49);

the shadow shape is almost right.

why not exacly same value in case of all is same??
Anybody know the all process that the difference is occured?

thanks for reading.