Esempio n. 1
0
ProjectedShadow::ProjectedShadow( SceneObject *object )
{
    mParentObject = object;
    mShapeBase = dynamic_cast<ShapeBase*>( object );

    mRadius = 0;
    mLastRenderTime = 0;
    mUpdateTexture = false;

    mShadowLength = 10.0f;

    mDecalData = new DecalData;
    mDecalData->skipVertexNormals = true;

    mDecalInstance = NULL;

    mLastLightDir.set( 0, 0, 0 );
    mLastObjectPosition.set( object->getRenderPosition() );
    mLastObjectScale.set( object->getScale() );

    CustomMaterial *customMat = NULL;
    Sim::findObject( "BL_ProjectedShadowMaterial", customMat );
    if ( customMat )
    {
        mDecalData->material = customMat;
        mDecalData->matInst = customMat->createMatInstance();
    }
    else
        mDecalData->matInst = MATMGR->createMatInstance( "WarningMaterial" );

    mDecalData->matInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat<GFXVertexPNTT>() );

    mCasterPositionSC = NULL;
    mShadowLengthSC = NULL;
}
void ProcessedFFMaterial::_initPassStateBlock( RenderPassData *rpd, GFXStateBlockDesc &result )
{
   Parent::_initPassStateBlock( rpd, result );

   if ( mIsLightingMaterial )
   {
      result.ffLighting = true;
      result.blendDefined = true;
      result.blendEnable = true;
      result.blendSrc = GFXBlendOne;
      result.blendSrc = GFXBlendOne;
   }

   // This is here for generic FF shader fallbacks.
   CustomMaterial* custmat = dynamic_cast<CustomMaterial*>(mMaterial);
   if (custmat && custmat->getStateBlockData() )
      result.addDesc(custmat->getStateBlockData()->getState());
}
Esempio n. 3
0
bool WaterObject::initMaterial( S32 idx )
{
   // We must return false for any case which it is NOT safe for the caller
   // to use the indexed material.
   
   if ( idx < 0 || idx > NumMatTypes )
      return false;

   BaseMatInstance *mat = mMatInstances[idx];
   WaterMatParams &matParams = mMatParamHandles[idx];
   
   // Is it already initialized?

   if ( mat && mat->isValid() )
      return true;

   // Do we need to allocate anything?

   if ( mSurfMatName[idx].isNotEmpty() )
   {      
      if ( mat )
         SAFE_DELETE( mat );

      CustomMaterial *custMat;
      if ( Sim::findObject( mSurfMatName[idx], custMat ) && custMat->mShaderData )
         mat = custMat->createMatInstance();
      else
         mat = MATMGR->createMatInstance( mSurfMatName[idx] );

      const GFXVertexFormat *flags = getGFXVertexFormat<GFXVertexPC>();

      if ( mat && mat->init( MATMGR->getDefaultFeatures(), flags ) )
      {      
         mMatInstances[idx] = mat;
         matParams.init( mat );         
         return true;
      }
            
      SAFE_DELETE( mat );      
   }

   return false;
}
Esempio n. 4
0
bool ccKneeboard::apply_image_as_page(Graphics::Texture * tex)
{
    if (!tex)
        return false;
    const std::string & normalized_name = tex->Name();
    bool       have_material = resourcer->IsResourceExists(rtMaterial,normalized_name);
    Material * mat  = have_material ? (Material *)resourcer->GetResource(rtMaterial,normalized_name):
                      (Material *)resourcer->GetResourceByClass(rtMaterial,"IlsMaterial");
    if (!mat)
        return false;

    CustomMaterial *cmat = mat->QueryCustomMaterial();
    cmat->SetDiffuseColor(Vector3(1,1,1));
    cmat->SetDiffuseMap(0,tex);
    cmat->SetOpacity(1);
    cmat->SetLighted(false);
    cmat->SetTwoSided(true);
    if (!have_material)
    {
        mat->SetName(normalized_name);
        mat->Register();
        ccDrawable::materials[normalized_name] = mat;
    }
    static const std::string head =  "x = 1\
									 y  =  GetAspect()\
									 SetScale(1)\
									 picture = CreateElement 'ceTexPoly'\
									 picture.name = 'picture'\
									 picture.vertices   	 = {{-x,y},{x,y},{ x,-y},{-x,-y}}\
									 picture.indices	  	 = {0,1,2;0,2,3}\
/// Does the base render state block setting, normally per pass
void ProcessedFFMaterial::_initPassStateBlock(const Material::BlendOp blendOp, U32 numTex, const U32 texFlags[Material::MAX_TEX_PER_PASS], GFXStateBlockDesc& result)
{
   Parent::_initPassStateBlock(blendOp, numTex, texFlags, result);   
   if (mIsLightingMaterial)
   {
      result.ffLighting = true;
      result.blendDefined = true;
      result.blendEnable = true;
      result.blendSrc = GFXBlendOne;
      result.blendSrc = GFXBlendOne;
   }

   // This is here for generic FF shader fallbacks.
   CustomMaterial* custmat = dynamic_cast<CustomMaterial*>(mMaterial);
   if (custmat)
   {
      if (custmat->getStateBlockData())
      {
         result.addDesc(custmat->getStateBlockData()->getState());
      }      
   }
}