Game Development Community

Render a Shadow Without Rendering its Source Object?

by Chad Kilgore · in Torque Game Engine · 08/07/2007 (11:39 am) · 9 replies

It has to be possible. How can I easily render a shadow of an object without rendering the source object? I'm trying to create that eerie feeling of ghostly apparitions. Thanks.

#1
08/08/2007 (12:30 pm)
I've never tried this, but what if you create an invisible material for the object, so it is completely transparent. The engine may still render its shadow... but I don't know. You could try it.
#2
08/08/2007 (12:56 pm)
When I made a completely transparent texture, the object was rendered as an entirely black object.
#3
08/08/2007 (12:59 pm)
I would use setCloaked to make an invisible object, then modify shapeBase.cc to render the shadow even while cloaked.
#4
08/08/2007 (5:38 pm)
I have created a variable mRenderShadow (= true) and modified line 4037 to read:
if (mRenderShadow ||
	   mShapeInstance && renderPlayer && mCloakLevel == 0.0f &&
       mMount.object == NULL && image->isTranslucent == true)

Can anybody point me in the right direction so that I can add a renderShadow variable, which can dynamically change, in the script Player object? Thanks a lot.
#5
08/09/2007 (8:07 am)
I think the easiest way is to create a consoleMethod for it. Look at how they create the setCloaked method:

ConsoleMethod( ShapeBase, setCloaked, void, 3, 3, "(bool isCloaked)")
{
   bool cloaked = dAtob(argv[2]);
   if (object->isServerObject())
      object->setCloakedState(cloaked);
}

Follow their example and create something similar for mRenderShadow
#6
08/09/2007 (8:45 am)
I goofed up btw. You would want to change the rendering code in the appropriate place, like player.cc, not shapeBase.cc
#7
08/09/2007 (9:06 am)
That good. Because I wasn't smart enough to find the shadow rendering code in the shapeBase.cc.

I anticipate times that I would want to have a cloaked player without a shadow and just display its footprints. So I am trying to add a variable that is read in from the bit stream and change it as needed. Using a consoleMethod seems more like a hack then solid implementation. I am having problems with the bitstream in player.cc. Any ideas or am I just being stubborn?
#8
08/09/2007 (9:24 am)
In shapeBase.h, declare this public function:
void setRenderShadow(bool bRenderOn)
{
       mRenderShadow = bRenderOn;
}

In shapeBase.cc, ShapeBase::ShapeBase()
mRenderShadow = true;

In shapeBase.cc, anywhere:
ConsoleMethod( ShapeBase, setShadowRender, void, 3, 3, "(bool renderShadow)")
{
   bool renderShadow = dAtob(argv[2]);

   if (object->isServerObject())
      object->setRenderShadow(renderShadow);
}

In player.cc, within the renderImage function, replace
if (mShapeInstance && renderPlayer && mCloakLevel == 0.0f &&
       mMount.object == NULL && image->isTranslucent == true)
   {
      renderShadow(dist,fogAmount);
   }

With:
if ([b]mRenderShadow || [/b]mShapeInstance && renderPlayer && mCloakLevel == 0.0f &&
       mMount.object == NULL && image->isTranslucent == true)
   {
      renderShadow(dist,fogAmount);
   }

I just tested this and it worked for me.

*EDIT* - Fixed error with variable name in ConsoleMethod. Nice catch Chris
#9
08/09/2007 (1:56 pm)
Where are you putting your bool mRenderShadow variable? I have mine under
/// @name Cloaking
   /// @{
   bool mCloaked;
   F32  mCloakLevel;
   TextureHandle mCloakTexture;
   bool mHidden; ///< in/out of world
at line 825 in the shapeBase.h but it doesn't want to work.

It appears as though the mRenderShadow variable isn't getting set to the appropriate value, or at least not in the appropriate place.