Merge branch 'development' into imageAsset_refactor_rev3

This commit is contained in:
marauder2k7 2025-03-24 20:07:06 +00:00 committed by GitHub
commit 0da0903599
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4189 changed files with 29881 additions and 635347 deletions

View file

@ -82,7 +82,7 @@ CustomMaterial::CustomMaterial()
void CustomMaterial::initPersistFields()
{
docsURL;
addField("version", TypeF32, Offset(mVersion, CustomMaterial),
addFieldV("version", TypeRangedF32, Offset(mVersion, CustomMaterial), &CommonValidators::PositiveFloat,
"@brief Specifies pixel shader version for hardware.\n\n"
"Valid pixel shader versions include 2.0, 3.0, etc. "
"@note All features aren't compatible with all pixel shader versions.");

View file

@ -38,6 +38,7 @@
#include "T3D/accumulationVolume.h"
#include "gui/controls/guiTreeViewCtrl.h"
#include <console/persistenceManager.h>
#include "console/typeValidators.h"
IMPLEMENT_CONOBJECT(Material);
@ -71,21 +72,17 @@ ConsoleDocClass(Material,
ImplementBitfieldType(MaterialAnimType,
"The type of animation effect to apply to this material.\n"
"@ingroup GFX\n\n")
{
Material::Scroll, "Scroll", "Scroll the material along the X/Y axis.\n"
},
{ Material::Rotate, "Rotate" , "Rotate the material around a point.\n" },
{ Material::Wave, "Wave" , "Warps the material with an animation using Sin, Triangle or Square mathematics.\n" },
{ Material::Scale, "Scale", "Scales the material larger and smaller with a pulsing effect.\n" },
{ Material::Sequence, "Sequence", "Enables the material to have multiple frames of animation in its imagemap.\n" }
{ Material::Scroll, "$Scroll", "Scroll the material along the X/Y axis.\n"},
{ Material::Rotate, "$Rotate" , "Rotate the material around a point.\n" },
{ Material::Wave, "$Wave" , "Warps the material with an animation using Sin, Triangle or Square mathematics.\n" },
{ Material::Scale, "$Scale", "Scales the material larger and smaller with a pulsing effect.\n" },
{ Material::Sequence, "$Sequence", "Enables the material to have multiple frames of animation in its imagemap.\n" }
EndImplementBitfieldType;
ImplementEnumType(MaterialBlendOp,
"The type of graphical blending operation to apply to this material\n"
"@ingroup GFX\n\n")
{
Material::None, "None", "Disable blending for this material."
},
{ Material::None, "None", "Disable blending for this material."},
{ Material::Mul, "Mul", "Multiplicative blending." },
{ Material::PreMul, "PreMul", "Premultiplied alpha." },
{ Material::Add, "Add", "Adds the color of the material to the frame buffer with full alpha for each pixel." },
@ -230,6 +227,17 @@ Material::Material()
mReverbSoundOcclusion = 1.0;
}
IRangeValidator bmpChanRange(0, 3);
FRangeValidator glowMulRange(0.0f, 20.0f);
FRangeValidator parallaxScaleRange(0.0f, 4.0f);
FRangeValidator scrollSpeedRange(0.0f, 10.0f);
FRangeValidator waveFreqRange(0.0f, 10.0f);
void Material::onImageAssetChanged()
{
flush();
reload();
}
void Material::initPersistFields()
{
docsURL;
@ -250,32 +258,30 @@ void Material::initPersistFields()
endGroup("Basic Texture Maps");
addGroup("Light Influence Maps");
addField("roughness", TypeF32, Offset(mRoughness, Material), MAX_STAGES,
"The degree of roughness when not using a ORMConfigMap.");
addField("metalness", TypeF32, Offset(mMetalness, Material), MAX_STAGES,
"The degree of Metalness when not using a ORMConfigMap.");
addField("invertRoughness", TypeBool, Offset(mInvertRoughness, Material), MAX_STAGES,
"Treat Roughness as Roughness");
addField("AOChan", TypeF32, Offset(mAOChan, Material), MAX_STAGES,
"The input channel AO maps use.");
addField("roughnessChan", TypeF32, Offset(mRoughnessChan, Material), MAX_STAGES,
"The input channel roughness maps use.");
addField("metalChan", TypeF32, Offset(mMetalChan, Material), MAX_STAGES,
"The input channel metalness maps use.");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(ORMConfigMap, MAX_STAGES, Material, "AO|Roughness|metalness map");
addField("isSRGb", TypeBool, Offset(mIsSRGb, Material), MAX_STAGES,
"Substance Designer Workaround.");
addField("invertRoughness", TypeBool, Offset(mInvertRoughness, Material), MAX_STAGES,
"Treat Roughness as Roughness");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(AOMap, MAX_STAGES, Material, "AOMap");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(RoughMap, MAX_STAGES, Material, "RoughMap (also needs MetalMap)");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(MetalMap, MAX_STAGES, Material, "MetalMap (also needs RoughMap)");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(GlowMap, MAX_STAGES, Material, "GlowMap (needs Albedo)");
addFieldV("AOChan", TypeRangedS32, Offset(mAOChan, Material), &bmpChanRange, MAX_STAGES,
"The input channel AO maps use.");
addFieldV("roughness", TypeRangedF32, Offset(mRoughness, Material), &CommonValidators::F32_8BitPercent,MAX_STAGES,
"The degree of roughness when not using a ORMConfigMap.");
addFieldV("roughnessChan", TypeRangedS32, Offset(mRoughnessChan, Material), &bmpChanRange, MAX_STAGES,
"The input channel roughness maps use.");
addFieldV("metalness", TypeRangedF32, Offset(mMetalness, Material), &CommonValidators::F32_8BitPercent, MAX_STAGES,
"The degree of Metalness when not using a ORMConfigMap.");
addFieldV("metalChan", TypeRangedS32, Offset(mMetalChan, Material), &bmpChanRange, MAX_STAGES,
"The input channel metalness maps use.");
addField("glowMul", TypeF32, Offset(mGlowMul, Material), MAX_STAGES,
addFieldV("glowMul", TypeRangedF32, Offset(mGlowMul, Material),&glowMulRange, MAX_STAGES,
"glow mask multiplier");
endGroup("Light Influence Maps");
@ -285,7 +291,8 @@ void Material::initPersistFields()
"The scale factor for the detail map.");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(DetailNormalMap, MAX_STAGES, Material, "DetailNormalMap");
addField("detailNormalMapStrength", TypeF32, Offset(mDetailNormalMapStrength, Material), MAX_STAGES,
addFieldV("detailNormalMapStrength", TypeRangedF32, Offset(mDetailNormalMapStrength, Material), &CommonValidators::PositiveFloat, MAX_STAGES,
"Used to scale the strength of the detail normal map when blended with the base normal map.");
INITPERSISTFIELD_IMAGEASSET_ARRAY_REFACTOR(OverlayMap, MAX_STAGES, Material, "Overlay");
@ -297,19 +304,19 @@ void Material::initPersistFields()
addProtectedField("accuEnabled", TYPEID< bool >(), Offset(mAccuEnabled, Material),
&_setAccuEnabled, &defaultProtectedGetFn, MAX_STAGES, "Accumulation texture.");
addField("accuScale", TypeF32, Offset(mAccuScale, Material), MAX_STAGES,
addFieldV("accuScale", TypeRangedF32, Offset(mAccuScale, Material), &CommonValidators::PositiveFloat, 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,
addFieldV("accuDirection", TypeRangedF32, Offset(mAccuDirection, Material), &CommonValidators::DirFloat, 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,
addFieldV("accuStrength", TypeRangedF32, Offset(mAccuStrength, Material), &CommonValidators::NormalizedFloat, 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,
addFieldV("accuCoverage", TypeRangedF32, Offset(mAccuCoverage, Material), &CommonValidators::NormalizedFloat, 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,
addFieldV("accuSpecular", TypeRangedF32, Offset(mAccuSpecular, Material), &CommonValidators::NormalizedFloat, MAX_STAGES,
"Changes specularity to this value where the accumulated material is present.");
endGroup("Accumulation Properties");
@ -320,7 +327,7 @@ void Material::initPersistFields()
"Enables emissive lighting for the material.");
addField("glow", TypeBool, Offset(mGlow, Material), MAX_STAGES,
"Enables rendering as glowing.");
addField("parallaxScale", TypeF32, Offset(mParallaxScale, Material), MAX_STAGES,
addFieldV("parallaxScale", TypeRangedF32, Offset(mParallaxScale, Material),&parallaxScaleRange, MAX_STAGES,
"Enables parallax mapping and defines the scale factor for the parallax effect. Typically "
"this value is less than 0.4 else the effect breaks down.");
@ -331,7 +338,7 @@ void Material::initPersistFields()
"If true the vertex color is used for lighting.");
addField("vertColor", TypeBool, Offset(mVertColor, Material), MAX_STAGES,
"If enabled, vertex colors are premultiplied with diffuse colors.");
/* presently unsupported directly. advice would be to use a glowmap+glowmul to fine tune backscatter effects
addField("subSurface", TypeBool, Offset(mSubSurface, Material), MAX_STAGES,
"Enables the subsurface scattering approximation.");
addField("minnaertConstant", TypeF32, Offset(mMinnaertConstant, Material), MAX_STAGES,
@ -340,6 +347,7 @@ void Material::initPersistFields()
"The color used for the subsurface scattering approximation.");
addField("subSurfaceRolloff", TypeF32, Offset(mSubSurfaceRolloff, Material), MAX_STAGES,
"The 0 to 1 rolloff factor used in the subsurface scattering approximation.");
*/
endGroup("Lighting Properties");
addGroup("Animation Properties");
@ -349,10 +357,10 @@ void Material::initPersistFields()
addField("scrollDir", TypePoint2F, Offset(mScrollDir, Material), MAX_STAGES,
"The scroll direction in UV space when scroll animation is enabled.");
addField("scrollSpeed", TypeF32, Offset(mScrollSpeed, Material), MAX_STAGES,
addFieldV("scrollSpeed", TypeRangedF32, Offset(mScrollSpeed, Material), &scrollSpeedRange, MAX_STAGES,
"The speed to scroll the texture in UVs per second when scroll animation is enabled.");
addField("rotSpeed", TypeF32, Offset(mRotSpeed, Material), MAX_STAGES,
addFieldV("rotSpeed", TypeRangedF32, Offset(mRotSpeed, Material), &CommonValidators::DegreeRange, MAX_STAGES,
"The speed to rotate the texture in degrees per second when rotation animation is enabled.");
addField("rotPivotOffset", TypePoint2F, Offset(mRotPivotOffset, Material), MAX_STAGES,
@ -361,10 +369,10 @@ void Material::initPersistFields()
addField("waveType", TYPEID< WaveType >(), Offset(mWaveType, Material), MAX_STAGES,
"The type of wave animation to perform when wave animation is enabled.");
addField("waveFreq", TypeF32, Offset(mWaveFreq, Material), MAX_STAGES,
addFieldV("waveFreq", TypeRangedF32, Offset(mWaveFreq, Material),&waveFreqRange, MAX_STAGES,
"The wave frequency when wave animation is enabled.");
addField("waveAmp", TypeF32, Offset(mWaveAmp, Material), MAX_STAGES,
addFieldV("waveAmp", TypeRangedF32, Offset(mWaveAmp, Material), &CommonValidators::NormalizedFloat, MAX_STAGES,
"The wave amplitude when wave animation is enabled.");
addField("sequenceFramePerSec", TypeF32, Offset(mSeqFramePerSec, Material), MAX_STAGES,
@ -378,7 +386,7 @@ void Material::initPersistFields()
"@internal");
addField("cellLayout", TypePoint2I, Offset(mCellLayout, Material), MAX_STAGES,
"@internal");
addField("cellSize", TypeS32, Offset(mCellSize, Material), MAX_STAGES,
addFieldV("cellSize", TypeRangedS32, Offset(mCellSize, Material), &CommonValidators::PositiveInt, MAX_STAGES,
"@internal");
addField("bumpAtlas", TypeBool, Offset(mNormalMapAtlas, Material), MAX_STAGES,
"@internal");
@ -408,7 +416,7 @@ void Material::initPersistFields()
addField("alphaTest", TypeBool, Offset(mAlphaTest, Material),
"Enables alpha test when rendering the material.\n@see alphaRef\n");
addField("alphaRef", TypeS32, Offset(mAlphaRef, Material),
addFieldV("alphaRef", TypeRangedS32, Offset(mAlphaRef, Material), &CommonValidators::S32_8BitCap,
"The alpha reference value for alpha testing. Must be between 0 to 255.\n@see alphaTest\n");
addField("cubemap", TypeRealString, Offset(mCubemapName, Material),
@ -483,10 +491,22 @@ void Material::initPersistFields()
endGroup("Behavioral (All Layers)");
// For backwards compatibility.
//
// They point at the new 'map' fields, but reads always return
// an empty string and writes only apply if the value is not empty.
//
//
// They point at the new 'map' fields, but reads always return
// an empty string and writes only apply if the value is not empty.
//
addProtectedField("baseTex", TypeImageFilename, Offset(mDiffuseMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see diffuseMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("detailTex", TypeImageFilename, Offset(mDetailMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see detailMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("overlayTex", TypeImageFilename, Offset(mOverlayMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see overlayMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("bumpTex", TypeImageFilename, Offset(mNormalMapName, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see normalMap\n", AbstractClassRep::FIELD_HideInInspectors);
addProtectedField("colorMultiply", TypeColorF, Offset(mDiffuse, Material),
defaultProtectedSetNotEmptyFn, emptyStringProtectedGetFn, MAX_STAGES,
"For backwards compatibility.\n@see diffuseColor\n", AbstractClassRep::FIELD_HideInInspectors);

View file

@ -115,11 +115,11 @@ public:
enum AnimType
{
Scroll = 1,
Rotate = 2,
Wave = 4,
Scale = 8,
Sequence = 16,
Scroll = BIT(0),
Rotate = BIT(1),
Wave = BIT(2),
Scale = BIT(3),
Sequence = BIT(4),
};
enum WaveType

View file

@ -914,98 +914,81 @@ void ProcessedShaderMaterial::_setTextureTransforms(const U32 pass)
PROFILE_SCOPE( ProcessedShaderMaterial_SetTextureTransforms );
ShaderConstHandles* handles = _getShaderConstHandles(pass);
if (handles->mTexMatSC->isValid())
{
MatrixF texMat( true );
if (!handles->mTexMatSC->isValid())
return;
mMaterial->updateTimeBasedParams();
F32 waveOffset = _getWaveOffset( pass ); // offset is between 0.0 and 1.0
MatrixF texMat(true);
mMaterial->updateTimeBasedParams();
F32 waveOffset = _getWaveOffset(pass); // offset is between 0.0 and 1.0
// handle scroll anim type
if( mMaterial->mAnimFlags[pass] & Material::Scroll )
{
if( mMaterial->mAnimFlags[pass] & Material::Wave )
{
Point3F scrollOffset;
scrollOffset.x = mMaterial->mScrollDir[pass].x * waveOffset;
scrollOffset.y = mMaterial->mScrollDir[pass].y * waveOffset;
scrollOffset.z = 1.0;
// --- Scroll Animation ---
if (mMaterial->mAnimFlags[pass] & Material::Scroll)
{
Point3F offset = (mMaterial->mAnimFlags[pass] & Material::Wave)
? Point3F(mMaterial->mScrollDir[pass].x * waveOffset,
mMaterial->mScrollDir[pass].y * waveOffset, 0.0f)
: Point3F(mMaterial->mScrollOffset[pass].x,
mMaterial->mScrollOffset[pass].y, 0.0f);
texMat.setColumn( 3, scrollOffset );
}
else
{
Point3F offset( mMaterial->mScrollOffset[pass].x,
mMaterial->mScrollOffset[pass].y,
1.0 );
texMat.setColumn( 3, offset );
}
}
// handle rotation
if( mMaterial->mAnimFlags[pass] & Material::Rotate )
{
if( mMaterial->mAnimFlags[pass] & Material::Wave )
{
F32 rotPos = waveOffset * M_2PI;
texMat.set( EulerF( 0.0, 0.0, rotPos ) );
texMat.setColumn( 3, Point3F( 0.5, 0.5, 0.0 ) );
MatrixF test( true );
test.setColumn( 3, Point3F( mMaterial->mRotPivotOffset[pass].x,
mMaterial->mRotPivotOffset[pass].y,
0.0 ) );
texMat.mul( test );
}
else
{
texMat.set( EulerF( 0.0, 0.0, mMaterial->mRotPos[pass] ) );
texMat.setColumn( 3, Point3F( 0.5, 0.5, 0.0 ) );
MatrixF test( true );
test.setColumn( 3, Point3F( mMaterial->mRotPivotOffset[pass].x,
mMaterial->mRotPivotOffset[pass].y,
0.0 ) );
texMat.mul( test );
}
}
// Handle scale + wave offset
if( mMaterial->mAnimFlags[pass] & Material::Scale &&
mMaterial->mAnimFlags[pass] & Material::Wave )
{
F32 wOffset = fabs( waveOffset );
texMat.setColumn( 3, Point3F( 0.5, 0.5, 0.0 ) );
MatrixF temp( true );
temp.setRow( 0, Point3F( wOffset, 0.0, 0.0 ) );
temp.setRow( 1, Point3F( 0.0, wOffset, 0.0 ) );
temp.setRow( 2, Point3F( 0.0, 0.0, wOffset ) );
temp.setColumn( 3, Point3F( -wOffset * 0.5, -wOffset * 0.5, 0.0 ) );
texMat.mul( temp );
}
// handle sequence
if( mMaterial->mAnimFlags[pass] & Material::Sequence )
{
U32 frameNum = (U32)(MATMGR->getTotalTime() * mMaterial->mSeqFramePerSec[pass]);
F32 offset = frameNum * mMaterial->mSeqSegSize[pass];
if ( mMaterial->mAnimFlags[pass] & Material::Scale )
texMat.scale( Point3F( mMaterial->mSeqSegSize[pass], 1.0f, 1.0f ) );
Point3F texOffset = texMat.getPosition();
texOffset.x += offset;
texMat.setPosition( texOffset );
}
GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
shaderConsts->setSafe(handles->mTexMatSC, texMat);
MatrixF scrollMat(true);
scrollMat.setColumn(3, offset);
texMat.mul(scrollMat);
}
// --- Rotation Animation ---
if (mMaterial->mAnimFlags[pass] & Material::Rotate)
{
F32 rotationAngle = (mMaterial->mAnimFlags[pass] & Material::Wave)
? waveOffset * M_2PI
: mMaterial->mRotPos[pass];
MatrixF rotationMat(EulerF(0.0f, 0.0f, rotationAngle));
Point3F pivotPoint(
mMaterial->mRotPivotOffset[pass].x,
mMaterial->mRotPivotOffset[pass].y,
0.0f);
MatrixF finalRotationMat(true);
finalRotationMat.setColumn(3, pivotPoint);
finalRotationMat.mul(rotationMat);
finalRotationMat.setColumn(3, -pivotPoint);
// Apply final rotation matrix
texMat.mul(finalRotationMat);
}
// --- Scale Animation ---
if ((mMaterial->mAnimFlags[pass] & Material::Scale) && (mMaterial->mAnimFlags[pass] & Material::Wave))
{
F32 scaleFactor = mFabs(waveOffset);
MatrixF scaleMat(true);
scaleMat.setRow(0, Point3F(scaleFactor, 0.0f, 0.0f));
scaleMat.setRow(1, Point3F(0.0f, scaleFactor, 0.0f));
scaleMat.setRow(2, Point3F(0.0f, 0.0f, scaleFactor));
// Apply final scale matrix
texMat.mul(scaleMat);
}
// --- Sequence Animation ---
if (mMaterial->mAnimFlags[pass] & Material::Sequence)
{
U32 frameNum = static_cast<U32>(MATMGR->getTotalTime() * mMaterial->mSeqFramePerSec[pass]);
F32 offset = frameNum * mMaterial->mSeqSegSize[pass];
MatrixF sequenceMat(true);
sequenceMat.setColumn(3, Point3F(offset, 0.0f, 0.0f));
if (mMaterial->mAnimFlags[pass] & Material::Scale)
sequenceMat.scale(Point3F(mMaterial->mSeqSegSize[pass], 1.0f, 1.0f));
texMat.mul(sequenceMat);
}
GFXShaderConstBuffer* shaderConsts = _getShaderConstBuffer(pass);
shaderConsts->setSafe(handles->mTexMatSC, texMat);
}
//--------------------------------------------------------------------------

View file

@ -28,6 +28,7 @@
#include "core/strings/stringUnit.h"
#include "lighting/lightManager.h"
#include "console/engineAPI.h"
#include "console/typeValidators.h"
using namespace Torque;
@ -115,7 +116,7 @@ void ShaderData::initPersistFields()
"@brief If true, the maximum pixel shader version offered by the graphics card will be used.\n\n"
"Otherwise, the script-defined pixel shader version will be used.\n\n");
addField("pixVersion", TypeF32, Offset(mPixVersion, ShaderData),
addFieldV("pixVersion", TypeRangedF32, Offset(mPixVersion, ShaderData), &CommonValidators::PositiveFloat,
"@brief Indicates target level the shader should be compiled.\n\n"
"Valid numbers at the time of this writing are 1.1, 1.4, 2.0, and 3.0. "
"The shader will not run properly if the hardware does not support the "