Skip to content

Commit

Permalink
Added an additional switch to deliberately treat static and dynamic c…
Browse files Browse the repository at this point in the history
…ubemaps slightly differently. TODO: adress HDR exacerbating the differences.
  • Loading branch information
Azaezel committed Sep 2, 2015
1 parent 6647060 commit db3dc27
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions Engine/source/materials/materialFeatureTypes.cpp
Expand Up @@ -62,6 +62,7 @@ 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 );
Expand Down
1 change: 1 addition & 0 deletions Engine/source/materials/materialFeatureTypes.h
Expand Up @@ -126,6 +126,7 @@ DeclareFeatureType( MFT_ToneMap );
DeclareFeatureType( MFT_VertLit );
DeclareFeatureType( MFT_VertLitTone );

DeclareFeatureType( MFT_StaticCubemap );
DeclareFeatureType( MFT_CubeMap );
DeclareFeatureType( MFT_PixSpecular );
DeclareFeatureType( MFT_FlipRB );
Expand Down
1 change: 1 addition & 0 deletions Engine/source/materials/processedShaderMaterial.cpp
Expand Up @@ -356,6 +356,7 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
//if (features.hasFeature(MFT_SkyBox))
if (mMaterial->mIsSky)
{
fd.features.addFeature(MFT_StaticCubemap);
fd.features.addFeature(MFT_CubeMap);
fd.features.addFeature(MFT_SkyBox);
}
Expand Down
7 changes: 4 additions & 3 deletions Engine/source/renderInstance/renderPrePassMgr.cpp
Expand Up @@ -772,11 +772,12 @@ void ProcessedPrePassMaterial::_determineFeatures( U32 stageNum,
if (!mMaterial->mEmissive[stageNum] && test && (test->getTypeMask() & (DynamicShapeObjectType | StaticObjectType | StaticShapeObjectType)))
envmapped = true;
// cubemaps only available on stage 0 for now - bramage
if ( stageNum < 1 &&
if ( stageNum < 1 &&
( ( mMaterial->mCubemapData && mMaterial->mCubemapData->mCubemap ) ||
mMaterial->mDynamicCubemap ) ||
mMaterial->mDynamicCubemap || envmapped)
mMaterial->mDynamicCubemap || envmapped) )
{
if (!mMaterial->mDynamicCubemap)
fd.features.addFeature(MFT_StaticCubemap);
newFeatures.addFeature( MFT_CubeMap );
newFeatures.removeFeature(MFT_UseInstancing);
}
Expand Down
7 changes: 5 additions & 2 deletions Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp
Expand Up @@ -1908,9 +1908,10 @@ void ReflectCubeFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
else
blendOp = Material::Mul;
}

Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
if (fd.features[MFT_isDeferred])
{
Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
//metalness: black(0) = color, white(1) = reflection
if (fd.features[MFT_ToneMap])
meta->addStatement(new GenOp(" @ *= vec4(pow(@,vec4(2.2)));\r\n", targ, texCube));
Expand All @@ -1919,7 +1920,7 @@ void ReflectCubeFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
}
else
{
Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var *metalness = (Var*)LangElement::find("metalness");
if (metalness)
{
Expand All @@ -1930,6 +1931,8 @@ void ReflectCubeFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
else
meta->addStatement(new GenOp(" @.rgb *= @.rgb;\r\n", targ, texCube));
}
if (fd.features[MFT_StaticCubemap]) //dynamic reflections are linearized coming and going. so do statics twice
meta->addStatement(new GenOp(" @ = vec4(pow(@,vec4(2.2)));\r\n", targ, targ));
output = meta;
}

Expand Down
1 change: 1 addition & 0 deletions Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp
Expand Up @@ -63,6 +63,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_NormalMap, new BumpFeatGLSL );
FEATUREMGR->registerFeature( MFT_DetailNormalMap, new NamedFeatureGLSL( "Detail Normal Map" ) );
FEATUREMGR->registerFeature( MFT_DetailMap, new DetailFeatGLSL );
FEATUREMGR->registerFeature( MFT_StaticCubemap, new NamedFeatureGLSL( "Static Cubemap" ) );
FEATUREMGR->registerFeature( MFT_CubeMap, new ReflectCubeFeatGLSL );
FEATUREMGR->registerFeature( MFT_PixSpecular, new PixelSpecularGLSL );
FEATUREMGR->registerFeature( MFT_FlipRB, new NamedFeatureGLSL( "Substance Workaround" ) );
Expand Down
7 changes: 5 additions & 2 deletions Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp
Expand Up @@ -1907,9 +1907,10 @@ void ReflectCubeFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
else
blendOp = Material::Mul;
}

Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
if (fd.features[MFT_isDeferred])
{
Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
//metalness: black(0) = color, white(1) = reflection
if (fd.features[MFT_ToneMap])
meta->addStatement(new GenOp(" @ *= pow(@,2.2);\r\n", targ, texCube));
Expand All @@ -1919,7 +1920,7 @@ void ReflectCubeFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
else
{
meta->addStatement(new GenOp(" //forward lit cubemapping\r\n"));
Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));

Var *metalness = (Var*)LangElement::find("metalness");
if (metalness)
Expand All @@ -1931,6 +1932,8 @@ void ReflectCubeFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
else
meta->addStatement(new GenOp(" @.rgb *= @.rgb;\r\n", targ, texCube));
}
if (fd.features[MFT_StaticCubemap]) //dynamic reflections are linearized coming and going. so do statics twice
meta->addStatement(new GenOp(" @ = pow(@,2.2);\r\n", targ, targ));
output = meta;
}

Expand Down
1 change: 1 addition & 0 deletions Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp
Expand Up @@ -62,6 +62,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_NormalMap, new BumpFeatHLSL );
FEATUREMGR->registerFeature( MFT_DetailNormalMap, new NamedFeatureHLSL( "Detail Normal Map" ) );
FEATUREMGR->registerFeature( MFT_DetailMap, new DetailFeatHLSL );
FEATUREMGR->registerFeature( MFT_StaticCubemap, new NamedFeatureHLSL( "Static Cubemap" ) );
FEATUREMGR->registerFeature( MFT_CubeMap, new ReflectCubeFeatHLSL );
FEATUREMGR->registerFeature( MFT_PixSpecular, new PixelSpecularHLSL );
FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureHLSL( "Translucent" ) );
Expand Down

0 comments on commit db3dc27

Please sign in to comment.