#159631 - zeruda - Thu Jul 03, 2008 6:33 am
I'm trying to get shadow casting using the hardware working but it eludes me. Here is what I am doing so far:
So theres a character that moves around. A shadow box that surrounds the character. A normal box offset on the z axis to the character. A terrain, and a giant box.
I get some strange results.
The character and terrain show as normal.
The shadow box is invisible and does nothing.
The giant box which should be white is normally invisible, but if I move so that it is in between the camera and the terrain, it is clipped to the terrain by the stencil. So where there is no terrain the box is invisible, where there is terrain I can see white.
The same happens with the character.
The other green box is stencilled to the terrain. So if in the sky it is invisible, any parts overlapping the terrain green shows. If both the white and green box overlap, they are invisible, and if they both overlap the terrain the white box wins the fight and white shows.
Any suggestions on what I'm doing wrong? I get some sort of stencilling, but no projection of any kind of shadows. Is the algorithm/approach correct?
Thanks
Code: |
glPushMatrix(); BoxPos = CharacterPosition; glColor3f(1,0,0); glPolyFmt(POLY_ALPHA(1) | POLY_SHADOW | (1<<14)); DrawOutCube(0, 0.03, BoxPos); glPopMatrix(1); glPolyFmt(POLY_ALPHA(30) | CULL_BACK | POLY_ID(8) | LIGHT_0); glPushMatrix(); BoxPos.z -= 0.1; glColor3f(0,1,0); DrawOutCube(0, 0.03, BoxPos); // <draw quad> glPopMatrix(1); glPushMatrix(); glColor3f(0.9,0.9,0.9); BoxPos = CVector(4.0, 0.0, 0.0); glPolyFmt(SETALPHA(30) | CULL_BACK | POLY_ID(12) | LIGHT_0); DrawOutCube(0, 3, BoxPos); // 100 times the other cubes size glPopMatrix(1); glColor3f(1,1,1); glPolyFmt(SETALPHA(30) | POLY_FOG | CULL_BACK | LIGHT_0 | POLY_ID(17)); glPushMatrix(); Texture.Bind(Texture.texture[0]); DrawLandscape() glPopMatrix(1); Texture.Bind(Texture.texture[1]); glPushMatrix(); // Draw Kazir glPolyFmt(SETALPHA(30) | POLY_FOG | CULL_BACK | LIGHT_0 | POLY_ID(11)); DrawCharacter(); glPopMatrix(1); glFlush(GL_TRANS_MANUALSORT | GL_WBUFFERING); // or glFlush(GL_TRANS_MANUALSORT); |
So theres a character that moves around. A shadow box that surrounds the character. A normal box offset on the z axis to the character. A terrain, and a giant box.
I get some strange results.
The character and terrain show as normal.
The shadow box is invisible and does nothing.
The giant box which should be white is normally invisible, but if I move so that it is in between the camera and the terrain, it is clipped to the terrain by the stencil. So where there is no terrain the box is invisible, where there is terrain I can see white.
The same happens with the character.
The other green box is stencilled to the terrain. So if in the sky it is invisible, any parts overlapping the terrain green shows. If both the white and green box overlap, they are invisible, and if they both overlap the terrain the white box wins the fight and white shows.
Any suggestions on what I'm doing wrong? I get some sort of stencilling, but no projection of any kind of shadows. Is the algorithm/approach correct?
Thanks