本文整理汇总了C++中BaseMatInstance类的典型用法代码示例。如果您正苦于以下问题:C++ BaseMatInstance类的具体用法?C++ BaseMatInstance怎么用?C++ BaseMatInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseMatInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: internalAddElement
void RenderGlowMgr::addElement( RenderInst *inst )
{
// Skip out if we don't have the glow post
// effect enabled at this time.
if ( !isGlowEnabled() )
return;
// TODO: We need to get the scene state here in a more reliable
// manner so we can skip glow in a non-diffuse render pass.
//if ( !mParentManager->getSceneManager()->getSceneState()->isDiffusePass() )
//return RenderBinManager::arSkipped;
ParticleRenderInst *particleInst = NULL;
if(inst->type == RenderPassManager::RIT_Particle)
particleInst = static_cast<ParticleRenderInst*>(inst);
if(particleInst && particleInst->glow)
{
internalAddElement(inst);
return;
}
// Skip it if we don't have a glowing material.
BaseMatInstance *matInst = getMaterial( inst );
if ( !matInst || !matInst->hasGlow() )
return;
internalAddElement(inst);
}
示例2: _render
void TSForestCellBatch::_render( const SceneRenderState *state )
{
if ( !mVB.isValid() ||
( state->isShadowPass() && !TSLastDetail::smCanShadow ) )
return;
// Make sure we have a material to render with.
BaseMatInstance *mat = state->getOverrideMaterial( mDetail->getMatInstance() );
if ( mat == NULL )
return;
// We don't really render here... we submit it to
// the render manager which collects all the batches
// in the scene, sorts them by texture, sets up the
// shader, and then renders them all at once.
ImposterBatchRenderInst *inst = state->getRenderPass()->allocInst<ImposterBatchRenderInst>();
inst->mat = mat;
inst->vertBuff = &mVB;
// We sort by the imposter type first so that RIT_Imposter and
// RIT_ImposterBatches do not get mixed together.
//
// We then sort by material.
//
inst->defaultKey = 0;
inst->defaultKey2 = mat->getStateHint();
state->getRenderPass()->addInst( inst );
}
示例3: PROFILE_SCOPE
BaseMatInstance* InstancingMaterialHook::getInstancingMat( BaseMatInstance *matInst )
{
PROFILE_SCOPE( InstancingMaterialHook_GetInstancingMat );
if ( matInst == NULL )
return NULL;
InstancingMaterialHook *hook = matInst->getHook<InstancingMaterialHook>();
if ( hook == NULL )
{
hook = new InstancingMaterialHook();
matInst->addHook( hook );
BaseMatInstance *instMat = matInst->getMaterial()->createMatInstance();
FeatureSet features( matInst->getRequestedFeatures() );
features.addFeature( MFT_UseInstancing );
if ( !instMat->init( features, matInst->getVertexFormat() ) )
SAFE_DELETE( instMat );
hook->mMatInst = instMat;
}
return hook->mMatInst;
}
示例4: allocateAndRegister
BaseMatInstance * MaterialManager::createMeshDebugMatInstance(const ColorF &meshColor)
{
String meshDebugStr = String::ToString( "Torque_MeshDebug_%d", meshColor.getRGBAPack() );
Material *debugMat;
if (!Sim::findObject(meshDebugStr,debugMat))
{
debugMat = allocateAndRegister( meshDebugStr );
debugMat->mDiffuse[0] = meshColor;
debugMat->mEmissive[0] = true;
}
BaseMatInstance *debugMatInstance = NULL;
if( debugMat != NULL )
{
debugMatInstance = debugMat->createMatInstance();
GFXStateBlockDesc desc;
desc.setCullMode(GFXCullNone);
desc.fillMode = GFXFillWireframe;
debugMatInstance->addStateBlockDesc(desc);
// Disable fog and other stuff.
FeatureSet debugFeatures;
debugFeatures.addFeature( MFT_DiffuseColor );
debugMatInstance->init( debugFeatures, getGFXVertexFormat<GFXVertexPCN>() );
}
return debugMatInstance;
}
示例5: init
void ImposterCaptureMaterialHook::init( BaseMatInstance *inMat )
{
// We cannot capture impostors on custom materials
// as we don't know how to get just diffuse and just
// normals rendering.
if ( dynamic_cast<CustomMaterial*>( inMat->getMaterial() ) )
return;
// Tweak the feature data to include just what we need.
FeatureSet features;
features.addFeature( MFT_VertTransform );
features.addFeature( MFT_DiffuseMap );
features.addFeature( MFT_OverlayMap );
features.addFeature( MFT_DetailMap );
features.addFeature( MFT_DiffuseColor );
features.addFeature( MFT_AlphaTest );
features.addFeature( MFT_IsTranslucent );
const String &matName = inMat->getMaterial()->getName();
mDiffuseMatInst = MATMGR->createMatInstance( matName );
mDiffuseMatInst->getFeaturesDelegate().bind( &ImposterCaptureMaterialHook::_overrideFeatures );
mDiffuseMatInst->init( features, inMat->getVertexFormat() );
features.addFeature( MFT_IsDXTnm );
features.addFeature( MFT_NormalMap );
features.addFeature( MFT_NormalsOut );
mNormalsMatInst = MATMGR->createMatInstance( matName );
mNormalsMatInst->getFeaturesDelegate().bind( &ImposterCaptureMaterialHook::_overrideFeatures );
mNormalsMatInst->init( features, inMat->getVertexFormat() );
}
示例6: addElement
void RenderTranslucentMgr::addElement( RenderInst *inst )
{
// Right off the bat if its not translucent skip it.
if ( !inst->translucentSort )
return;
// What type of instance is this.
const bool isMeshInst = inst->type == RenderPassManager::RIT_Translucent;
// Get its material if its a mesh.
BaseMatInstance* matInst = NULL;
if ( isMeshInst )
matInst = static_cast<MeshRenderInst*>( inst )->matInst;
// If the material isn't translucent the skip it.
if ( matInst && !matInst->getMaterial()->isTranslucent() )
return;
// We made it this far, add the instance.
mElementList.increment();
MainSortElem& elem = mElementList.last();
elem.inst = inst;
// Override the instances default key to be the sort distance. All
// the pointer dereferencing is in there to prevent us from losing
// information when converting to a U32.
elem.key = *((U32*)&inst->sortDistSq);
AssertFatal( inst->defaultKey != 0, "RenderTranslucentMgr::addElement() - Got null sort key... did you forget to set it?" );
// Then use the instances primary key as our secondary key
elem.key2 = inst->defaultKey;
}
示例7: hasAccumulation
// Returns true is the shape contains any materials with accumulation enabled.
bool TSShapeInstance::hasAccumulation()
{
bool result = false;
for ( U32 i = 0; i < mMaterialList->size(); ++i )
{
BaseMatInstance* mat = mMaterialList->getMaterialInst(i);
if ( mat->hasAccumulation() )
result = true;
}
return result;
}
示例8: PROFILE_SCOPE
void GroundPlane::prepRenderImage( SceneRenderState* state )
{
PROFILE_SCOPE( GroundPlane_prepRenderImage );
// TODO: Should we skip rendering the ground plane into
// the shadows? Its not like you can ever get under it.
if ( !mMaterial )
return;
// If we don't have a material instance after the override then
// we can skip rendering all together.
BaseMatInstance *matInst = state->getOverrideMaterial( mMaterial );
if ( !matInst )
return;
PROFILE_SCOPE( GroundPlane_prepRender );
// Update the geometry.
createGeometry( state->getCullingFrustum() );
if( mVertexBuffer.isNull() )
return;
// Add a render instance.
RenderPassManager* pass = state->getRenderPass();
MeshRenderInst* ri = pass->allocInst< MeshRenderInst >();
ri->type = RenderPassManager::RIT_Mesh;
ri->vertBuff = &mVertexBuffer;
ri->primBuff = &mPrimitiveBuffer;
ri->prim = &mPrimitive;
ri->matInst = matInst;
ri->objectToWorld = pass->allocUniqueXform( MatrixF::Identity );
ri->worldToCamera = pass->allocSharedXform( RenderPassManager::View );
ri->projection = pass->allocSharedXform( RenderPassManager::Projection );
ri->visibility = 1.0f;
ri->translucentSort = matInst->getMaterial()->isTranslucent();
ri->defaultKey = matInst->getStateHint();
if( ri->translucentSort )
ri->type = RenderPassManager::RIT_Translucent;
// If we need lights then set them up.
if ( matInst->isForwardLit() )
{
LightQuery query;
query.init( getWorldSphere() );
query.getLights( ri->lights, 8 );
}
pass->addInst( ri );
}
示例9: createMatInstance
BaseMatInstance* MaterialManager::createMatInstance( const String &matName,
const FeatureSet& features,
const GFXVertexFormat *vertexFormat )
{
BaseMatInstance* mat = createMatInstance(matName);
if (mat)
{
mat->init( features, vertexFormat );
return mat;
}
return NULL;
}
示例10: _updateVBIB
void PxCloth::prepRenderImage( SceneRenderState *state )
{
if ( mIsVBDirty )
_updateVBIB();
// Recreate the material if we need to.
if ( !mMatInst )
_initMaterial();
// If we don't have a material instance after the override then
// we can skip rendering all together.
BaseMatInstance *matInst = state->getOverrideMaterial( mMatInst );
if ( !matInst )
return;
MeshRenderInst *ri = state->getRenderPass()->allocInst<MeshRenderInst>();
// If we need lights then set them up.
if ( matInst->isForwardLit() )
{
LightQuery query;
query.init( getWorldSphere() );
query.getLights( ri->lights, 8 );
}
ri->projection = state->getRenderPass()->allocSharedXform(RenderPassManager::Projection);
ri->objectToWorld = &MatrixF::Identity;
ri->worldToCamera = state->getRenderPass()->allocSharedXform(RenderPassManager::View);
ri->type = RenderPassManager::RIT_Mesh;
ri->primBuff = &mPrimBuffer;
ri->vertBuff = &mVB;
ri->matInst = matInst;
ri->prim = state->getRenderPass()->allocPrim();
ri->prim->type = GFXTriangleList;
ri->prim->minIndex = 0;
ri->prim->startIndex = 0;
ri->prim->numPrimitives = mNumIndices / 3;
ri->prim->startVertex = 0;
ri->prim->numVertices = mNumVertices;
ri->defaultKey = matInst->getStateHint();
ri->defaultKey2 = (U32)ri->vertBuff;
state->getRenderPass()->addInst( ri );
}
示例11: PROFILE_START
void AtlasClipMapBatcher::renderClipMap( SceneGraphData& sgData, BaseMatInstance* overrideMat )
{
PROFILE_START(AtlasClipMapBatcher_renderClipMap);
for(S32 curBin=1; curBin<4; curBin++)
{
// If bin is empty, skip.
if(mRenderList[curBin].size() == 0)
continue;
for(S32 i=0; i<mRenderList[curBin].size(); i++)
{
// Grab the render note.
const RenderNote *rn = mRenderList[curBin][i];
// Set up clipmap levels.
if( !mFixedFunction )
{
BaseMatInstance* material = overrideMat;
if( !material )
switch( rn->levelCount )
{
case 2: material = mClipMap->getMaterialAndTextures( rn->levelEnd, rn->levelStart, -1, -1, false ); break;
case 3: material = mClipMap->getMaterialAndTextures( rn->levelEnd, rn->levelStart + 1, rn->levelStart, -1, false ); break;
case 4: material = mClipMap->getMaterialAndTextures( rn->levelEnd, rn->levelStart + 2, rn->levelStart + 1, rn->levelStart, false ); break;
default: material = MaterialManager::get()->getWarningMatInstance();
}
while( material->setupPass( mState, sgData ) )
rn->chunk->render();
}
else
{
Point4F clipmapMapping;
for( U32 curLayer = rn->levelEnd; curLayer >= rn->levelStart; -- curLayer )
{
BaseMatInstance* material = overrideMat;
if( !material )
material = mClipMap->bindTexturesFF( curLayer, clipmapMapping, curLayer == rn->levelEnd, false );
while( material->setupPass( mState, sgData ) )
rn->chunk->render();
}
}
}
}
PROFILE_END();
}
示例12: getShadowMat
BaseMatInstance* TerrainCellMaterial::getShadowMat()
{
// Find our material which has some settings
// defined on it in script.
Material *mat = MATMGR->getMaterialDefinitionByName( "AL_DefaultShadowMaterial" );
// Create the material instance adding the feature which
// handles rendering terrain cut outs.
FeatureSet features = MATMGR->getDefaultFeatures();
BaseMatInstance *matInst = mat->createMatInstance();
if ( !matInst->init( features, getGFXVertexFormat<TerrVertex>() ) )
{
delete matInst;
matInst = NULL;
}
return matInst;
}
示例13: initMaterial
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;
}
示例14: getDefaultFeatures
BaseMatInstance * MaterialManager::createWarningMatInstance()
{
Material *warnMat = static_cast<Material*>(Sim::findObject("WarningMaterial"));
BaseMatInstance *warnMatInstance = NULL;
if( warnMat != NULL )
{
warnMatInstance = warnMat->createMatInstance();
GFXStateBlockDesc desc;
desc.setCullMode(GFXCullNone);
warnMatInstance->addStateBlockDesc(desc);
warnMatInstance->init( getDefaultFeatures(),
getGFXVertexFormat<GFXVertexPNTTB>() );
}
return warnMatInstance;
}
示例15: dumpMaterialInstances
void MaterialManager::dumpMaterialInstances( BaseMaterialDefinition *target ) const
{
if ( !mMatInstanceList.size() )
return;
if ( target )
Con::printf( "--------------------- %s MatInstances ---------------------", target->getName() );
else
Con::printf( "--------------------- MatInstances %d ---------------------", mMatInstanceList.size() );
for( U32 i=0; i<mMatInstanceList.size(); i++ )
{
BaseMatInstance *inst = mMatInstanceList[i];
if ( target && inst->getMaterial() != target )
continue;
inst->dumpShaderInfo();
Con::printf( "" );
}
Con::printf( "---------------------- Dump complete ----------------------");
}