Game Development Community

Shadows

by Andrew · in Torque Game Engine · 05/15/2002 (11:11 pm) · 6 replies

OK, before I dive into the source code alone, just wondering if anyone can give me a start on modifying the code so that all objects (ie. DIF and DTS) cast and receive shadows. Thanks.

About the author


#1
03/07/2003 (2:53 pm)
anyone find solution to this?
#2
03/07/2003 (7:44 pm)
As far as I know, all object already cast shadows.

I know in my project we had to uncomment or replace one line of code that prevented it on some objects like items. Look for stuff about shadows and I'm sure you'll find it fairly quickly.
#3
03/08/2003 (9:15 pm)
Here's what I've found so far today.

DIFs automatically cast shadows on the ground, so they're already perfect.
DTS by default do not cast or recieve shadows.

Modify item.cc and uncomment the line that says:
mGenerateShadow = true;

I also added it to staticShape.cc

StaticShape::StaticShape()
{
   mTypeMask |= StaticShapeObjectType | StaticObjectType;
   mDataBlock = 0;
   // squid
   mGenerateShadow = true;
}

Edit shapeBase.h

//#define StaticShape_GenericShadowLevel 2.0f
//#define StaticShape_NoShadowLevel 2.0f

#define StaticShape_GenericShadowLevel 0.2f
// originaly I changed it to 0.4f, but 0.2f looks good too.

#define StaticShape_NoShadowLevel 0.01f

Then recompile.

You can turn shadows on for ITEMS. In order to make an item shadow casting, you need to whip something like this:

TestTree.cs
datablock StaticShapeData(TestTree2)
{
   // Mission editor category
   category = "Misc";

   // Basic Item properties
   shapeFile = "~/data/shapes/test/bigtree.dts";
};


function StaticShapeData::create(%block)
{
  
   %obj = new StaticShape()
   {
      dataBlock = %block;
   };
   return(%obj);
}




and include this new item in your server/game.cs file, so that it execs on map startup. Then, load up the mission editor and drop your new shadowy tree on the map!

My testing shows that Both StaticShapeData derived item files, and ItemData derived files will work the same as far as shadow-casting goes.

As far as having shadows being recieved from other objects, I need to do some more digging. I know some other people hinted that they have added that into their engine, but currently, the shadow from my player model doesn't show up when I'm standing in front of my tree-trunk.


Just a quick additional note, without the addition of mGenerateShadow = true; to staticShape.cc, your datablock StaticShapeData(TestTree2)
items will not cast a shadow on the ground.
#4
03/08/2003 (9:23 pm)
Your shadow for the player doesn't show up in first person. It will if you change to third person however.
To fix this edit your player datablock so that it reads

renderFirstPerson = true; // i think this is right? ;p

And it should work fine.
#5
05/11/2003 (10:17 am)
how do you change your camera to third person? in what file?
#6
05/11/2003 (11:22 am)
You can change your camera view using the "Tab" file, er... key. I'm not sure how to script that.