Steve_Yorkshire Posted January 30, 2017 Share Posted January 30, 2017 Finally worked out how to get customMaterials to use castShadows the same way as normal materials. As it's spread over multiple pages of the refraction/distortion thread - it's posted here together.First thing to do is stop customMaterials from ALWAYS casting a shadow. Someone at GG decided to force this regardless. Problem is, that it doesn't matter whether translucent or anything else has filtered shadows out, shadows will be forcibly set on here.lighting/shadowMap/shadowMatHook.cppvoid ShadowMaterialHook::init( BaseMatInstance *inMat ) { //... // Do instancing in shadows if we can. if ( inFeatures.hasFeature( MFT_UseInstancing ) ) features.addFeature( MFT_UseInstancing ); Material *shadowMat = (Material*)inMat->getMaterial(); /* yorks out start - let customMaterials decide for themselves if (dynamic_cast< CustomMaterial* >(shadowMat)) { // This is a custom material... who knows what it really does, but // if it wasn't already filtered out of the shadow render then just // give it some default depth out material. shadowMat = MATMGR->getMaterialDefinitionByName("AL_DefaultShadowMaterial"); } */ //yorks end of out // By default we want to disable some states // that the material might enable for us. GFXStateBlockDesc forced; //... source/materials/CustomMaterialDefinition.hclass CustomMaterial : public Material { typedef Material Parent; public: //... bool mForwardLit; bool mCastShadows;//yorks in F32 mVersion; // 0 = legacy, 1 = DX 8.1, 2 = DX 9.0 bool mRefract; //... virtual bool onAdd(); virtual void onRemove(); virtual bool castsShadows() const { return mCastShadows; }//yorks in //... source/materials/CustomMaterialDefinition.cppCustomMaterial::CustomMaterial() { //... mForwardLit = false; mCastShadows = true;//yorks in } //-------------------------------------------------------------------------- // Init fields //-------------------------------------------------------------------------- void CustomMaterial::initPersistFields() { //... addField("forwardLit", TypeBool, Offset(mForwardLit, CustomMaterial), "@brief Determines if the material should recieve lights in Basic Lighting. " "Has no effect in Advanced Lighting.\n\n"); //yorks start in addField("castShadows", TypeBool, Offset(mCastShadows, CustomMaterial), "If set to false the lighting system will not cast shadows from this material."); //yorks end in Parent::initPersistFields(); } After that you can control the shadows in your CustomMaterial. Remember shadows are on by default so your TorqueScript definition wants to look likesingleton CustomMaterial(Mat_wobble_Soldier_Main : Mat_Soldier_Main) { mapTo = "wobble_Soldier_Main"; translucent = true;//translucent materials (custom or standard) never cast shadows shader = wobbleTextureShader; sampler["diffuseMap"] = "#PreRenderTranslucent"; }; singleton CustomMaterial(Mat_wobble2_Soldier_Main : Mat_Soldier_Main) { mapTo = "wobble2_Soldier_Main"; translucent = false; //castShadows = true;//default is true so don't need this. shader = wobbleTextureShader; sampler["diffuseMap"] = "#PreRenderTranslucent"; }; singleton CustomMaterial(Mat_wobble3_Soldier_Main : Mat_Soldier_Main) { mapTo = "wobble3_Soldier_Main"; translucent = false; castShadows = false; shader = wobbleTextureShader; sampler["diffuseMap"] = "#PreRenderTranslucent"; }; And these 3 then look like this in-game:http://i.imgur.com/YJni7sA.jpg Quote Link to comment Share on other sites More sharing options...
Steve_Yorkshire Posted January 30, 2017 Author Share Posted January 30, 2017 And here's a standard customMaterial so you can actually see the model :Phttp://i.imgur.com/zYymlBm.jpg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.