FxSunlight fix
by Tom Spilman · in Torque Game Engine Advanced · 01/23/2007 (12:50 pm) · 6 replies
FxSunlight is broken in the latest TGEA release... in particular it was first a culling issue then it had diry texture states.
In about line 1811 of fxSunlight.cpp change this...
... to this...
Then at the end of that function change this...
... to this...
That fixes it... although i have to say that fxSunlight doesn't cause the specular type reflection on the water like it probably should, but that's a new feature for another time.
In about line 1811 of fxSunlight.cpp change this...
// Render // ------------------------------------------------------------------------- GFX->setBaseRenderState(); // Setup Alpha GFX->setAlphaTestEnable( true );
... to this...
// Render // ------------------------------------------------------------------------- GFX->pushState(); // Setup the base state. GFX->setCullMode( GFXCullNone ); GFX->disableShaders(); GFX->setLightingEnable( false ); // Disable the unused texture stages... hacky // we need a helper function for reseting the // texture stages. GFX->setTexture(1, NULL ); GFX->setTextureStageColorOp( 1, GFXTOPDisable ); GFX->setTextureStageAlphaOp( 1, GFXTOPDisable ); GFX->setTexture(2, NULL ); GFX->setTextureStageColorOp( 2, GFXTOPDisable ); GFX->setTextureStageAlphaOp( 2, GFXTOPDisable ); GFX->setTexture(3, NULL ); GFX->setTextureStageColorOp( 3, GFXTOPDisable ); GFX->setTextureStageAlphaOp( 3, GFXTOPDisable ); // Setup Alpha GFX->setAlphaTestEnable( true );
Then at the end of that function change this...
PrimBuild::end(); // Exit GFX->setZWriteEnable( true ); GFX->setZEnable( true ); GFX->setAlphaTestEnable( false ); GFX->setBaseRenderState(); }
... to this...
PrimBuild::end(); // Exit GFX->popState(); }
That fixes it... although i have to say that fxSunlight doesn't cause the specular type reflection on the water like it probably should, but that's a new feature for another time.
About the author
Tom is a programmer and co-owner of Sickhead Games, LLC.
#2
01/23/2007 (1:04 pm)
You'll have to compare the code yourself, but our last merge was with 4.0.
#3
If it's a texture issue, then
should be all you need to fix it. Oh, yeah and the culling.
Can anyone confirm?
01/24/2007 (3:16 pm)
You don't need to explicitly disable each texture stage; when you disable a particular stage, it automatically disables all stages above it. Setting the texture to NULL shouldn't be necessary either.If it's a texture issue, then
GFX->setTextureStageColorOp( 1, GFXTOPDisable );
should be all you need to fix it. Oh, yeah and the culling.
Can anyone confirm?
#4
Also... i really like the pushState/popState() method over the explicit cleanup stuff... seems much more robust to me. Is that preferred now?
01/24/2007 (3:40 pm)
Humm... i'll have to test that. I wasn't aware that disabling one stage disables the ones above it... but it makes perfect sense now.Also... i really like the pushState/popState() method over the explicit cleanup stuff... seems much more robust to me. Is that preferred now?
#5
01/25/2007 (5:33 pm)
Yeah, the push/pop state is really quite nice. The only reason I'd hesitate to use it is I'm not sure how optimized it is. I think it's OK now, but I remember it needed a couple of tweaks to get it more optimal, just can't remember if I got to it.
#6
01/25/2007 (5:46 pm)
Well... even if you didn't get it perfectly optimal... IMO... all rendering functions should be switched over to using it as soon as it is possible. There is way too many dirty states being leaked all over the engine. This is why culling was broken for objects not long ago. In fact if push/popState was used and enforced properly... then setBaseRenderState() would never be necessary.
Torque 3D Owner Dave Young
Dave Young Games