Game Development Community

Shadow fun..

by Phil Carlisle · in Torque Game Engine Advanced · 09/26/2006 (3:40 am) · 11 replies

Hey guys..

Just want to check my sanity here.

In air ace, we have a bunch of planes that we want shadowed. We did the MS4 merge recently and I had hoped that the shadows would magically work :) of course, things dont end up QUITE how we like em.

So what we've got, is that the shadows DO work, but only if I place an sgLightObject in the scene. But an issue with that, is that doing that only casts shadows from up close to the light. If I increase the light radius, it then washes out any buildings in the scene.

So I guess a few questions:

1) Is the sun supposed to cast shadows? It seems to control ambience on the tsStatic's in the scene, but not on the planes (vehicles). Why does the plane not recieve sun ambience?

2) Why is there only a shadow when an sgLightObject is close? I'm guessing its some function of the projection distance and shadow visibility distance or some such.

3) The planes have translucent materials for the prop disk, but the shadows are full dark. Is there a setting to enable translucency on the shadowed material?

4) Would it be easier to just code up a stencil shadow method instead?

#1
09/26/2006 (3:42 am)
Enable the 'castsShadows' property in your sun object.

Edit: It looks like shadow transparency might be possible in the next release: www.garagegames.com/mg/forums/result.thread.php?qt=51171
#2
09/26/2006 (4:25 am)
Did the "castsshadows" thing, didnt do anything.
#3
09/26/2006 (6:55 am)
Phil i was wondering if i could get some help from you. I didn't do the Milestone 4 merg in myself (and i dont have CVS install at the moment so i'm trying to avoid pulling the latest code and diff-ing it).

We were having the problem that whenever a vech was spawned if you went to look at it you crashed with some wierd Plane error. It was fine untill you tryed to get it on your screen.

i managed to track the crash to the following code:
(in renderObjectMgr.cpp)
//-----------------------------------------------------------------------------
// render objects
//-----------------------------------------------------------------------------
void RenderObjectMgr::render()
{
   for( U32 i=0; i<mElementList.size(); i++ )
   {
      RenderInst *ri = mElementList[i].inst;
	  if(ri->type == RenderInstManager::RIT_Shadow)
	  {
	         ri->obj->renderShadow( ri->state, ri );
	  }
	  else
	  {
		 ri->obj->renderObject( ri->state, ri );
	  }
   }
}

when ever renderShadow is called the crash occures, i did some in depth testing but didn't go all out. i hadn't intended to post this question as i'm not entirly clear why renderShadow is only called on Vech for us and not on other things. But i noticed you were using shadows and vech and was wondering if you had had any trouble with the code above or if this is probably something specific to my current project and i should pull down a clean CVS and check to see whats different.
#4
09/26/2006 (7:14 am)
Phil, when merging - did you also merge the new shadow parameters inside the vehicle class? Probably, just making sure.
#5
09/26/2006 (11:30 am)
Not quite following you Stefan.. if you mean did I add the items to the vehicle datablock, yes.

I CAN see the shadows, occasionally, but they look a bit nasty and arent quite right. Its more the lighting thats disturbing me a little :) I was kind of expecting the sun to cast shadows and magically work all shiny and new! could be the merge though.

Pauliver: You probably want to ask John K, however I've not seen that problem myself. Are any of the pointers rubbish?
#6
09/26/2006 (11:35 am)
It would be really nice if the shadows worked off a new OBB so it actually worked, instead of taking the unpredictable bounds from the DCC package.
#7
09/26/2006 (11:54 am)
If you're not seeing any shadows that sounds like a merge issue. If you do see them occasionally or they look off, post a screen shot and I'll try to see whats going on.

Btw: did you see the bounding box issue from the previous shadow thread - could you be seeing the same thing?
#8
09/26/2006 (12:39 pm)
Dont think this is the same thing John. If I create and sgLightObject and sit it directly above the plane, then the plane is lit and I see the shadow. Sometimes the shadow looks strange when it projects onto the atlas2 terrain.

But if I dont have an sgLightObject, I dont get much lighting on the plane at all and no shadow. Unfortunately adding an sgLightObject isnt going to work, as I need a global sun shadow and lighting thing so that planes dont fly away from the lightsource and become dark again.

We'll show you over at GG if youre there :)
#9
09/26/2006 (1:12 pm)
Hmm, you're also having issues with the lighting. Check sun.cc and sun.h (also shapeBase.cc and shapeBase.h just in case) to make sure all of the code is merged. It sounds like the object's lights aren't being setup properly. Because the point lights work, it sounds specifically related to the sun. Also drop a break point in Sun::registerLights to make sure it's being called and that relight is properly set.

Yup, I'll be in Eugene next week, so we can sit down and I can see what you guys have been working on over there. :)


Pauliver,

Sorry, I missed your post before, can you post the file/line it crashes in, a stack trace, and the error itself.
#10
09/26/2006 (5:23 pm)
What is the thread that has the bound box issue?

First off this crash is only occuring after you spawn a vech (the test map has the vech term around the corner from the vech pad), and then only when you try and move the vech into sight. If you spawn it and walk away and never try to round the corner to see it, there is no problem.
Second like i said i didn't do the merge and i dont have CVS installed currently so i haven't done a basic diff to make sure the merge went smoothly:

The exact error is:
Error, no plane possible! Points: (-15.202, 14.000, 11.091) (-15.201, 14.000, 11.091) (-15.202, 14.000, 11.091)

that actually goes off in PlatformASsert.cpp Line 126 [i doubt thats helpfull]

Fatal: (c:\Programming\Engine\engine\math/mPlane.h @ 255) Error, no plane possible! Points: (-15.202, 14.000, 11.091) (-15.201, 14.000, 11.091) (-15.202, 14.000, 11.091)


Ascension_DEBUG.exe!PlatformAssert::process(PlatformAssert::Type assertType=Fatal, const char * filename=0x00ae412c, unsigned int lineNumber=255, const char * message=0x00cbf500)  Line 127	C++
 	Ascension_DEBUG.exe!PlatformAssert::processAssert(PlatformAssert::Type assertType=Fatal, const char * filename=0x00ae412c, unsigned int lineNumber=255, const char * message=0x00cbf500)  Line 148 + 0x23 bytes	C++
 	Ascension_DEBUG.exe!PlaneF::set(const Point3F & k={...}, const Point3F & j={...}, const Point3F & l={...})  Line 255 + 0xae bytes	C++
 	Ascension_DEBUG.exe!sgShadowProjector::sgCalculateBoundingBox()  Line 386	C++
 	Ascension_DEBUG.exe!sgShadowProjector::sgRender(float camdist=61.145229)  Line 557	C++
 	Ascension_DEBUG.exe!sgObjectShadows::sgRender(SceneObject * parentobject=0x1295b8ec, TSShapeInstance * shapeinstance=0x1295dd94, float camdist=61.145229)  Line 329	C++
 	Ascension_DEBUG.exe!ShapeBase::renderShadow(SceneState * state=0x11ba6f20, RenderInst * ri=0x165103fc)  Line 2504	C++
 	Ascension_DEBUG.exe!RenderObjectMgr::render()  Line 20	C++
 	Ascension_DEBUG.exe!RenderInstManager::render()  Line 279	C++
 	Ascension_DEBUG.exe!SceneState::renderCurrentImages()  Line 144	C++
 	Ascension_DEBUG.exe!SceneGraph::traverseSceneTree(SceneState * pState=0x11ba6f20)  Line 364	C++
 	Ascension_DEBUG.exe!SceneGraph::renderScene(const unsigned int objectMask=4294967295)  Line 192	C++
 	Ascension_DEBUG.exe!GameRenderWorld()  Line 1007	C++
 	Ascension_DEBUG.exe!GameTSCtrl::renderWorld(const RectI & updateRect={...})  Line 42	C++
 	Ascension_DEBUG.exe!GuiTSCtrl::onRender(Point2I offset={...}, const RectI & updateRect={...})  Line 121	C++
 	Ascension_DEBUG.exe!GameTSCtrl::onRender(Point2I offset={...}, const RectI & updateRect={...})  Line 77	C++
 	Ascension_DEBUG.exe!GuiCanvas::renderFrame(bool preRenderOnly=false)  Line 1250	C++
 	Ascension_DEBUG.exe!DemoGame::processTimeEvent(TimeEvent * event=0x0012fd78)  Line 780	C++
 	Ascension_DEBUG.exe!GameInterface::processEvent(Event * event=0x0012fd78)  Line 73	C++
 	Ascension_DEBUG.exe!GameInterface::postEvent(Event & event={...})  Line 155	C++
 	Ascension_DEBUG.exe!TimeManager::process()  Line 1107	C++
 	Ascension_DEBUG.exe!DemoGame::main(int argc=1, const char * * argv=0x01e49570)  Line 567	C++
 	Ascension_DEBUG.exe!run(int argc=1, const char * * argv=0x01e49570)  Line 890 + 0x1a bytes	C++
 	Ascension_DEBUG.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * __formal=0x00000000, char * lpszCmdLine=0x00161f0c, HINSTANCE__ * __formal=0x00000000)  Line 999 + 0x17 bytes	C++
 	Ascension_DEBUG.exe!__tmainCRTStartup()  Line 578 + 0x35 bytes	C
 	Ascension_DEBUG.exe!WinMainCRTStartup()  Line 403	C
 	kernel32.dll!7c816fd7() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
>	Ascension_DEBUG.exe!TerrainEditor::lookupAction(const char * name=0x00650063)  Line 423 + 0x2e bytes	C++


i can reproduce this whenever i want so if you want any more information let me know i can get it easy
#11
09/26/2006 (9:34 pm)
Ok, try changing sgShadowProjector.cc around line 386 to this:

U32 a, b, c;
		a = poly.vertexStart;
		b = a + 1;
		c = a + 2;
[b]
		// apparently this is necessary under some conditions...
		if((sgShadowPoints[a] == sgShadowPoints[b]) ||
		   (sgShadowPoints[a] == sgShadowPoints[c]) ||
		   (sgShadowPoints[b] == sgShadowPoints[c]))
			continue;
[/b]
		poly.plane.set(sgShadowPoints[a], sgShadowPoints[b], sgShadowPoints[c]);