add material tileScale

by request
This commit is contained in:
AzaezelX 2025-12-25 19:52:06 -06:00
parent 0fb68936f9
commit c0ce94f32a
8 changed files with 32 additions and 9 deletions

View file

@ -158,7 +158,7 @@ Material::Material()
mIgnoreLighting[i] = false; mIgnoreLighting[i] = false;
mDetailScale[i].set(2.0f, 2.0f); mDetailScale[i].set(2.0f, 2.0f);
mTileScale[i].set(1.0f, 1.0f);
mDetailNormalMapStrength[i] = 1.0f; mDetailNormalMapStrength[i] = 1.0f;
mMinnaertConstant[i] = -1.0f; mMinnaertConstant[i] = -1.0f;
@ -257,6 +257,8 @@ void Material::initPersistFields()
"is present this is the material color."); "is present this is the material color.");
addField("diffuseMapSRGB", TypeBool, Offset(mDiffuseMapSRGB, Material), MAX_STAGES, addField("diffuseMapSRGB", TypeBool, Offset(mDiffuseMapSRGB, Material), MAX_STAGES,
"Enable sRGB for the diffuse color texture map."); "Enable sRGB for the diffuse color texture map.");
addField("TileScale", TypePoint2F, Offset(mTileScale, Material), MAX_STAGES,
"The scale factor for the detail map.");
INITPERSISTFIELD_IMAGEASSET_ARRAY(NormalMap, MAX_STAGES, Material, "NormalMap"); INITPERSISTFIELD_IMAGEASSET_ARRAY(NormalMap, MAX_STAGES, Material, "NormalMap");
endGroup("Basic Texture Maps"); endGroup("Basic Texture Maps");

View file

@ -270,6 +270,7 @@ public:
/// The repetition scale of the detail texture /// The repetition scale of the detail texture
/// over the base texture. /// over the base texture.
Point2F mDetailScale[MAX_STAGES]; Point2F mDetailScale[MAX_STAGES];
Point2F mTileScale[MAX_STAGES];
U32 mAnimFlags[MAX_STAGES]; U32 mAnimFlags[MAX_STAGES];
Point2F mScrollDir[MAX_STAGES]; Point2F mScrollDir[MAX_STAGES];

View file

@ -56,6 +56,7 @@
void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/) void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/)
{ {
mDiffuseColorSC = shader->getShaderConstHandle("$diffuseMaterialColor"); mDiffuseColorSC = shader->getShaderConstHandle("$diffuseMaterialColor");
mTileScaleSC = shader->getShaderConstHandle(ShaderGenVars::tileScale);
mTexMatSC = shader->getShaderConstHandle(ShaderGenVars::texMat); mTexMatSC = shader->getShaderConstHandle(ShaderGenVars::texMat);
mToneMapTexSC = shader->getShaderConstHandle(ShaderGenVars::toneMap); mToneMapTexSC = shader->getShaderConstHandle(ShaderGenVars::toneMap);
mORMConfigSC = shader->getShaderConstHandle(ShaderGenVars::ormConfig); mORMConfigSC = shader->getShaderConstHandle(ShaderGenVars::ormConfig);
@ -1142,6 +1143,8 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons
shaderConsts->set( handles->mOneOverRTSizeSC, oneOverTargetSize ); shaderConsts->set( handles->mOneOverRTSizeSC, oneOverTargetSize );
} }
shaderConsts->setSafe(handles->mTileScaleSC, mMaterial->mTileScale[stageNum]);
// set detail scale // set detail scale
shaderConsts->setSafe(handles->mDetailScaleSC, mMaterial->mDetailScale[stageNum]); shaderConsts->setSafe(handles->mDetailScaleSC, mMaterial->mDetailScale[stageNum]);
shaderConsts->setSafe(handles->mDetailBumpStrength, mMaterial->mDetailNormalMapStrength[stageNum]); shaderConsts->setSafe(handles->mDetailBumpStrength, mMaterial->mDetailNormalMapStrength[stageNum]);

View file

@ -45,6 +45,7 @@ class ShaderConstHandles
public: public:
GFXShaderConstHandle* mDiffuseColorSC; GFXShaderConstHandle* mDiffuseColorSC;
GFXShaderConstHandle* mToneMapTexSC; GFXShaderConstHandle* mToneMapTexSC;
GFXShaderConstHandle* mTileScaleSC;
GFXShaderConstHandle* mTexMatSC; GFXShaderConstHandle* mTexMatSC;
GFXShaderConstHandle* mORMConfigSC; GFXShaderConstHandle* mORMConfigSC;
GFXShaderConstHandle* mRoughnessSC; GFXShaderConstHandle* mRoughnessSC;

View file

@ -364,6 +364,13 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name,
texCoord->setStructName( "OUT" ); texCoord->setStructName( "OUT" );
texCoord->setType( type ); texCoord->setType( type );
// create detail variable
Var* tileScale = new Var;
tileScale->setType("vec2");
tileScale->setName("tileScale");
tileScale->uniform = true;
tileScale->constSortPos = cspPotentialPrimitive;
if( useTexAnim ) if( useTexAnim )
{ {
inTex->setType( "vec4" ); inTex->setType( "vec4" );
@ -377,15 +384,15 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name,
// Statement allows for casting of different types which // Statement allows for casting of different types which
// eliminates vector truncation problems. // eliminates vector truncation problems.
String statement = String::ToString( " @ = %s(tMul(@, @).xy);\r\n", type ); String statement = String::ToString( " @ = %s(tMul(@, @).xy * @);\r\n", type );
meta->addStatement( new GenOp( statement , texCoord, texMat, inTex ) ); meta->addStatement( new GenOp( statement , texCoord, texMat, inTex, tileScale) );
} }
else else
{ {
// Statement allows for casting of different types which // Statement allows for casting of different types which
// eliminates vector truncation problems. // eliminates vector truncation problems.
String statement = String::ToString( " @ = %s(@);\r\n", type ); String statement = String::ToString( " @ = %s(@ * @);\r\n", type );
meta->addStatement( new GenOp( statement, texCoord, inTex ) ); meta->addStatement( new GenOp( statement, texCoord, inTex, tileScale) );
} }
} }

View file

@ -364,6 +364,13 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name,
texCoord->setStructName( "OUT" ); texCoord->setStructName( "OUT" );
texCoord->setType( type ); texCoord->setType( type );
// create detail variable
Var* tileScale = new Var;
tileScale->setType("float2");
tileScale->setName("tileScale");
tileScale->uniform = true;
tileScale->constSortPos = cspPotentialPrimitive;
if ( useTexAnim ) if ( useTexAnim )
{ {
inTex->setType( "float2" ); inTex->setType( "float2" );
@ -377,15 +384,15 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name,
// Statement allows for casting of different types which // Statement allows for casting of different types which
// eliminates vector truncation problems. // eliminates vector truncation problems.
String statement = String::ToString(" @ = (%s)mul(@, float4(@,1,1));\r\n", type); String statement = String::ToString(" @ = (%s)mul(@, float4(@,1,1))*@;\r\n", type);
meta->addStatement( new GenOp( statement, texCoord, texMat, inTex ) ); meta->addStatement( new GenOp( statement, texCoord, texMat, inTex, tileScale) );
} }
else else
{ {
// Statement allows for casting of different types which // Statement allows for casting of different types which
// eliminates vector truncation problems. // eliminates vector truncation problems.
String statement = String::ToString( " @ = (%s)@;\r\n", type ); String statement = String::ToString( " @ = (%s)(@ * @);\r\n", type );
meta->addStatement( new GenOp( statement, texCoord, inTex ) ); meta->addStatement( new GenOp( statement, texCoord, inTex, tileScale) );
} }
} }

View file

@ -47,6 +47,7 @@ const String ShaderGenVars::fogColor("$fogColor");
const String ShaderGenVars::detailScale("$detailScale"); const String ShaderGenVars::detailScale("$detailScale");
const String ShaderGenVars::visibility("$visibility"); const String ShaderGenVars::visibility("$visibility");
const String ShaderGenVars::colorMultiply("$colorMultiply"); const String ShaderGenVars::colorMultiply("$colorMultiply");
const String ShaderGenVars::tileScale("$tileScale");
const String ShaderGenVars::alphaTestValue("$alphaTestValue"); const String ShaderGenVars::alphaTestValue("$alphaTestValue");
const String ShaderGenVars::texMat("$texMat"); const String ShaderGenVars::texMat("$texMat");
const String ShaderGenVars::accumTime("$accumTime"); const String ShaderGenVars::accumTime("$accumTime");

View file

@ -56,6 +56,7 @@ struct ShaderGenVars
const static String detailScale; const static String detailScale;
const static String visibility; const static String visibility;
const static String colorMultiply; const static String colorMultiply;
const static String tileScale;
const static String alphaTestValue; const static String alphaTestValue;
const static String texMat; const static String texMat;
const static String accumTime; const static String accumTime;