Game Development Community

Using FixedFunctioin material

by Marton Gyorgy · in Torque 3D Professional · 05/23/2011 (10:28 pm) · 2 replies

Sean H. suggested to comment out the following conde in matInstance.cpp from around line 304:
if( dynamic_cast<CustomMaterial*>(mMaterial) )
   {
      F32 pixVersion = GFX->getPixelShaderVersion();
      CustomMaterial* custMat = static_cast<CustomMaterial*>(mMaterial);
      if ((custMat->mVersion > pixVersion) || (custMat->mVersion == 0.0))
      {
         if(custMat->mFallback)
         {
            mMaterial = custMat->mFallback;
            return processMaterial();            
         }
         else
         {            
            AssertWarn(custMat->mVersion == 0.0f, avar("Can't load CustomMaterial %s for %s, using generic FF fallback", 
               String(mMaterial->getName()).isEmpty() ? "Unknown" : mMaterial->getName(), custMat->mMapTo.c_str()));
            mProcessedMaterial = new ProcessedFFMaterial(*mMaterial);
         }
      }
      else 
         mProcessedMaterial = new ProcessedCustomMaterial(*mMaterial);
   }
   else if(GFX->getPixelShaderVersion() > 0.001)
      mProcessedMaterial = getShaderMaterial();
   else
      mProcessedMaterial = new ProcessedFFMaterial(*mMaterial);
and use this instead:
mProcessedMaterial = new ProcessedFFMaterial(*mMaterial);

so it could run faster on integrated graphic cards since ProcessedFFMaterial does not use shaders.

When tried to run the exe, I got an error (unhandled exception in Debug build) with the following call stack:

Blocks_DEBUG.dll!LightInfo::getType() Line 140 + 0xf bytes C++
Blocks_DEBUG.dll!ProcessedFFMaterial::_setPrimaryLightInfo(const MatrixF & _objTrans={...}, LightInfo * light=0x00000000, unsigned int pass=0) Line 250 + 0x8 bytes C++
Blocks_DEBUG.dll!ProcessedFFMaterial::setSceneInfo(SceneState * state=0x060ab298, const SceneGraphData & sgData={...}, unsigned int pass=0) Line 243 C++
Blocks_DEBUG.dll!MatInstance::setSceneInfo(SceneState * state=0x060ab298, const SceneGraphData & sgData={...}) Line 405 C++
Blocks_DEBUG.dll!RenderMeshMgr::render(SceneState * state=0x060ab298) Line 181 C++
Blocks_DEBUG.dll!RenderPassManager::render(SceneState * state=0x060ab298) Line 297 C++
Blocks_DEBUG.dll!SceneState::renderCurrentImages() Line 160 C++
Blocks_DEBUG.dll!SceneGraph::_traverseSceneTree(SceneState * pState=0x060ab298) Line 240 C++
Blocks_DEBUG.dll!SceneGraph::renderScene(SceneState * sceneState=0x060ab298, unsigned int objectMask=335548416) Line 202 C++
Blocks_DEBUG.dll!PSSMLightShadowMap::_render(SceneGraph * sceneManager=0x02627038, const SceneState * diffuseState=0x060aa358) Line 339 C++
Blocks_DEBUG.dll!LightShadowMap::render(SceneGraph * sceneManager=0x02627038, const SceneState * diffuseState=0x060aa358) Line 274 C++
Blocks_DEBUG.dll!ShadowMapPass::render(SceneGraph * sceneManager=0x02627038, const SceneState * diffuseState=0x060aa358, unsigned int objectMask=4294967295) Line 180 C++
Blocks_DEBUG.dll!ShadowMapManager::_onPreRender(SceneGraph * sg=0x02627038, const SceneState * state=0x060aa358) Line 78 C++
Blocks_DEBUG.dll!fastdelegate::FastDelegate2<SceneGraph *,SceneState const *,void>::operator()(SceneGraph * p1=0x02627038, const SceneState * p2=0x060aa358) Line 1078 + 0x1e bytes C++
Blocks_DEBUG.dll!Signal<void __cdecl(SceneGraph *,SceneState const *)>::trigger(SceneGraph * a=0x02627038, const SceneState * b=0x060aa358) Line 334 + 0x1b bytes C++
Blocks_DEBUG.dll!SceneGraph::renderScene(ScenePassType passType=SPT_Diffuse, unsigned int objectMask=4294967295) Line 166 C++
Blocks_DEBUG.dll!GameRenderWorld() Line 311 C++
Blocks_DEBUG.dll!GameTSCtrl::renderWorld(const RectI & updateRect={...}) Line 53 C++
Blocks_DEBUG.dll!GuiTSCtrl::onRender(Point2I offset={...}, const RectI & updateRect={...}) Line 255 C++
Blocks_DEBUG.dll!GameTSCtrl::onRender(Point2I offset={...}, const RectI & updateRect={...}) Line 156 C++
Blocks_DEBUG.dll!GuiCanvas::renderFrame(bool preRenderOnly=false, bool bufferSwap=true) Line 1559 C++
Blocks_DEBUG.dll!GuiCanvas::handlePaintEvent(unsigned int did=0) Line 220 C++
Blocks_DEBUG.dll!fastdelegate::FastDelegate1<unsigned int,void>::operator()(unsigned int p1=0) Line 993 + 0x1a bytes C++
Blocks_DEBUG.dll!Signal<void __cdecl(unsigned int)>::trigger(unsigned int a=0) Line 323 + 0x17 bytes C++
Blocks_DEBUG.dll!Journal::Call<Signal<void __cdecl(unsigned int)>,unsigned int>(Signal<void __cdecl(unsigned int)> * obj=0x026a01d8, void (unsigned int)* method=0x1057a6e7, unsigned int a=0) Line 541 + 0xa8 bytes C++
Blocks_DEBUG.dll!JournaledSignal<void __cdecl(unsigned int)>::trigger(unsigned int a=0) Line 52 + 0x12 bytes C++
Blocks_DEBUG.dll!GuiCanvas::paint() Line 1389 C++
Blocks_DEBUG.dll!fastdelegate::FastDelegate0<void>::operator()() Line 908 + 0x16 bytes C++
Blocks_DEBUG.dll!Signal<void __cdecl(void)>::trigger() Line 312 + 0x13 bytes C++
Blocks_DEBUG.dll!Process::processEvents() Line 62 C++
Blocks_DEBUG.dll!StandardMainLoop::doMainLoop() Line 542 + 0x5 bytes C++
Blocks_DEBUG.dll!torque_enginetick() Line 78 + 0x5 bytes C++
Blocks_DEBUG.dll!TorqueMain(int argc=2, const char * * argv=0x00dbcef8) Line 369 + 0x5 bytes C++
Blocks_DEBUG.dll!torque_winmain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * __formal=0x00000000, char * lpszCmdLine=0x00151f3a, HINSTANCE__ * __formal=0x00000000) Line 423 + 0x17 bytes C++
Blocks_DEBUG.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpszCmdLine=0x00151f3a, int nCommandShow=1) Line 47 + 0x16 bytes C++
Blocks_DEBUG.exe!__tmainCRTStartup() Line 263 + 0x2c bytes C
Blocks_DEBUG.exe!WinMainCRTStartup() Line 182 C
kernel32.dll!7c817077()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
Blocks_DEBUG.exe!_mtinitlocknum(int locknum=16843277) Line 288 + 0xe bytes C
00000001()

Could somebody help me to make this work?

#1
05/26/2011 (12:00 pm)
The FF Material is incomplete, and you need to make lots of changes to get it to work. But even when you do, you'll get severely limited. Also, many elements (like the ScatterSky and the terrain) rely on shaders and thus you cannot fallback the entire rendering to fixed function.

The best approach for integrated cards is having an ultra-low graphics mode where you still use shaders, but force Torque to user shader 2.0 and disable as much graphic features as you can. Disable normal mapping, or even lighting entirely if possible (set all materials to emissive). If you know how to make more complex shader modifications, you can edit the lighting.hlsl file and add an #ifdef for the ultra-low mode which uses a simplified lighting algorithm (use only one light instead of four, disable spotlight support, etc).
#2
05/26/2011 (2:15 pm)
Thank you for the tip, I will go this way then!