Object Shadows ?
by Chris Labombard · in Torque Game Engine · 08/17/2005 (9:41 am) · 9 replies
I appologize. I couldnt find any info that answered my questions.
The shadows of objects are created from there collision meshes, correct ?
My NPC's have very nice, well defined stencil shadows (using Blue Guy) ... My trees have very light, non defined shadows (they sorta fade into the terrain), and my player has no shadow at all.
How do I make my static objects have a well defined shadow like my NPC's ? What is needed to make the player shadow show up ? Collision meshes for each part of the body (example CollisionA-1, CollisionB-2, etc.) ? Are there any other requirements that could be stopping his shadow from showing up ?
In case it matters. This is all in regards to casting shadows onto the terrain.
The shadows of objects are created from there collision meshes, correct ?
My NPC's have very nice, well defined stencil shadows (using Blue Guy) ... My trees have very light, non defined shadows (they sorta fade into the terrain), and my player has no shadow at all.
How do I make my static objects have a well defined shadow like my NPC's ? What is needed to make the player shadow show up ? Collision meshes for each part of the body (example CollisionA-1, CollisionB-2, etc.) ? Are there any other requirements that could be stopping his shadow from showing up ?
In case it matters. This is all in regards to casting shadows onto the terrain.
About the author
I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.
#2
I removed that block of code and compiled. My trees still don't display a shadow.
They are just plain old statics. Do I have to create a datablock for them and place them that way ? If so, how do I enable shadows for them ?
I only want my trees and weapons to display shadows.
Thank you
08/17/2005 (10:37 am)
Manoel - Thank you for your reply :)I removed that block of code and compiled. My trees still don't display a shadow.
They are just plain old statics. Do I have to create a datablock for them and place them that way ? If so, how do I enable shadows for them ?
I only want my trees and weapons to display shadows.
Thank you
#3
Your framerate will drop a LOT, depending on how many trees you have in there.
08/17/2005 (10:41 am)
Read the post again: only Player/Vehicles have dynamic shadows on. If you want to enable shadows for TSStatics, use the search feature to find a thread that contains the information on doing so, but be warned:Your framerate will drop a LOT, depending on how many trees you have in there.
#4
Well.... I got this sorta working.
I had to enable mGenerateShadow in the ShapeBase constructor.
And then make a datablock to place the tree as an item :S
It looks like what I wanted it to. nice, well defined tree outline. But it is acting odd.
Firstly, the base of the shadow doesnt line up with the base of the trunk of my tree. The shadow starts before my tree trunk.... If I move my tree a bit I can get it to line up perfectly, so this isn't a big issue.
Also, I can't get the shadow angle to change. I want it to Be projected from the sun like my NPC's are doing.
And, sometimes the shadow disappears... If I am between the base of the tree and end of the shadow sometimes it just disappears.
And... My player has no shadow. I am using the blue guy for my NPC's currently. What are the requirements for my player to have a shadow ?
08/18/2005 (4:56 pm)
Thank you for your help ManoelWell.... I got this sorta working.
I had to enable mGenerateShadow in the ShapeBase constructor.
And then make a datablock to place the tree as an item :S
It looks like what I wanted it to. nice, well defined tree outline. But it is acting odd.
Firstly, the base of the shadow doesnt line up with the base of the trunk of my tree. The shadow starts before my tree trunk.... If I move my tree a bit I can get it to line up perfectly, so this isn't a big issue.
Also, I can't get the shadow angle to change. I want it to Be projected from the sun like my NPC's are doing.
And, sometimes the shadow disappears... If I am between the base of the tree and end of the shadow sometimes it just disappears.
And... My player has no shadow. I am using the blue guy for my NPC's currently. What are the requirements for my player to have a shadow ?
#5
This is odd... the shadows should behave the same for all shapebases. I never tried to toggle them on for all shapes, did you check if there was something about that on that topic?
The shadows will not be rendered if the shapes are culled out: so, if the object bounding box is not visible, it's shadow will not be rendered.
Do the NPCs have shadows? Is your player a custom model? We had problems with player shadows when the player had only a single LOD level. Adding a 2nd LOD (even if it's an empty one, to make the character disappear when it's too far) seems to solve the problem.
08/19/2005 (9:37 am)
Quote:Firstly, the base of the shadow doesnt line up with the base of the trunk of my tree. The shadow starts before my tree trunk.... If I move my tree a bit I can get it to line up perfectly, so this isn't a big issue.
Quote:Also, I can't get the shadow angle to change. I want it to Be projected from the sun like my NPC's are doing.
This is odd... the shadows should behave the same for all shapebases. I never tried to toggle them on for all shapes, did you check if there was something about that on that topic?
Quote:And, sometimes the shadow disappears... If I am between the base of the tree and end of the shadow sometimes it just disappears.
The shadows will not be rendered if the shapes are culled out: so, if the object bounding box is not visible, it's shadow will not be rendered.
Quote:And... My player has no shadow. I am using the blue guy for my NPC's currently. What are the requirements for my player to have a shadow ?
Do the NPCs have shadows? Is your player a custom model? We had problems with player shadows when the player had only a single LOD level. Adding a 2nd LOD (even if it's an empty one, to make the character disappear when it's too far) seems to solve the problem.
#6
I will try the LOD fix and see if it works :)
I have searched for shadow issues and found nothing relative.
Are you saying that no matter what I do, short of recoding the shadow code, that the shadows aren't going to render if the bb isnt in view ? Even if I do get the nice dynamic shadows like the player has, to work.
08/19/2005 (9:44 am)
The NPC's have shadows, yes. I will try the LOD fix and see if it works :)
I have searched for shadow issues and found nothing relative.
Are you saying that no matter what I do, short of recoding the shadow code, that the shadows aren't going to render if the bb isnt in view ? Even if I do get the nice dynamic shadows like the player has, to work.
#7
Even the player shadow will disappear when the player is out of sight - changing it would involve changes to the scenegraph (the scenegraph avoids rendering off-screen objects).
-John
08/19/2005 (1:21 pm)
Hi Chris,Even the player shadow will disappear when the player is out of sight - changing it would involve changes to the scenegraph (the scenegraph avoids rendering off-screen objects).
-John
#8
Thank you for your help guys.
08/22/2005 (4:18 am)
Ok. I figured out why my player wasn't casting a shadow. He had some alphed out polys. After removing those, he worked. Well, he also has an LOD but I have no idea if that effected this or not. Thank you for your help guys.
#9
08/22/2005 (4:46 pm)
So do we get to see some cool screen shots? :)
Associate Manoel Neto
Default Studio Name
Only lightmap shadows are generated by collision meshes. Those are baked on the lightmaps and are not dymanic.
Anything derived form shapebase (the player/aiplayer class and the vehicles, as example) can use a dynamic shadow, that is rendered by a software renderer and projected against collision geometry (it defaults to project against interior and terrain collision only). Mind you, the shadow is updated every frame (or at every few frames, depending on the shadow detail level), so having lots of those in full quality can destroy your performance.
The dynamic shadow rendering code skips drawing the shadow if the object contains transparency meshes, but it's quite easy to fix that:
In shapeBase.cc, look for ShapeBase::renderShadow(F32 dist, F32 fogAmount). Then comment out this block of code:
if (mShapeInstance->getShape()->subShapeFirstTranslucentObject.empty() || mShapeInstance->getShape()->subShapeFirstTranslucentObject[0] == 0) return;Now the shadow will hapily draw the shape, even if there's alpha channels in there (keep in mind that alpha channels and textures as a whole are not used while drawing the shadow, so if you have big semi-transparent features in your model, they'll draw opaque on the shadow).
The dynamic shadows are turned off by default on the shapebase class, and only the Player class and the Vehicle class enable it for themselves (maybe the Item class does it too, but I haven't checked it). Turning it on for all objects is a BAD idea, because it'll seriously bring down the framerate. Plus, the dynamic shadow has other limitations:
- It's a single shadow, so it looks rather strange when there are more than one strong light close to the object
- It's projected orthogonally (no perspective), so it looks a bit strange when you have a light too close to a shadow caster object, since the shadow will not grow bigger with the distance as expected