simple shadows

  • Follow


Hi,

anyone remembering Mario64? They had round shaddows underneath every 
object:
http://img.kult-mag.com/photos/00/00/41/42/ME0000414277_2.jpg
I hope this screenshot is working!?

Can someone tell me how to do this? I've created a 3d object that is a 
very flat cone and used colision detection to get the y of the bottom 
underneath the player, but it looks rather funny when you stand on an 
edge with the shadow floating in the air...

Thank you,

-- 
-Gernot
int main(int argc, char** argv) {printf 
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com


0
Reply Gernot 11/16/2004 2:23:50 PM

Gernot Frisch wrote:

> Hi,
> 
> anyone remembering Mario64? They had round shaddows underneath every
> object:
> http://img.kult-mag.com/photos/00/00/41/42/ME0000414277_2.jpg
> I hope this screenshot is working!?
> 
> Can someone tell me how to do this? I've created a 3d object that is a
> very flat cone and used colision detection to get the y of the bottom
> underneath the player, but it looks rather funny when you stand on an
> edge with the shadow floating in the air...
> 
> Thank you,
> 
 Just use the cone for a shadow cast (shadow volume to be specific). the
base of the cone at the players feet and the apex in direction to the
ground.
 Use the cone for stencil shadows, i.e.
 + add one to stencil buffer when drawing the cone front facing sides 
 + sub one from stencil buffer when drawing the back facing sides
 + draw a shadow where stencil buffer > 0! 
   -> draw a black (gray or whatever color you like) quad
      with stencil test > 0.

 This avoids shadows in the air, make players' shadow smaller when they
jump, wrap the shadow around objects (standing at the edge of one object
vs. 'air shadows')!

 sorry, for being not more specific. google for 'stencil shadow' for more
advice.

_______________________________
remove the _ for reply.
0
Reply Gottfried 11/17/2004 12:10:48 PM


Gottfried Eibner wrote:
> Gernot Frisch wrote:
> 
> 
>>Hi,
>>
>>anyone remembering Mario64? They had round shaddows underneath every
>>object:
>>http://img.kult-mag.com/photos/00/00/41/42/ME0000414277_2.jpg
>>I hope this screenshot is working!?
>>

> 
>  Just use the cone for a shadow cast (shadow volume to be specific). the
> base of the cone at the players feet and the apex in direction to the
> ground.
>  Use the cone for stencil shadows, i.e.
>  + add one to stencil buffer when drawing the cone front facing sides 
>  + sub one from stencil buffer when drawing the back facing sides
>  + draw a shadow where stencil buffer > 0! 
>    -> draw a black (gray or whatever color you like) quad
>       with stencil test > 0.
> 
>  This avoids shadows in the air, make players' shadow smaller when they
> jump, wrap the shadow around objects (standing at the edge of one object
> vs. 'air shadows')!
> 

I did mine by clipping the shadow a cone to the polygons
under the player's feet. This avoids overhangs and
doesn't need stencil or anything like that.


-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/17/2004 1:07:45 PM

> I did mine by clipping the shadow a cone to the polygons
> under the player's feet. This avoids overhangs and
> doesn't need stencil or anything like that.
>
w-w-w-wait a minute... "clipping the shadow a cone to the polygons".
I read it 10 times now, I don't understand it - out of brains,error. 
Can you explain it to me? 


0
Reply Gernot 11/17/2004 1:28:01 PM

Gernot Frisch wrote:
>>I did mine by clipping the shadow a cone to the polygons
>>under the player's feet. This avoids overhangs and
>>doesn't need stencil or anything like that.
>>
> 
> w-w-w-wait a minute... "clipping the shadow a cone to the polygons".
> I read it 10 times now, I don't understand it - out of brains,error. 
> Can you explain it to me? 
> 

Well...there's polygons under his feet (the
thing he's standing on).

Now imagine a cone which goes down from his feet.

Find the intersection of the two, that's the shadow.

If you assume the shadow is vertical then it's not
as hard as it sounds because you can do the
intersection math in 2D.


-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/17/2004 1:29:45 PM

> Well...there's polygons under his feet (the
> thing he's standing on).
>
> Now imagine a cone which goes down from his feet.
>
> Find the intersection of the two, that's the shadow.
>
> If you assume the shadow is vertical then it's not
> as hard as it sounds because you can do the
> intersection math in 2D.

Ah. So you're drawing a polygon for the cast shadow? Isn't that time 
expensive?
I played with stencil buffers and think this might work. What do you 
say?

 RenderScene();  // render scene in depth + color buffer

 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Don't draw 
r,g,b,a - only z
 glEnable(GL_STENCIL_TEST);
 glDepthMask(GL_FALSE); // Do not write into depth buffer
 glStencilFunc(GL_ALWAYS, 0, 0);

 // Draw the whole model front+backfaces, always inverting the stencil 
buffer
 // If only one face has been drawn, the buffer == -1, otherwise == 0
 // Where 0, it's infront/behind the shadow
 glDisable(GL_CULL_FACE);
 glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // If visible, flip stencil
 DrawShadowVolumes();
 glEnable(GL_CULL_FACE);

 // Now turn everything back to normal
 glCullFace(GL_BACK);
 glDepthMask(GL_TRUE);
 glDepthFunc(GL_LEQUAL);
 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
 // Wherever stencil != 0, draw the shadow
 glStencilFunc(GL_EQUAL, 1,1);
 glEnable(GL_BLEND);
 glBlendFunc(GL_ZERO, GL_DST_COLOR);
 DrawShadowVolumes(); // finally render the shadow volume(s)
 glDisable(GL_BLEND);




0
Reply Gernot 11/17/2004 2:08:19 PM

fungus wrote:
> 
> Well...there's polygons under his feet (the
> thing he's standing on).
> 
> Now imagine a cone which goes down from his feet.
> 
> Find the intersection of the two, that's the shadow.
> 
> If you assume the shadow is vertical then it's not
> as hard as it sounds because you can do the
> intersection math in 2D.
> 
> 
 nice!! but what if you have no simple plane underneath your feet; rocky
terrain as an example?! and then you have to compute the vertices for your
shadow and a triangle-fan or something similar, haven't you?
 Good choice for simple terrain in any case. But did you made experience
with complex terrains, too? And non high-noon lighting?
 regards,
  godfired
_______________________________
remove the _ for reply.
0
Reply Gottfried 11/17/2004 2:10:07 PM

On Wed, 17 Nov 2004 15:10:07 +0100, Gottfried Eibner <gottfried_.eibner_@univie_.ac_.at_> wrote:
>  nice!! but what if you have no simple plane underneath your feet; rocky
> terrain as an example?! and then you have to compute the vertices for your
> shadow and a triangle-fan or something similar, haven't you?
>  Good choice for simple terrain in any case. But did you made experience
> with complex terrains, too? And non high-noon lighting?

The purpose of the mario style shadow is not really a shadow, but rather a 
projection where the player is, to ease jumping the platforms. For 
anything more complex than that it propably looks stupid, so I'd suggest 
using correct stencil shadows stuff for that anyway.

If you have simple geometry as in the original example picture, I think 
the manual clipping might be the best choise, because you can actually 
make the cone clipping to something like clipping by 7 planes, and that 
should not be that expensive.

Or... if you have relatively well tesselated level and you can query the 
underlying polygons relatively easily, then the texture projection may be 
a good choise as well.


--memon

 cos(pi),sin(pi)            lddoW                      6Jo'3p15u1@uow3w
                            uow3W                 uow3w~/6Jo'3p15u1'mmm
0
Reply Mikko 11/17/2004 2:19:46 PM

Gottfried Eibner wrote:
> 
>  nice!! but what if you have no simple plane underneath your feet; rocky
> terrain as an example?! and then you have to compute the vertices for your
> shadow and a triangle-fan or something similar, haven't you?

Yes, but really it's not so bad....the polygons
you need to look at come out of the normal
collision detection code.

> Good choice for simple terrain in any case. But did you made experience
> with complex terrains, too? And non high-noon lighting?
>  

It works with anything, even complex objects and it's
never been too slow. I used a round texture for animated
objects and for things like aircraft I made a texture the
same shape as the aircraft and scale it in x/y as the
aircraft rolls/pitches. It looks really good.


-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/17/2004 4:51:36 PM

Gernot Frisch wrote:
>>
>>Find the intersection of the two, that's the shadow.
>>
> 
> 
> Ah. So you're drawing a polygon for the cast shadow?

Several, depending on how many fragments pop out
of the intersection.

If you move over a complex object then you could
get dozens of polygons in the shadow.

> Isn't that time expensive?

Not really...not as expensive as the stencil method.



-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/17/2004 5:14:19 PM

Here's a couple of screenshots of my method
in action:

http://www.artlum.com/Image2.jpg
http://www.artlum.com/Image3.jpg

In the wireframe view you can see that the
shadow made three new triangles.


-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/17/2004 5:22:26 PM

"fungus" <openglMY@SOCKSartlum.com> schrieb im Newsbeitrag 
news:lNLmd.3717$WW2.2348@news.ono.com...
> Here's a couple of screenshots of my method
> in action:
>
> http://www.artlum.com/Image2.jpg
> http://www.artlum.com/Image3.jpg
>
> In the wireframe view you can see that the
> shadow made three new triangles.

I can't see it... Is it the 3 triangles that the terrain has? Then - 
how do you calculate the texture coordinates. Can you draw a wireframe 
around the shadow's triangles, please?
More - why is drawing with a stencil buffer slow? I just have to draw 
about 14 triangles for a light cone e.g. and then draw them again with 
alpha blending. Did you see my method I posted? I don't draw the 
complete scene twice, I only alpha blend the shadow at the stencil 
bits over the completely rendered scene.


0
Reply Gernot 11/18/2004 8:56:01 AM

Gernot Frisch wrote:
> "fungus" <openglMY@SOCKSartlum.com> schrieb im Newsbeitrag 
> news:lNLmd.3717$WW2.2348@news.ono.com...
> 
>>Here's a couple of screenshots of my method
>>in action:
>>
>>http://www.artlum.com/Image2.jpg
>>http://www.artlum.com/Image3.jpg
>>
>>In the wireframe view you can see that the
>>shadow made three new triangles.
> 
> 
> I can't see it... Is it the 3 triangles that the terrain has?

Each triangle in the terrain will produce a
shadow fragment. If the shadow covers three
terrain triangles then you get three shadow
fragments.


> More - why is drawing with a stencil buffer slow? I just have to draw 
> about 14 triangles for a light cone e.g. and then draw them again with 
> alpha blending.

So that's 28 triangles...and usually quite a
lot of pixel fill.

If you're happy with your method that's fine.
I'm just saying how I did shadows in a game
I wrote last year.

OTOH, the stencil method gets very complex when
you take all possibilities into account (eg.
the viewer goes inside the shadow volume).


-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/18/2004 10:45:23 AM

"fungus" <openglMY@SOCKSartlum.com> schrieb im Newsbeitrag 
news:93%md.4520$WW2.2622@news.ono.com...
> Gernot Frisch wrote:
>> "fungus" <openglMY@SOCKSartlum.com> schrieb im Newsbeitrag 
>> news:lNLmd.3717$WW2.2348@news.ono.com...
>>
>>>Here's a couple of screenshots of my method
>>>in action:
>>>
>>>http://www.artlum.com/Image2.jpg
>>>http://www.artlum.com/Image3.jpg
>>>
>>>In the wireframe view you can see that the
>>>shadow made three new triangles.
>>
>>
>> I can't see it... Is it the 3 triangles that the terrain has?
>
> Each triangle in the terrain will produce a
> shadow fragment. If the shadow covers three
> terrain triangles then you get three shadow
> fragments.

How do you calculate the texture coordinates for the shadow image? 
That's a real mystery to me. You must use some form function to map it 
os something very sophisticated, right?

>> More - why is drawing with a stencil buffer slow? I just have to 
>> draw about 14 triangles for a light cone e.g. and then draw them 
>> again with alpha blending.
>
> So that's 28 triangles...and usually quite a
> lot of pixel fill.

because of front/backside? Pixel fill... Hmmm. right. Will it be slow? 
I've not measured it yet. Do you have any experience? Because 
intersecting is a bit difficult for me. I don't know about the 
complete scene at one. I only know each blocky object at a time...

> If you're happy with your method that's fine.
> I'm just saying how I did shadows in a game
> I wrote last year.

Where can I get it? :)

> OTOH, the stencil method gets very complex when
> you take all possibilities into account (eg.
> the viewer goes inside the shadow volume).

Yes, I read about that. Really a PITA, but for simple Mario64 style 
shadows it would do. The camera never comes into a shadow. I've 
checked it btw: Mario64 does an intersect line + triangles to get the 
closest point under marios's feet and then get the normal angle of 
that triangle. That describes the surface the shadow will be drawn in. 
2 triangles, one intersection. Really nice idea. The shadow is very 
small if you're standing on the ground, so you won't notice it much 
when part of the shadow is 'floating' in the air at edges, and when 
you jump it's scaling bigger by the jump height, but the camera turns 
so you can't see the shadow as a still spot. Nice ceating, very nice + 
fast. I'd like to do the scencil thing if it would be fast enough, 
though. Looks "better" and is very easy to implement.
-Gernot









0
Reply Gernot 11/18/2004 10:59:52 AM

Gernot Frisch wrote:
> 
> How do you calculate the texture coordinates for the shadow image? 
> That's a real mystery to me. You must use some form function to map it 
> os something very sophisticated, right?
> 

You transform the tterrain into "shadow space"
and the texture is just an axis-aligned square
in there.


>>So that's 28 triangles...and usually quite a
>>lot of pixel fill.
> 
> 
> because of front/backside? Pixel fill... Hmmm. right. Will it be slow? 

Depends on your graphics card. You also require
a stencil buffer so you can only run in 32-bit
graphics mode. 16 bit is often twice as fast
for pixel fill.

> intersecting is a bit difficult for me. I don't know about the 
> complete scene at one. I only know each blocky object at a time...
> 

That's the hard part. I can get the triangles from
my collision detector so it worked out nicely for me.


> when you jump it's scaling bigger by the jump height

I increase the alpha so it fades with distance.



-- 
<\___/>          For email, remove my socks.
/ O O \
\_____/  FTB.    The Cheat is not dead!


0
Reply fungus 11/18/2004 11:37:21 AM

>> How do you calculate the texture coordinates for the shadow image? 
>> That's a real mystery to me. You must use some form function to map 
>> it os something very sophisticated, right?
>>
>
> You transform the tterrain into "shadow space"
> and the texture is just an axis-aligned square
> in there.

Very good idea.


>> Will stencil buffering be slow?
>
> Depends on your graphics card. You also require
> a stencil buffer so you can only run in 32-bit
> graphics mode. 16 bit is often twice as fast
> for pixel fill.

32 bits for stencil buffer required? Thanks, that was all I need to 
know. <dump>


>> when you jump it's scaling bigger by the jump height
>
> I increase the alpha so it fades with distance.

For a flight simulator a good idea. For a jump and run the shadow is 
essential to locate where you're jumping.

Thank you very much.
-Gernot




0
Reply Gernot 11/18/2004 12:00:00 PM

15 Replies
125 Views

(page loaded in 0.137 seconds)

Similiar Articles:


















7/17/2012 7:44:13 AM


Reply: