Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sahara #726

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,57 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
output = meta;
return;
}
else if (fd.features[MFT_AccuMap])
{
Var *bumpSample = (Var *)LangElement::find( "bumpSample" );
if( bumpSample == NULL )
{
MultiLine *meta = new MultiLine;

Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList );

Var *bumpMap = getNormalMapTex();

bumpSample = new Var;
bumpSample->setType( "float4" );
bumpSample->setName( "bumpSample" );
LangElement *bumpSampleDecl = new DecOp( bumpSample );

meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord ) );

if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
{
Var *bumpMap = (Var*)LangElement::find( "detailBumpMap" );
if ( !bumpMap ) {
bumpMap = new Var;
bumpMap->setType( "sampler2D" );
bumpMap->setName( "detailBumpMap" );
bumpMap->uniform = true;
bumpMap->sampler = true;
bumpMap->constNum = Var::getTexUnitNum();
}

texCoord = getInTexCoord( "detCoord", "float2", true, componentList );
LangElement *texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );

Var *detailBump = new Var;
detailBump->setName( "detailBump" );
detailBump->setType( "float4" );
meta->addStatement( expandNormalMap( texOp, new DecOp( detailBump ), detailBump, fd ) );

Var *detailBumpScale = new Var;
detailBumpScale->setType( "float" );
detailBumpScale->setName( "detailBumpStrength" );
detailBumpScale->uniform = true;
detailBumpScale->constSortPos = cspPass;
meta->addStatement( new GenOp( " @.xy += @.xy * @;\r\n", bumpSample, detailBump, detailBumpScale ) );
}

output = meta;

return;
}
}
else if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_RTLighting] )
Expand Down Expand Up @@ -397,7 +448,17 @@ void DeferredBumpFeatHLSL::setTexData( Material::StageData &stageDat,
return;
}

if ( !fd.features[MFT_Parallax] && !fd.features[MFT_SpecularMap] &&
if ( !fd.features[MFT_PrePassConditioner] && fd.features[MFT_AccuMap] )
{
passData.mTexType[ texIndex ] = Material::Bump;
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_NormalMap );

if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
{
passData.mTexType[ texIndex ] = Material::DetailBump;
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_DetailNormalMap );
}
} else if ( !fd.features[MFT_Parallax] && !fd.features[MFT_SpecularMap] &&
( fd.features[MFT_PrePassConditioner] ||
fd.features[MFT_PixSpecular] ) )
{
Expand Down Expand Up @@ -478,6 +539,15 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
AssertFatal( lightInfoSamp && d_specular && d_NL_Att,
"DeferredPixelSpecularHLSL::processPix - Something hosed the deferred features!" );

if (fd.features[ MFT_AccuMap ]) {
// change specularity where the accu texture is applied
Var *accuPlc = (Var*) LangElement::find( "plc" );
Var *accuSpecular = (Var*)LangElement::find( "accuSpecular" );
if(accuPlc != NULL && accuSpecular != NULL)
//d_specular = clamp(lerp( d_specular, accuSpecular * d_specular, plc.a), 0, 1)
meta->addStatement( new GenOp( " @ = clamp( lerp( @, @ * @, @.a), 0, 1);\r\n", d_specular, d_specular, accuSpecular, d_specular, accuPlc ) );
}

// (a^m)^n = a^(m*n)
meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n",
specDecl, d_specular, specPow, specStrength ) );
Expand Down
24 changes: 24 additions & 0 deletions Engine/source/materials/materialDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ Material::Material()
mSpecularStrength[i] = 1.0f;
mPixelSpecular[i] = false;

mAccuScale[i] = 1.0f;
mAccuDirection[i] = 1.0f;
mAccuStrength[i] = 0.6f;
mAccuCoverage[i] = 0.9f;
mAccuSpecular[i] = 16.0f;

mParallaxScale[i] = 0.0f;

mVertLit[i] = false;
Expand Down Expand Up @@ -249,6 +255,24 @@ void Material::initPersistFields()
"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("accuMap", TypeImageFilename, Offset(mAccuMapFilename, Material), MAX_STAGES,
"The accu map texture. It should be used much like a diffuse texture - except it is only placed in carefully chosen spots on the model.");

addField("accuScale", TypeF32, Offset(mAccuScale, Material), MAX_STAGES,
"The scale that is applied to the accu map texture. You can use this to fit the texture to smaller or larger objects.");

addField("accuDirection", TypeF32, Offset(mAccuDirection, Material), MAX_STAGES,
"The direction of the accumulation. Chose whether you want the accu map to go from top to bottom (ie. snow) or upwards (ie. mold).");

addField("accuStrength", TypeF32, Offset(mAccuStrength, Material), MAX_STAGES,
"The strength of the accu map. This changes the transparency of the accu map texture. Make it subtle or add more contrast.");

addField("accuCoverage", TypeF32, Offset(mAccuCoverage, Material), MAX_STAGES,
"The coverage ratio of the accu map texture. Use this to make the entire shape pick up some of the accu map texture or none at all.");

addField("accuSpecular", TypeF32, Offset(mAccuSpecular, Material), MAX_STAGES,
"Changes specularity to this value where the accumulated material is present.");

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. "
Expand Down
7 changes: 7 additions & 0 deletions Engine/source/materials/materialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------

#ifndef _MATERIALDEFINITION_H_
#define _MATERIALDEFINITION_H_

Expand Down Expand Up @@ -198,6 +199,12 @@ class Material : public BaseMaterialDefinition
// Data
//-----------------------------------------------------------------------
FileName mDiffuseMapFilename[MAX_STAGES];
String mAccuMapFilename[MAX_STAGES];
F32 mAccuScale[MAX_STAGES];
F32 mAccuDirection[MAX_STAGES];
F32 mAccuStrength[MAX_STAGES];
F32 mAccuCoverage[MAX_STAGES];
F32 mAccuSpecular[MAX_STAGES];
FileName mOverlayMapFilename[MAX_STAGES];
FileName mLightMapFilename[MAX_STAGES];
FileName mToneMapFilename[MAX_STAGES];
Expand Down
8 changes: 8 additions & 0 deletions Engine/source/materials/materialFeatureTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ ImplementFeatureType( MFT_TexAnim, MFG_PreTexture, 1.0f, true );
ImplementFeatureType( MFT_Parallax, MFG_PreTexture, 2.0f, true );
ImplementFeatureType( MFT_DiffuseVertColor, MFG_PreTexture, 3.0f, true );

ImplementFeatureType( MFT_AccuScale, MFG_PreTexture, 4.0f, true );
ImplementFeatureType( MFT_AccuDirection, MFG_PreTexture, 4.0f, true );
ImplementFeatureType( MFT_AccuStrength, MFG_PreTexture, 4.0f, true );
ImplementFeatureType( MFT_AccuCoverage, MFG_PreTexture, 4.0f, true );
ImplementFeatureType( MFT_AccuSpecular, MFG_PreTexture, 4.0f, true );

ImplementFeatureType( MFT_DiffuseMap, MFG_Texture, 2.0f, true );
ImplementFeatureType( MFT_OverlayMap, MFG_Texture, 3.0f, true );
ImplementFeatureType( MFT_DetailMap, MFG_Texture, 4.0f, true );
Expand All @@ -41,6 +47,8 @@ ImplementFeatureType( MFT_SpecularMap, MFG_Texture, 8.0f, true );
ImplementFeatureType( MFT_NormalMap, MFG_Texture, 9.0f, true );
ImplementFeatureType( MFT_DetailNormalMap, MFG_Texture, 10.0f, 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 );
Expand Down
7 changes: 7 additions & 0 deletions Engine/source/materials/materialFeatureTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ DeclareFeatureType( MFT_DetailMap );
DeclareFeatureType( MFT_DiffuseColor );
DeclareFeatureType( MFT_DetailNormalMap );

DeclareFeatureType( MFT_AccuMap );
DeclareFeatureType( MFT_AccuScale );
DeclareFeatureType( MFT_AccuDirection );
DeclareFeatureType( MFT_AccuStrength );
DeclareFeatureType( MFT_AccuCoverage );
DeclareFeatureType( MFT_AccuSpecular );

/// This feature enables vertex coloring for the diffuse channel.
DeclareFeatureType( MFT_DiffuseVertColor );

Expand Down
8 changes: 8 additions & 0 deletions Engine/source/materials/processedMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,14 @@ void ProcessedMaterial::_setStageData()
mMaterial->logError("Failed to load specular map %s for stage %i", _getTexturePath(mMaterial->mSpecularMapFilename[i]).c_str(), i);
}

// AccuMap
if( mMaterial->mAccuMapFilename[i].isNotEmpty() )
{
mStages[i].setTex( MFT_AccuMap, _createTexture( mMaterial->mAccuMapFilename[i], &GFXDefaultStaticDiffuseProfile ) );
if(!mStages[i].getTex( MFT_AccuMap ))
mMaterial->logError("Failed to load accu map %s for stage %i", _getTexturePath(mMaterial->mAccuMapFilename[i]).c_str(), i);
}

// EnironmentMap
if( mMaterial->mEnvMapFilename[i].isNotEmpty() )
{
Expand Down
41 changes: 41 additions & 0 deletions Engine/source/materials/processedShaderMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/
mSpecularColorSC = shader->getShaderConstHandle(ShaderGenVars::specularColor);
mSpecularPowerSC = shader->getShaderConstHandle(ShaderGenVars::specularPower);
mSpecularStrengthSC = shader->getShaderConstHandle(ShaderGenVars::specularStrength);
mAccuScaleSC = shader->getShaderConstHandle("$accuScale");
mAccuDirectionSC = shader->getShaderConstHandle("$accuDirection");
mAccuStrengthSC = shader->getShaderConstHandle("$accuStrength");
mAccuCoverageSC = shader->getShaderConstHandle("$accuCoverage");
mAccuSpecularSC = shader->getShaderConstHandle("$accuSpecular");
mParallaxInfoSC = shader->getShaderConstHandle("$parallaxInfo");
mFogDataSC = shader->getShaderConstHandle(ShaderGenVars::fogData);
mFogColorSC = shader->getShaderConstHandle(ShaderGenVars::fogColor);
Expand Down Expand Up @@ -420,6 +425,31 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
if( mStages[stageNum].getTex( MFT_SpecularMap )->mHasTransparency )
fd.features.addFeature( MFT_GlossMap );
}

if ( mMaterial->mAccuMapFilename[stageNum] != String::EmptyString) {
fd.features.addFeature( MFT_AccuMap );
}

// we need both diffuse and normal maps + sm3 to have an accu map
if( fd.features[ MFT_AccuMap ] &&
( !fd.features[ MFT_DiffuseMap ] ||
!fd.features[ MFT_NormalMap ] ||
GFX->getPixelShaderVersion() < 3.0f ) ) {
AssertWarn(false, "SAHARA: Using an Accu Map requires SM 3.0 and a normal map.");
fd.features.removeFeature( MFT_AccuMap );
}

// if we still have the AccuMap feature, we add all accu constant features
if ( fd.features[ MFT_AccuMap ] ) {
// add the dependencies of the accu map
fd.features.addFeature( MFT_AccuScale );
fd.features.addFeature( MFT_AccuDirection );
fd.features.addFeature( MFT_AccuStrength );
fd.features.addFeature( MFT_AccuCoverage );
fd.features.addFeature( MFT_AccuSpecular );
// now remove some features that are not compatible with this
fd.features.removeFeature( MFT_UseInstancing );
}

// Without a base texture use the diffuse color
// feature to ensure some sort of output.
Expand Down Expand Up @@ -1081,6 +1111,17 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons
0.0f, 0.0f ); // TODO: Wrap mode flags?
shaderConsts->setSafe(handles->mBumpAtlasTileSC, atlasTileParams);
}

if( handles->mAccuScaleSC->isValid() )
shaderConsts->set( handles->mAccuScaleSC, mMaterial->mAccuScale[stageNum] );
if( handles->mAccuDirectionSC->isValid() )
shaderConsts->set( handles->mAccuDirectionSC, mMaterial->mAccuDirection[stageNum] );
if( handles->mAccuStrengthSC->isValid() )
shaderConsts->set( handles->mAccuStrengthSC, mMaterial->mAccuStrength[stageNum] );
if( handles->mAccuCoverageSC->isValid() )
shaderConsts->set( handles->mAccuCoverageSC, mMaterial->mAccuCoverage[stageNum] );
if( handles->mAccuSpecularSC->isValid() )
shaderConsts->set( handles->mAccuSpecularSC, mMaterial->mAccuSpecular[stageNum] );
}

bool ProcessedShaderMaterial::_hasCubemap(U32 pass)
Expand Down
5 changes: 5 additions & 0 deletions Engine/source/materials/processedShaderMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class ShaderConstHandles
GFXShaderConstHandle* mSpecularPowerSC;
GFXShaderConstHandle* mSpecularStrengthSC;
GFXShaderConstHandle* mParallaxInfoSC;
GFXShaderConstHandle* mAccuScaleSC;
GFXShaderConstHandle* mAccuDirectionSC;
GFXShaderConstHandle* mAccuStrengthSC;
GFXShaderConstHandle* mAccuCoverageSC;
GFXShaderConstHandle* mAccuSpecularSC;
GFXShaderConstHandle* mFogDataSC;
GFXShaderConstHandle* mFogColorSC;
GFXShaderConstHandle* mDetailScaleSC;
Expand Down
3 changes: 2 additions & 1 deletion Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "shaderGen/HLSL/paraboloidHLSL.h"
#include "materials/materialFeatureTypes.h"
#include "core/module.h"

#include "shaderGen/accuFeature.h"

static ShaderGen::ShaderGenInitDelegate sInitDelegate;

Expand Down Expand Up @@ -66,6 +66,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatHLSL );
FEATUREMGR->registerFeature( MFT_Fog, new FogFeatHLSL );
FEATUREMGR->registerFeature( MFT_SpecularMap, new SpecularMapHLSL );
FEATUREMGR->registerFeature( MFT_AccuMap, new AccuTexFeatHLSL );
FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureHLSL( "Gloss Map" ) );
FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureHLSL( "Lightbuffer MRT" ) );
FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget1 ) );
Expand Down
Loading