Game Development Community

Simple shadow, transparency problem

by Luis Anton · in Torque Game Engine · 02/28/2005 (2:44 am) · 9 replies

On these days of pixel shaders and those megathings, I'm trying to add a simple shadow, like those we saw years ago in many, many games (like resident evil). Most scenes in our 'educational game' are inside .dts (I know, I know, but our modeler hates quark), and this is is an old solution for shadows.

Here are some results:
www.blogs.ya.com/programmind/files/casa1.gifwww.blogs.ya.com/programmind/files/casa2.gif

Well, it seems to work. BUT (there's always a 'but'), seen from a different angle, the alpha transparency of the texture used for the shadow goes through the whole house model (it's a dts) and shows the terrain below it!! (there's even a cellar below the hall)

www.blogs.ya.com/programmind/files/casa3.gifwww.blogs.ya.com/programmind/files/casa4.gif

For the shadow, I saw how fxRenderObject was rendered, and added some code in player.cc and player.h. Here's the rendering part, in Player::renderImage:

if (mShapeInstance && renderPlayer && DetailManager::selectCurrentDetail(mShapeInstance)) {
   glPushMatrix();
   dglMultMatrix(&getRenderTransform());
   glScalef(mObjScale.x,mObjScale.y,mObjScale.z);
[b]
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   // Enable Texturing.
   glEnable(GL_TEXTURE_2D);

   // Select the objects' texture.
   mDataBlock->mTextureHandle = TextureHandle(
         mDataBlock->mTextureName, BitmapTexture, true);
   glBindTexture(GL_TEXTURE_2D, mDataBlock->mTextureHandle.getGLName());

   // Set Colour/Alpha.
   glColor4f(1,1,1,1);

   // Calculate Quad Radius.
   F32 QuadSize = 0.50;

   glBegin(GL_QUADS);
   glTexCoord2f(0,0);
   glVertex3f(-QuadSize,+QuadSize,0.0);
   glTexCoord2f(1,0);
   glVertex3f(+QuadSize,+QuadSize,0.0);
   glTexCoord2f(1,1);
   glVertex3f(+QuadSize,-QuadSize,0.0);
   glTexCoord2f(0,1);
   glVertex3f(-QuadSize,-QuadSize,0.0);
   glEnd();

   glDisable(GL_BLEND);
   glDisable(GL_TEXTURE_2D);

[/b]
   if (mCloakLevel != 0.0) {
         glMatrixMode(GL_TEXTURE);
         glPushMatrix();

         static U32 shiftX = 0;...


Why is this happening? Could it be a sorting problem? Something related to .dts shapes and transparency?

#1
03/01/2005 (1:10 am)
Uh... I don't like doing this, but I would like having that 'shadow' in game. No one knows what could be happening? Could it be I'm drawing it in the wrong section of the player render code?

I though it was 'easy', I coudn't imagine something like that transparency problem...
#2
03/01/2005 (3:01 am)
I've found it also happens in the torque example, with the orc, inside and on .dif objects (huts and docks)
#3
03/01/2005 (9:47 am)
Hey Luis, here is just a quick guess to try out and see what happens. Try turning off writing to the depth buffer before writing out your quad and then turn it back on again after the quad is drawn. Let me know if it works.
#4
03/01/2005 (9:58 am)
Have you thought about creating the shadow as a part of your model or mounting your model to a "shadow" DTS? I know it's not a code solution, but it may be a quick and dirty way to fix it.
#5
03/01/2005 (10:36 am)
Kevin: I tried disbling the depth buffer (glDisable(GL_DEPTH_TEST);). There's no transparency problem like before:
www.blogs.ya.com/programmind/files/ss1.gif
but of course, simpleShadows aren't sorted anymore, so they appear in front of everything else. Here's an snapshop:
www.blogs.ya.com/programmind/files/ss2.gif
The small one belongs to another bot, who is downstairs, in the cellar.

David: Yes, adding the shadow as a part of our models was my first idea, but just trying to free the modeler from extra work, I tried this before. And of course, this could be a hack for shadows inside .dts files, for those who need them.

Thanks for the feedback! :D I hope there's a solution!
#6
03/01/2005 (11:29 am)
Don't disable the depth test, but disable writing to the depth buffer.
#7
03/01/2005 (11:45 am)
Ups!

...
glDepthMask ( GL_FALSE);
...

and... it works! Now it looks ok! Could you explain the trick, please?
#8
03/01/2005 (12:35 pm)
From your first screen shot it looked like your shadow was being drawn before the floor. When the floor came around to be drawn the shadow quad area of the floor would not be drawn because of what the shadow had drawn into the depth buffer.

You still want the depth buffer check on for the shadow though because you want it to be drawn behind other objects like the player.
#9
03/01/2005 (3:12 pm)
I see! Thanks!

I know that thing is not an awesome tweak, but it looks much better now inside dts shapes.

And what is more, with your aid I finally managed to add a visual object to Torque (something useful, I did some time ago the classical 'drips on water' effect seen in many demos, but on a heightmap), with a texture and all that. First step :)

Thanks again.