| 47 | } |
| 48 | |
| 49 | void ShadowMaterialHook::init( BaseMatInstance *inMat ) |
| 50 | { |
| 51 | if( !inMat->isValid() ) |
| 52 | return; |
| 53 | |
| 54 | // Tweak the feature data to include just what we need. |
| 55 | FeatureSet features; |
| 56 | features.addFeature( MFT_VertTransform ); |
| 57 | features.addFeature( MFT_DiffuseMap ); |
| 58 | features.addFeature( MFT_TexAnim ); |
| 59 | features.addFeature( MFT_AlphaTest ); |
| 60 | features.addFeature( MFT_Visibility ); |
| 61 | |
| 62 | // Actually we want to include features from the inMat |
| 63 | // if they operate on the preTransform verts so things |
| 64 | // like wind/deformation effects will also affect the shadow. |
| 65 | const FeatureSet &inFeatures = inMat->getFeatures(); |
| 66 | for ( U32 i = 0; i < inFeatures.getCount(); i++ ) |
| 67 | { |
| 68 | const FeatureType& ft = inFeatures.getAt(i); |
| 69 | |
| 70 | if ( ft.getGroup() == MFG_PreTransform ) |
| 71 | features.addFeature( ft ); |
| 72 | } |
| 73 | |
| 74 | // Do instancing in shadows if we can. |
| 75 | if ( inFeatures.hasFeature( MFT_UseInstancing ) ) |
| 76 | features.addFeature( MFT_UseInstancing ); |
| 77 | |
| 78 | Material *shadowMat = (Material*)inMat->getMaterial(); |
| 79 | if ( dynamic_cast<CustomMaterial*>( shadowMat ) ) |
| 80 | { |
| 81 | // This is a custom material... who knows what it really does, but |
| 82 | // if it wasn't already filtered out of the shadow render then just |
| 83 | // give it some default depth out material. |
| 84 | shadowMat = MATMGR->getMaterialDefinitionByName( "AL_DefaultShadowMaterial" ); |
| 85 | } |
| 86 | |
| 87 | // By default we want to disable some states |
| 88 | // that the material might enable for us. |
| 89 | GFXStateBlockDesc forced; |
| 90 | forced.setBlend( false ); |
| 91 | forced.setAlphaTest( false ); |
| 92 | |
| 93 | // We should force on zwrite as the deferred |
| 94 | // will disable it by default. |
| 95 | forced.setZReadWrite( true, true ); |
| 96 | |
| 97 | // TODO: Should we render backfaces for |
| 98 | // shadows or does the ESM take care of |
| 99 | // all our acne issues? |
| 100 | //forced.setCullMode( GFXCullCW ); |
| 101 | |
| 102 | // Vector, and spotlights use the same shadow material. |
| 103 | BaseMatInstance *newMat = new ShadowMatInstance( shadowMat ); |
| 104 | newMat->setUserObject( inMat->getUserObject() ); |
| 105 | newMat->getFeaturesDelegate().bind( &ShadowMaterialHook::_overrideFeatures ); |
| 106 | newMat->addStateBlockDesc( forced ); |
nothing calls this directly
no test coverage detected