bool ProcessedCustomMaterial::init( const FeatureSet &features, 
                                    const GFXVertexFormat *vertexFormat,
                                    const MatFeaturesDelegate &featuresDelegate )
{
   // If we don't have a shader data... we have nothing to do.
   if ( !mCustomMaterial->mShaderData )
      return true;

   // Custom materials only do one pass at the moment... so
   // add one for the stage data to fill in.
   ShaderRenderPassData *rpd = new ShaderRenderPassData();
   mPasses.push_back( rpd );

   _setStageData();
   _initPassStateBlocks();   
   mStateHint.clear();

   // Note: We don't use the vertex format in a custom 
   // material at all right now.
   //
   // Maybe we can add some required semantics and
   // validate that the format fits the shader?

   // Build a composite list of shader macros from
   // the conditioner and the user defined lists.
   Vector<GFXShaderMacro> macros;
   macros.merge( mConditionerMacros );
   macros.merge( mUserMacros );

   // Ask the shader data to give us a shader instance.
   rpd->shader = mCustomMaterial->mShaderData->getShader( macros );      
   if ( !rpd->shader )
   {
      delete rpd;
      mPasses.clear();
      return false;
   }

   rpd->shaderHandles.init( rpd->shader, mCustomMaterial );      
   _initMaterialParameters();
   mDefaultParameters = allocMaterialParameters();
   setMaterialParameters( mDefaultParameters, 0 );
   mStateHint.init( this );
   
   return true;
}
示例#2
0
//
// Material init
//
bool ProcessedShaderMaterial::init( const FeatureSet &features, 
                                    const GFXVertexFormat *vertexFormat,
                                    const MatFeaturesDelegate &featuresDelegate )
{
   // Load our textures
   _setStageData();

   // Determine how many stages we use
   mMaxStages = getNumStages(); 
   mVertexFormat = vertexFormat;
   mFeatures.clear();
   mStateHint.clear();
   SAFE_DELETE(mInstancingState);

   for( U32 i=0; i<mMaxStages; i++ )
   {
      MaterialFeatureData fd;

      // Determine the features of this stage
      _determineFeatures( i, fd, features );
   
      // Let the delegate poke at the features.
      if ( featuresDelegate )
         featuresDelegate( this, i, fd, features );

      // Create the passes for this stage
      if ( fd.features.isNotEmpty() )
         if( !_createPasses( fd, i, features ) )
            return false;
   }

   _initRenderPassDataStateBlocks();
   _initMaterialParameters();
   mDefaultParameters =  allocMaterialParameters();
   setMaterialParameters( mDefaultParameters, 0 );
   mStateHint.init( this );   

   // Enable instancing if we have it.
   if ( mFeatures.hasFeature( MFT_UseInstancing ) )
   {
      mInstancingState = new InstancingState();
      mInstancingState->setFormat( &_getRPD( 0 )->shader->mInstancingFormat, mVertexFormat );
   }

   // Check for a RenderTexTargetBin assignment
   // *IMPORTANT NOTE* 
   // This is a temporary solution for getting diffuse mapping working with tex targets for standard materials
   // It should be removed once this is done properly, at that time the sAllowTextureTargetAssignment should also be removed 
   // from Material (it is necessary for catching shadow maps/post effect this shouldn't be applied to)
   if (Material::sAllowTextureTargetAssignment)
      if (mMaterial && mMaterial->mDiffuseMapFilename[0].isNotEmpty() && mMaterial->mDiffuseMapFilename[0].substr( 0, 1 ).equal("#"))
      {
         String texTargetBufferName = mMaterial->mDiffuseMapFilename[0].substr(1, mMaterial->mDiffuseMapFilename[0].length() - 1);
         NamedTexTarget *texTarget = NamedTexTarget::find( texTargetBufferName ); 

         RenderPassData* rpd = getPass(0);      

         if (rpd)
         {
            rpd->mTexSlot[0].texTarget = texTarget;
            rpd->mTexType[0] = Material::TexTarget;
         }
      }

   return true;
}