TGEA 1.7 Possible Bug: Projectiles and selectCurrentDetail()
by Jeff Faust · in Torque Game Engine Advanced · 06/11/2008 (7:37 am) · 10 replies
In TGE 1.5.2 and TGEA 1.7, TSShapeInstance has a suite of methods with variations of the name selectCurrentDetail(), (selectCurrentDetail, selectCurrentDetail2, selectCurrentDetailEx, selectCurrentDetail2Ex). In TGEA 1.0.3, these variations are reduced to just two selectCurrentDetail() methods with the comment, "This subsumes the old selectCurrentDetail* family of functions." This methods are for determining the displayed level of detail for dts models and can play a role in visibility culling.
To the best of my knowledge, the changes in TGEA 1.0.3 came about because it was discovered in older TGEA versions that selectCurrentDetail() on Projectile models was culling the model in case when it should be easily seen. Although it worked in TGE, in TGEA, the distance calculation was comparing the local space position of the projectile object's center with the world position of the camera. In most cases, this means that the projectile object's lod was being determined by the distance from the camera to near (0,0,0) rather than the actual distance from the camera to the projectile. See this thread:
www.garagegames.com/mg/forums/result.thread.php?qt=64190
I believe that the bug described here is back in TGEA 1.7. I've observed similar problems with Projectile object's under TGEA 1.7 and a code comparison shows that 1.7 uses selectCurrentDetail() methods like those found in TGE not like those in TGEA 1.0.3. Also, copying the selectCurrentDetail() method from 1.0.3 to 1.7 and using that for Projectile fixes the problem in observed cases.
To the best of my knowledge, the changes in TGEA 1.0.3 came about because it was discovered in older TGEA versions that selectCurrentDetail() on Projectile models was culling the model in case when it should be easily seen. Although it worked in TGE, in TGEA, the distance calculation was comparing the local space position of the projectile object's center with the world position of the camera. In most cases, this means that the projectile object's lod was being determined by the distance from the camera to near (0,0,0) rather than the actual distance from the camera to the projectile. See this thread:
www.garagegames.com/mg/forums/result.thread.php?qt=64190
I believe that the bug described here is back in TGEA 1.7. I've observed similar problems with Projectile object's under TGEA 1.7 and a code comparison shows that 1.7 uses selectCurrentDetail() methods like those found in TGE not like those in TGEA 1.0.3. Also, copying the selectCurrentDetail() method from 1.0.3 to 1.7 and using that for Projectile fixes the problem in observed cases.
About the author
Jeff Faust creates special effects indie middleware and games for Faust Logic. --- Blog: Effectronica.com --- Twitter: @FaustLogic
#2
@ Brian -- Is your patch intended as a long-term fix, or would a long-term fix be to migrate the selectCurrentDetail() variations over from TGEA 1.0.3?
06/15/2008 (1:47 pm)
NOTE - This problem is also present in 1.7.1.@ Brian -- Is your patch intended as a long-term fix, or would a long-term fix be to migrate the selectCurrentDetail() variations over from TGEA 1.0.3?
#3
06/16/2008 (10:15 am)
The patch should be a permanent fix. Basically, this makes the projectile code use the same LOD selection code that the TSStatics use. Maybe the code could be consolidated a bit, but I think it's definitely better to have less code paths for LOD selection if we can.
#4
06/16/2008 (10:37 am)
Sounds good, but the main point of my question is that TGEA 1.0.3 does appear to reduce the code paths for LOD selection, from about 7 variations to 2. Just curious if the full TGEA solution will get migrated over or is it a dead-end branch.
#5
I *think* the projectile patch above would still apply in the reduced case world.
06/16/2008 (12:06 pm)
D'oh! I mis-read your initial post. I think a similar (possibly the same?) change was made to builder, but I thought it was done in trunk. That's why I thought 1.7 probably had the reduced code path stuff in it. It probably should get that change whenever Matt & company have time. hehI *think* the projectile patch above would still apply in the reduced case world.
#6
06/17/2008 (10:59 am)
Yeah...this bug report and fix came after we had entered code lockdown for TGEA 1.7.1. I'll make sure it makes it into the next version =)
#7
We're using a chaingun type weapon and we're firing projectiles (traces) at a fairly high rate, the first few render fine, but after a certain point they no longer render up close and only begin to render out so far. I thought it was an LOD issue (which we did have, but have since fixed).
Is it possible the projectile is moving too fast and causing some weird calculations or possibly some issue with how its being batched?
06/22/2008 (11:20 am)
We're still seeing some odd issues with Projectiles, but I was hoping this fix would be responsible.We're using a chaingun type weapon and we're firing projectiles (traces) at a fairly high rate, the first few render fine, but after a certain point they no longer render up close and only begin to render out so far. I thought it was an LOD issue (which we did have, but have since fixed).
Is it possible the projectile is moving too fast and causing some weird calculations or possibly some issue with how its being batched?
#8
06/22/2008 (11:33 am)
I'm seeing that in TGEA 1.03 as well, Jeremiah.
#9
Glad I found this thread, I couldn't figure out why my projectiles weren't rendering.
07/08/2009 (10:19 am)
This fix is not included in TGEA 1.8.1Glad I found this thread, I couldn't figure out why my projectiles weren't rendering.
#10
02/22/2010 (4:40 pm)
Another fix is to set the detail level to Detail0 when exporting. That works for me.
Torque Owner Brian Richardson
Index: projectile.cpp =================================================================== --- projectile.cpp (revision 11823) +++ projectile.cpp (revision 11824) @@ -7,6 +7,7 @@ #include "sceneGraph/sceneGraph.h" #include "sceneGraph/lightInfo.h" #include "sceneGraph/lightManager.h" +#include "sceneGraph/detailManager.h" #include "console/consoleTypes.h" #include "console/typeValidators.h" #include "core/bitStream.h" @@ -21,8 +22,8 @@ #include "sim/netConnection.h" #include "T3D/fx/particleEmitter.h" #include "terrain/terrData.h" +#include "gfx/gfxTransformSaver.h" - IMPLEMENT_CO_DATABLOCK_V1(ProjectileData); IMPLEMENT_CO_NETOBJECT_V1(Projectile); @@ -981,6 +982,21 @@ // don't need to return a specialized RenderImage... if (state->isObjectRendered(this)) { + Point3F cameraOffset; + getRenderTransform().getColumn(3,&cameraOffset); + cameraOffset -= state->getCameraPosition(); + F32 dist = cameraOffset.len(); + if (dist < 0.01f) + dist = 0.01f; + F32 fogAmount = state->getHazeAndFog(dist,cameraOffset.z); + if (fogAmount>0.99f) + return false; + + F32 invScale = (1.0f/getMax(getMax(mObjScale.x,mObjScale.y),mObjScale.z)); + DetailManager::selectPotentialDetails(mProjectileShape,dist,invScale); + if (mProjectileShape->getCurrentDetail()<0) + return false; + prepBatchRender( state ); } @@ -989,24 +1005,14 @@ void Projectile::prepBatchRender(SceneState* state) { - // New code for TSE - MatrixF proj = GFX->getProjectionMatrix(); + GFXTransformSaver saver; - RectI viewport = GFX->getViewport(); state->setupObjectProjection(this); - - // hack until new scenegraph in place - MatrixF world = GFX->getWorldMatrix(); - TSMesh::setCamTrans( world ); + + TSMesh::setCamTrans( GFX->getWorldMatrix() ); TSMesh::setSceneState( state ); + TSMesh::setObject(this); - // Uncomment below if projectiles support refraction. Don't forget - // to uncomment the code in ::prepRenderImage() - // TSMesh::setRefract( image->sortType == SceneRenderImage::Refraction ); - - - GFX->pushWorldMatrix(); - MatrixF mat = getRenderTransform(); mat.scale( mObjScale ); GFX->setWorldMatrix( mat ); @@ -1015,15 +1021,8 @@ { AssertFatal(mProjectileShape != NULL, "Projectile::renderObject: Error, projectile shape should always be present in renderObject"); - mProjectileShape->selectCurrentDetail(); mProjectileShape->animate(); - mProjectileShape->render(); } - - - GFX->popWorldMatrix(); - - GFX->setProjectionMatrix( proj ); - GFX->setViewport( viewport ); + TSMesh::setObject(NULL); }