Core implementation of Physical Based Rendering.

This commit is contained in:
Areloch 2018-09-15 20:19:57 -05:00
parent 54f1d8c18e
commit b4a1d18f42
148 changed files with 4464 additions and 1016 deletions

View file

@ -116,11 +116,17 @@ Material::Material()
{
mDiffuse[i].set( 1.0f, 1.0f, 1.0f, 1.0f );
mDiffuseMapSRGB[i] = true;
mSpecular[i].set( 1.0f, 1.0f, 1.0f, 1.0f );
mSpecularPower[i] = 8.0f;
mSpecularStrength[i] = 1.0f;
mSmoothness[i] = 0.0f;
mMetalness[i] = 0.0f;
mPixelSpecular[i] = false;
mIsSRGb[i] = false;
mInvertSmoothness[i] = false;
mSmoothnessChan[i] = 0;
mAOChan[i] = 1;
mMetalChan[i] = 2;
mAccuEnabled[i] = false;
mAccuScale[i] = 1.0f;
@ -166,6 +172,9 @@ Material::Material()
// Deferred Shading
mMatInfoFlags[i] = 0.0f;
mRoughMapFilename[i].clear();
mAOMapFilename[i].clear();
mMetalMapFilename[i].clear();
}
dMemset(mCellIndex, 0, sizeof(mCellIndex));
@ -255,20 +264,12 @@ void Material::initPersistFields()
addField( "detailNormalMapStrength", TypeF32, Offset(mDetailNormalMapStrength, Material), MAX_STAGES,
"Used to scale the strength of the detail normal map when blended with the base normal map." );
addField("smoothness", TypeF32, Offset(mSmoothness, Material), MAX_STAGES,
"The degree of smoothness when not using a specularMap." );
addField("specular", TypeColorF, Offset(mSpecular, Material), MAX_STAGES,
"The color of the specular highlight when not using a specularMap." );
addField("specularPower", TypeF32, Offset(mSpecularPower, Material), MAX_STAGES,
"The hardness of the specular highlight when not using a specularMap." );
addField("specularStrength", TypeF32, Offset(mSpecularStrength, Material), MAX_STAGES,
"The strength of the specular highlight when not using a specularMap." );
addField("pixelSpecular", TypeBool, Offset(mPixelSpecular, Material), MAX_STAGES,
"This enables per-pixel specular highlights controlled by the alpha channel of the "
"normal map texture. Note that if pixel specular is enabled the DXTnm format will not "
"work with your normal map, unless you are also using a specular map." );
addField("metalness", TypeF32, Offset(mMetalness, Material), MAX_STAGES,
"The degree of Metalness when not using a specularMap." );
addProtectedField( "accuEnabled", TYPEID< bool >(), Offset( mAccuEnabled, Material ),
&_setAccuEnabled, &defaultProtectedGetFn, MAX_STAGES, "Accumulation texture." );
@ -288,10 +289,31 @@ void Material::initPersistFields()
addField("accuSpecular", TypeF32, Offset(mAccuSpecular, Material), MAX_STAGES,
"Changes specularity to this value where the accumulated material is present.");
addField("isSRGb", TypeBool, Offset(mIsSRGb, Material), MAX_STAGES,
"Substance Designer Workaround.");
addField("invertSmoothness", TypeBool, Offset(mInvertSmoothness, Material), MAX_STAGES,
"Treat Smoothness as Roughness");
addField( "specularMap", TypeImageFilename, Offset(mSpecularMapFilename, Material), MAX_STAGES,
"The specular map texture. The RGB channels of this texture provide a per-pixel replacement for the 'specular' parameter on the material. "
"If this texture contains alpha information, the alpha channel of the texture will be used as the gloss map. "
"This provides a per-pixel replacement for the 'specularPower' on the material" );
"Prepacked specular map texture. The RGB channels of this texture provide per-pixel reference values for: "
"smoothness (R), Ambient Occlusion (G), and metalness(B)");
addField("roughMap", TypeImageFilename, Offset(mRoughMapFilename, Material), MAX_STAGES,
"smoothness map. will be packed into the R channel of a packed 'specular' map");
addField("smoothnessChan", TypeF32, Offset(mSmoothnessChan, Material), MAX_STAGES,
"The input channel smoothness maps use.");
addField("aoMap", TypeImageFilename, Offset(mAOMapFilename, Material), MAX_STAGES,
"Ambient Occlusion map. will be packed into the G channel of a packed 'specular' map");
addField("AOChan", TypeF32, Offset(mAOChan, Material), MAX_STAGES,
"The input channel AO maps use.");
addField("metalMap", TypeImageFilename, Offset(mMetalMapFilename, Material), MAX_STAGES,
"Metalness map. will be packed into the B channel of a packed 'specular' map");
addField("metalChan", TypeF32, Offset(mMetalChan, Material), MAX_STAGES,
"The input channel metalness maps use.");
addField( "parallaxScale", TypeF32, Offset(mParallaxScale, Material), MAX_STAGES,
"Enables parallax mapping and defines the scale factor for the parallax effect. Typically "
@ -706,6 +728,13 @@ DefineConsoleMethod( Material, setAutoGenerated, void, (bool isAutoGenerated), ,
object->setAutoGenerated(isAutoGenerated);
}
DefineConsoleMethod(Material, getAutogeneratedFile, const char*, (), , "Get filename of autogenerated shader file")
{
SimObject *material = static_cast<SimObject *>(object);
return material->getFilename();
}
// Accumulation
bool Material::_setAccuEnabled( void *object, const char *index, const char *data )
{

View file

@ -213,7 +213,15 @@ public:
FileName mDetailMapFilename[MAX_STAGES];
FileName mNormalMapFilename[MAX_STAGES];
bool mIsSRGb[MAX_STAGES];
bool mInvertSmoothness[MAX_STAGES];
FileName mSpecularMapFilename[MAX_STAGES];
FileName mRoughMapFilename[MAX_STAGES];
F32 mSmoothnessChan[MAX_STAGES];
FileName mAOMapFilename[MAX_STAGES];
F32 mAOChan[MAX_STAGES];
FileName mMetalMapFilename[MAX_STAGES];
F32 mMetalChan[MAX_STAGES];
/// A second normal map which repeats at the detail map
/// scale and blended with the base normal map.
@ -226,11 +234,10 @@ public:
/// or if it has a texture it is multiplied against
/// the diffuse texture color.
LinearColorF mDiffuse[MAX_STAGES];
F32 mSmoothness[MAX_STAGES];
F32 mMetalness[MAX_STAGES];
LinearColorF mSpecular[MAX_STAGES];
F32 mSpecularPower[MAX_STAGES];
F32 mSpecularStrength[MAX_STAGES];
bool mPixelSpecular[MAX_STAGES];
bool mVertLit[MAX_STAGES];

View file

@ -43,6 +43,7 @@ ImplementFeatureType( MFT_DetailMap, MFG_Texture, 4.0f, true );
ImplementFeatureType( MFT_DiffuseColor, MFG_Texture, 5.0f, true );
ImplementFeatureType( MFT_DiffuseVertColor, MFG_Texture, 6.0f, true );
ImplementFeatureType( MFT_AlphaTest, MFG_Texture, 7.0f, true );
ImplementFeatureType(MFT_InvertSmoothness, U32(-1), -1, true);
ImplementFeatureType( MFT_SpecularMap, MFG_Texture, 8.0f, true );
ImplementFeatureType( MFT_NormalMap, MFG_Texture, 9.0f, true );
ImplementFeatureType( MFT_DetailNormalMap, MFG_Texture, 10.0f, true );
@ -51,14 +52,15 @@ ImplementFeatureType( MFT_Imposter, U32(-1), -1, true );
ImplementFeatureType( MFT_AccuMap, MFG_PreLighting, 2.0f, true );
ImplementFeatureType( MFT_RTLighting, MFG_Lighting, 2.0f, true );
ImplementFeatureType( MFT_SubSurface, MFG_Lighting, 3.0f, true );
ImplementFeatureType( MFT_LightMap, MFG_Lighting, 4.0f, true );
ImplementFeatureType( MFT_ToneMap, MFG_Lighting, 5.0f, true );
ImplementFeatureType( MFT_VertLitTone, MFG_Lighting, 6.0f, false );
ImplementFeatureType( MFT_VertLit, MFG_Lighting, 7.0f, true );
ImplementFeatureType( MFT_PixSpecular, MFG_Lighting, 9.0f, true );
ImplementFeatureType( MFT_LightMap, MFG_Lighting, 3.0f, true );
ImplementFeatureType( MFT_ToneMap, MFG_Lighting, 4.0f, true );
ImplementFeatureType( MFT_VertLitTone, MFG_Lighting, 5.0f, false );
ImplementFeatureType( MFT_PixSpecular, MFG_Lighting, 6.0f, true );
ImplementFeatureType( MFT_StaticCubemap, U32(-1), -1.0, true );
ImplementFeatureType( MFT_CubeMap, MFG_Lighting, 7.0f, true );
ImplementFeatureType( MFT_SubSurface, MFG_Lighting, 8.0f, true );
ImplementFeatureType( MFT_VertLit, MFG_Lighting, 9.0f, true );
ImplementFeatureType( MFT_MinnaertShading, MFG_Lighting, 10.0f, true );
ImplementFeatureType( MFT_CubeMap, MFG_Lighting, 11.0f, true );
ImplementFeatureType( MFT_GlowMask, MFG_PostLighting, 1.0f, true );
ImplementFeatureType( MFT_Visibility, MFG_PostLighting, 2.0f, true );
@ -99,8 +101,6 @@ ImplementFeatureType( MFT_ImposterVert, MFG_PreTransform, 1.0, false );
// Deferred Shading
ImplementFeatureType( MFT_isDeferred, U32(-1), -1, true );
ImplementFeatureType( MFT_SkyBox, MFG_Transform, 1.0f, false );
ImplementFeatureType( MFT_DeferredEmptySpec, MFG_Texture, 8.01f, false );
ImplementFeatureType( MFT_DeferredSpecMap, MFG_Texture, 8.2f, false );
ImplementFeatureType( MFT_DeferredSpecVars, MFG_Texture, 8.5f, false );
ImplementFeatureType( MFT_DeferredMatInfoFlags, MFG_Texture, 8.7f, false );

View file

@ -122,8 +122,10 @@ DeclareFeatureType( MFT_ToneMap );
DeclareFeatureType( MFT_VertLit );
DeclareFeatureType( MFT_VertLitTone );
DeclareFeatureType( MFT_StaticCubemap );
DeclareFeatureType( MFT_CubeMap );
DeclareFeatureType( MFT_PixSpecular );
DeclareFeatureType( MFT_InvertSmoothness );
DeclareFeatureType( MFT_SpecularMap );
DeclareFeatureType( MFT_GlossMap );
@ -189,5 +191,4 @@ DeclareFeatureType( MFT_SkyBox );
DeclareFeatureType( MFT_DeferredSpecMap );
DeclareFeatureType( MFT_DeferredSpecVars );
DeclareFeatureType( MFT_DeferredMatInfoFlags );
DeclareFeatureType( MFT_DeferredEmptySpec );
#endif // _MATERIALFEATURETYPES_H_

View file

@ -125,7 +125,7 @@ void ProcessedMaterial::_setBlendState(Material::BlendOp blendOp, GFXStateBlockD
case Material::Mul:
{
desc.blendSrc = GFXBlendDestColor;
desc.blendDest = GFXBlendZero;
desc.blendDest = GFXBlendInvSrcAlpha;
break;
}
case Material::LerpAlpha:
@ -174,6 +174,11 @@ GFXTexHandle ProcessedMaterial::_createTexture( const char* filename, GFXTexture
return GFXTexHandle( _getTexturePath(filename), profile, avar("%s() - NA (line %d)", __FUNCTION__, __LINE__) );
}
GFXTexHandle ProcessedMaterial::_createCompositeTexture(const char *filenameR, const char *filenameG, const char *filenameB, const char *filenameA, U32 inputKey[4], GFXTextureProfile *profile)
{
return GFXTexHandle(_getTexturePath(filenameR), _getTexturePath(filenameG), _getTexturePath(filenameB), _getTexturePath(filenameA), inputKey, profile, avar("%s() - NA (line %d)", __FUNCTION__, __LINE__));
}
void ProcessedMaterial::addStateBlockDesc(const GFXStateBlockDesc& sb)
{
mUserDefined = sb;
@ -379,100 +384,120 @@ void ProcessedMaterial::_setRenderState( const SceneRenderState *state,
void ProcessedMaterial::_setStageData()
{
// Only do this once
if ( mHasSetStageData )
if (mHasSetStageData)
return;
mHasSetStageData = true;
U32 i;
// Load up all the textures for every possible stage
for( i=0; i<Material::MAX_STAGES; i++ )
for (i = 0; i < Material::MAX_STAGES; i++)
{
// DiffuseMap
if( mMaterial->mDiffuseMapFilename[i].isNotEmpty() )
if (mMaterial->mDiffuseMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_DiffuseMap, _createTexture( mMaterial->mDiffuseMapFilename[i], &GFXStaticTextureSRGBProfile) );
if (!mStages[i].getTex( MFT_DiffuseMap ))
mStages[i].setTex(MFT_DiffuseMap, _createTexture(mMaterial->mDiffuseMapFilename[i], &GFXStaticTextureSRGBProfile));
if (!mStages[i].getTex(MFT_DiffuseMap))
{
//If we start with a #, we're probably actually attempting to hit a named target and it may not get a hit on the first pass. So we'll
//pass on the error rather than spamming the console
if (!mMaterial->mDiffuseMapFilename[i].startsWith("#"))
mMaterial->logError("Failed to load diffuse map %s for stage %i", _getTexturePath(mMaterial->mDiffuseMapFilename[i]).c_str(), i);
// Load a debug texture to make it clear to the user
// that the texture for this stage was missing.
mStages[i].setTex( MFT_DiffuseMap, _createTexture( GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile) );
mStages[i].setTex(MFT_DiffuseMap, _createTexture(GFXTextureManager::getMissingTexturePath().c_str(), &GFXStaticTextureSRGBProfile));
}
}
// OverlayMap
if( mMaterial->mOverlayMapFilename[i].isNotEmpty() )
if (mMaterial->mOverlayMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_OverlayMap, _createTexture( mMaterial->mOverlayMapFilename[i], &GFXStaticTextureSRGBProfile ) );
if(!mStages[i].getTex( MFT_OverlayMap ))
mStages[i].setTex(MFT_OverlayMap, _createTexture(mMaterial->mOverlayMapFilename[i], &GFXStaticTextureSRGBProfile));
if (!mStages[i].getTex(MFT_OverlayMap))
mMaterial->logError("Failed to load overlay map %s for stage %i", _getTexturePath(mMaterial->mOverlayMapFilename[i]).c_str(), i);
}
// LightMap
if( mMaterial->mLightMapFilename[i].isNotEmpty() )
if (mMaterial->mLightMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_LightMap, _createTexture( mMaterial->mLightMapFilename[i], &GFXStaticTextureSRGBProfile ) );
if(!mStages[i].getTex( MFT_LightMap ))
mStages[i].setTex(MFT_LightMap, _createTexture(mMaterial->mLightMapFilename[i], &GFXStaticTextureSRGBProfile));
if (!mStages[i].getTex(MFT_LightMap))
mMaterial->logError("Failed to load light map %s for stage %i", _getTexturePath(mMaterial->mLightMapFilename[i]).c_str(), i);
}
// ToneMap
if( mMaterial->mToneMapFilename[i].isNotEmpty() )
if (mMaterial->mToneMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_ToneMap, _createTexture( mMaterial->mToneMapFilename[i], &GFXStaticTextureProfile) );
if(!mStages[i].getTex( MFT_ToneMap ))
mStages[i].setTex(MFT_ToneMap, _createTexture(mMaterial->mToneMapFilename[i], &GFXStaticTextureProfile));
if (!mStages[i].getTex(MFT_ToneMap))
mMaterial->logError("Failed to load tone map %s for stage %i", _getTexturePath(mMaterial->mToneMapFilename[i]).c_str(), i);
}
// DetailMap
if( mMaterial->mDetailMapFilename[i].isNotEmpty() )
if (mMaterial->mDetailMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_DetailMap, _createTexture( mMaterial->mDetailMapFilename[i], &GFXStaticTextureProfile) );
if(!mStages[i].getTex( MFT_DetailMap ))
mStages[i].setTex(MFT_DetailMap, _createTexture(mMaterial->mDetailMapFilename[i], &GFXStaticTextureProfile));
if (!mStages[i].getTex(MFT_DetailMap))
mMaterial->logError("Failed to load detail map %s for stage %i", _getTexturePath(mMaterial->mDetailMapFilename[i]).c_str(), i);
}
// NormalMap
if( mMaterial->mNormalMapFilename[i].isNotEmpty() )
if (mMaterial->mNormalMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_NormalMap, _createTexture( mMaterial->mNormalMapFilename[i], &GFXNormalMapProfile) );
if(!mStages[i].getTex( MFT_NormalMap ))
mStages[i].setTex(MFT_NormalMap, _createTexture(mMaterial->mNormalMapFilename[i], &GFXNormalMapProfile));
if (!mStages[i].getTex(MFT_NormalMap))
mMaterial->logError("Failed to load normal map %s for stage %i", _getTexturePath(mMaterial->mNormalMapFilename[i]).c_str(), i);
}
// Detail Normal Map
if( mMaterial->mDetailNormalMapFilename[i].isNotEmpty() )
if (mMaterial->mDetailNormalMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_DetailNormalMap, _createTexture( mMaterial->mDetailNormalMapFilename[i], &GFXNormalMapProfile) );
if(!mStages[i].getTex( MFT_DetailNormalMap ))
mStages[i].setTex(MFT_DetailNormalMap, _createTexture(mMaterial->mDetailNormalMapFilename[i], &GFXNormalMapProfile));
if (!mStages[i].getTex(MFT_DetailNormalMap))
mMaterial->logError("Failed to load normal map %s for stage %i", _getTexturePath(mMaterial->mDetailNormalMapFilename[i]).c_str(), i);
}
GFXTextureProfile* profile = &GFXStaticTextureProfile;
if (mMaterial->mIsSRGb[i])
profile = &GFXStaticTextureSRGBProfile;
// SpecularMap
if( mMaterial->mSpecularMapFilename[i].isNotEmpty() )
if (mMaterial->mSpecularMapFilename[i].isNotEmpty())
{
mStages[i].setTex( MFT_SpecularMap, _createTexture( mMaterial->mSpecularMapFilename[i], &GFXStaticTextureSRGBProfile) );
if(!mStages[i].getTex( MFT_SpecularMap ))
mStages[i].setTex(MFT_SpecularMap, _createTexture(mMaterial->mSpecularMapFilename[i], profile));
if (!mStages[i].getTex(MFT_SpecularMap))
mMaterial->logError("Failed to load specular map %s for stage %i", _getTexturePath(mMaterial->mSpecularMapFilename[i]).c_str(), i);
}
else
{
if (mMaterial->mRoughMapFilename[i].isNotEmpty() && mMaterial->mMetalMapFilename[i].isNotEmpty())
{
U32 inputKey[4];
inputKey[0] = mMaterial->mSmoothnessChan[i];
inputKey[1] = mMaterial->mAOChan[i];
inputKey[2] = mMaterial->mMetalChan[i];
inputKey[3] = NULL;
mStages[i].setTex(MFT_SpecularMap, _createCompositeTexture(mMaterial->mRoughMapFilename[i], mMaterial->mAOMapFilename[i],
mMaterial->mMetalMapFilename[i], "",
inputKey, profile));
if (!mStages[i].getTex(MFT_SpecularMap))
mMaterial->logError("Failed to load specular map %s for stage %i", _getTexturePath(mMaterial->mSpecularMapFilename[i]).c_str(), i);
}
}
}
mMaterial->mCubemapData = dynamic_cast<CubemapData*>(Sim::findObject( mMaterial->mCubemapName ));
if( !mMaterial->mCubemapData )
mMaterial->mCubemapData = NULL;
mMaterial->mCubemapData = dynamic_cast<CubemapData*>(Sim::findObject(mMaterial->mCubemapName));
if (!mMaterial->mCubemapData)
mMaterial->mCubemapData = NULL;
// If we have a cubemap put it on stage 0 (cubemaps only supported on stage 0)
if( mMaterial->mCubemapData )
if (mMaterial->mCubemapData)
{
mMaterial->mCubemapData->createMap();
mStages[0].setCubemap( mMaterial->mCubemapData->mCubemap );
if ( !mStages[0].getCubemap() )
mStages[0].setCubemap(mMaterial->mCubemapData->mCubemap);
if (!mStages[0].getCubemap())
mMaterial->logError("Failed to load cubemap");
}
}

View file

@ -285,6 +285,7 @@ protected:
/// Loads the texture located at _getTexturePath(filename) and gives it the specified profile
GFXTexHandle _createTexture( const char *filename, GFXTextureProfile *profile );
GFXTexHandle _createCompositeTexture(const char *filenameR, const char *filenameG, const char *filenameB, const char *filenameA, U32 inputKey[4], GFXTextureProfile *profile);
/// @name State blocks
///

View file

@ -56,8 +56,8 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/
mTexMatSC = shader->getShaderConstHandle(ShaderGenVars::texMat);
mToneMapTexSC = shader->getShaderConstHandle(ShaderGenVars::toneMap);
mSpecularColorSC = shader->getShaderConstHandle(ShaderGenVars::specularColor);
mSpecularPowerSC = shader->getShaderConstHandle(ShaderGenVars::specularPower);
mSpecularStrengthSC = shader->getShaderConstHandle(ShaderGenVars::specularStrength);
mSmoothnessSC = shader->getShaderConstHandle(ShaderGenVars::smoothness);
mMetalnessSC = shader->getShaderConstHandle(ShaderGenVars::metalness);
mAccuScaleSC = shader->getShaderConstHandle("$accuScale");
mAccuDirectionSC = shader->getShaderConstHandle("$accuDirection");
mAccuStrengthSC = shader->getShaderConstHandle("$accuStrength");
@ -299,6 +299,8 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
// First we add all the features which the
// material has defined.
if (mMaterial->mInvertSmoothness[stageNum])
fd.features.addFeature(MFT_InvertSmoothness);
if ( mMaterial->isTranslucent() )
{
@ -335,7 +337,6 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
if ( features.hasFeature( MFT_UseInstancing ) &&
mMaxStages == 1 &&
!mMaterial->mGlow[0] &&
!mMaterial->mDynamicCubemap &&
shaderVersion >= 3.0f )
fd.features.addFeature( MFT_UseInstancing );
@ -363,6 +364,7 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
if (features.hasFeature(MFT_SkyBox))
{
fd.features.addFeature(MFT_StaticCubemap);
fd.features.addFeature(MFT_CubeMap);
fd.features.addFeature(MFT_SkyBox);
}
@ -1090,9 +1092,8 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons
if ( !shaderConsts->wasLost() )
return;
shaderConsts->setSafe(handles->mSpecularColorSC, mMaterial->mSpecular[stageNum]);
shaderConsts->setSafe(handles->mSpecularPowerSC, mMaterial->mSpecularPower[stageNum]);
shaderConsts->setSafe(handles->mSpecularStrengthSC, mMaterial->mSpecularStrength[stageNum]);
shaderConsts->setSafe(handles->mSmoothnessSC, mMaterial->mSmoothness[stageNum]);
shaderConsts->setSafe(handles->mMetalnessSC, mMaterial->mMetalness[stageNum]);
shaderConsts->setSafe(handles->mParallaxInfoSC, mMaterial->mParallaxScale[stageNum]);
shaderConsts->setSafe(handles->mMinnaertConstantSC, mMaterial->mMinnaertConstant[stageNum]);
@ -1262,21 +1263,25 @@ void ProcessedShaderMaterial::setNodeTransforms(const MatrixF *transforms, const
void ProcessedShaderMaterial::setSceneInfo(SceneRenderState * state, const SceneData& sgData, U32 pass)
{
PROFILE_SCOPE( ProcessedShaderMaterial_setSceneInfo );
PROFILE_SCOPE(ProcessedShaderMaterial_setSceneInfo);
GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
ShaderConstHandles* handles = _getShaderConstHandles(pass);
// Set cubemap stuff here (it's convenient!)
const Point3F &eyePosWorld = state->getCameraPosition();
if ( handles->mCubeEyePosSC->isValid() )
if (_hasCubemap(pass) || mMaterial->mDynamicCubemap)
{
if(_hasCubemap(pass) || mMaterial->mDynamicCubemap)
if (handles->mCubeEyePosSC->isValid())
{
Point3F cubeEyePos = eyePosWorld - sgData.objTrans->getPosition();
shaderConsts->set(handles->mCubeEyePosSC, cubeEyePos);
shaderConsts->set(handles->mCubeEyePosSC, cubeEyePos);
}
}
if (sgData.cubemap)
shaderConsts->setSafe(handles->mCubeMipsSC, (F32)sgData.cubemap->getMipMapLevels());
else
shaderConsts->setSafe(handles->mCubeMipsSC, 1.0f);
shaderConsts->setSafe(handles->mVisiblitySC, sgData.visibility);

View file

@ -45,8 +45,8 @@ public:
GFXShaderConstHandle* mToneMapTexSC;
GFXShaderConstHandle* mTexMatSC;
GFXShaderConstHandle* mSpecularColorSC;
GFXShaderConstHandle* mSpecularPowerSC;
GFXShaderConstHandle* mSpecularStrengthSC;
GFXShaderConstHandle* mSmoothnessSC;
GFXShaderConstHandle* mMetalnessSC;
GFXShaderConstHandle* mParallaxInfoSC;
GFXShaderConstHandle* mAccuScaleSC;
GFXShaderConstHandle* mAccuDirectionSC;