cleaned up variant of https://github.com/GarageGames/Torque3D/pull/768 alterations: opengl support, in-shader bug-reporting, direction vector fit to material slider-bar.

This commit is contained in:
Azaezel 2014-12-21 14:07:42 -06:00
parent 949251b988
commit c6cdfafe4e
42 changed files with 2680 additions and 8 deletions

View file

@ -185,6 +185,7 @@ public:
// BTRTODO: This stuff below should probably not be in BaseMatInstance
virtual bool hasGlow() = 0;
virtual bool hasAccumulation() = 0;
virtual U32 getCurPass() = 0;

View file

@ -497,6 +497,14 @@ bool MatInstance::hasGlow()
return false;
}
bool MatInstance::hasAccumulation()
{
if( mProcessedMaterial )
return mProcessedMaterial->hasAccumulation();
else
return false;
}
const FeatureSet& MatInstance::getFeatures() const
{
return mProcessedMaterial->getFeatures();

View file

@ -75,6 +75,7 @@ public:
virtual SimObject* getUserObject() const { return mUserObject; }
virtual Material *getMaterial() { return mMaterial; }
virtual bool hasGlow();
virtual bool hasAccumulation();
virtual U32 getCurPass() { return getMax( mCurPass, 0 ); }
virtual U32 getCurStageNum();
virtual RenderPassData *getPass(U32 pass);

View file

@ -34,6 +34,7 @@
#include "sfx/sfxTrack.h"
#include "sfx/sfxTypes.h"
#include "core/util/safeDelete.h"
#include "T3D/accumulationVolume.h"
IMPLEMENT_CONOBJECT( Material );
@ -119,6 +120,13 @@ Material::Material()
mSpecularStrength[i] = 1.0f;
mPixelSpecular[i] = false;
mAccuEnabled[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;
@ -250,6 +258,24 @@ void Material::initPersistFields()
"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." );
addProtectedField( "accuEnabled", TYPEID< bool >(), Offset( mAccuEnabled, Material ),
&_setAccuEnabled, &defaultProtectedGetFn, MAX_STAGES, "Accumulation texture." );
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. "
"If this texture contains alpha information, the alpha channel of the texture will be used as the gloss map. "
@ -669,4 +695,18 @@ ConsoleMethod( Material, setAutoGenerated, void, 3, 3,
"setAutoGenerated(bool isAutoGenerated): Set whether or not the Material is autogenerated." )
{
object->setAutoGenerated(dAtob(argv[2]));
}
// Accumulation
bool Material::_setAccuEnabled( void *object, const char *index, const char *data )
{
Material* mat = reinterpret_cast< Material* >( object );
if ( index )
{
U32 i = dAtoui(index);
mat->mAccuEnabled[i] = dAtob(data);
AccumulationVolume::refreshVolumes();
}
return true;
}

View file

@ -88,6 +88,7 @@ public:
DynamicLightMask,
NormalizeCube,
TexTarget,
AccuMap,
};
enum BlendOp
@ -198,6 +199,12 @@ public:
// Data
//-----------------------------------------------------------------------
FileName mDiffuseMapFilename[MAX_STAGES];
bool mAccuEnabled[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];
@ -371,6 +378,9 @@ public:
//
static void initPersistFields();
// Accumulation
static bool _setAccuEnabled( void *object, const char *index, const char *data );
DECLARE_CONOBJECT(Material);
protected:

View file

@ -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 );
@ -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 );

View file

@ -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 );

View file

@ -49,6 +49,7 @@ ProcessedCustomMaterial::ProcessedCustomMaterial(Material &mat)
mCustomMaterial = static_cast<CustomMaterial*>(mMaterial);
mHasSetStageData = false;
mHasGlow = false;
mHasAccumulation = false;
mMaxStages = 0;
mMaxTex = 0;
}

View file

@ -67,6 +67,7 @@ void ProcessedFFMaterial::_construct()
{
mHasSetStageData = false;
mHasGlow = false;
mHasAccumulation = false;
mIsLightingMaterial = false;
mDefaultHandle = new FFMaterialParameterHandle();
mDefaultParameters = new MaterialParameters();

View file

@ -93,6 +93,7 @@ ProcessedMaterial::ProcessedMaterial()
mCurrentParams( NULL ),
mHasSetStageData( false ),
mHasGlow( false ),
mHasAccumulation( false ),
mMaxStages( 0 ),
mVertexFormat( NULL ),
mUserObject( NULL )

View file

@ -197,6 +197,9 @@ public:
/// Returns true if any pass glows
bool hasGlow() const { return mHasGlow; }
/// Returns true if any pass accumulates
bool hasAccumulation() const { return mHasAccumulation; }
/// Gets the stage number for a pass
U32 getStageFromPass(U32 pass) const
{
@ -244,6 +247,9 @@ protected:
/// If we glow
bool mHasGlow;
/// If we have accumulation.
bool mHasAccumulation;
/// Number of stages (not to be confused with number of passes)
U32 mMaxStages;

View file

@ -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);
@ -423,6 +428,34 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
fd.features.addFeature( MFT_GlossMap );
}
if ( mMaterial->mAccuEnabled[stageNum] )
{
fd.features.addFeature( MFT_AccuMap );
mHasAccumulation = true;
}
// 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 );
mHasAccumulation = false;
}
// 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.
if (!fd.features[MFT_DiffuseMap])
@ -809,6 +842,13 @@ void ProcessedShaderMaterial::setTextureStages( SceneRenderState *state, const S
case Material::BackBuff:
GFX->setTexture( i, sgData.backBuffTex );
break;
case Material::AccuMap:
if ( sgData.accuTex )
GFX->setTexture( i, sgData.accuTex );
else
GFX->setTexture( i, GFXTexHandle::ZERO );
break;
case Material::TexTarget:
{
@ -1137,6 +1177,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)

View file

@ -48,6 +48,11 @@ public:
GFXShaderConstHandle* mSpecularPowerSC;
GFXShaderConstHandle* mSpecularStrengthSC;
GFXShaderConstHandle* mParallaxInfoSC;
GFXShaderConstHandle* mAccuScaleSC;
GFXShaderConstHandle* mAccuDirectionSC;
GFXShaderConstHandle* mAccuStrengthSC;
GFXShaderConstHandle* mAccuCoverageSC;
GFXShaderConstHandle* mAccuSpecularSC;
GFXShaderConstHandle* mFogDataSC;
GFXShaderConstHandle* mFogColorSC;
GFXShaderConstHandle* mDetailScaleSC;

View file

@ -64,6 +64,7 @@ struct SceneData
GFXTextureObject *backBuffTex;
GFXTextureObject *reflectTex;
GFXTextureObject *miscTex;
GFXTextureObject *accuTex;
/// The current lights to use in rendering
/// in order of the light importance.