From c0ce94f32a6c993110440208c7553495a94e8b2d Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 25 Dec 2025 19:52:06 -0600 Subject: [PATCH] add material tileScale by request --- Engine/source/materials/materialDefinition.cpp | 4 +++- Engine/source/materials/materialDefinition.h | 1 + .../source/materials/processedShaderMaterial.cpp | 3 +++ Engine/source/materials/processedShaderMaterial.h | 1 + .../source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 15 +++++++++++---- .../source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 15 +++++++++++---- Engine/source/shaderGen/shaderGenVars.cpp | 1 + Engine/source/shaderGen/shaderGenVars.h | 1 + 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 4c0e3a61f..5642d2fb3 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -158,7 +158,7 @@ Material::Material() mIgnoreLighting[i] = false; mDetailScale[i].set(2.0f, 2.0f); - + mTileScale[i].set(1.0f, 1.0f); mDetailNormalMapStrength[i] = 1.0f; mMinnaertConstant[i] = -1.0f; @@ -257,6 +257,8 @@ void Material::initPersistFields() "is present this is the material color."); addField("diffuseMapSRGB", TypeBool, Offset(mDiffuseMapSRGB, Material), MAX_STAGES, "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"); endGroup("Basic Texture Maps"); diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 832898949..abaec1583 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -270,6 +270,7 @@ public: /// The repetition scale of the detail texture /// over the base texture. Point2F mDetailScale[MAX_STAGES]; + Point2F mTileScale[MAX_STAGES]; U32 mAnimFlags[MAX_STAGES]; Point2F mScrollDir[MAX_STAGES]; diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index 2494fc759..b66fa0d5c 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -56,6 +56,7 @@ void ShaderConstHandles::init( GFXShader *shader, CustomMaterial* mat /*=NULL*/) { mDiffuseColorSC = shader->getShaderConstHandle("$diffuseMaterialColor"); + mTileScaleSC = shader->getShaderConstHandle(ShaderGenVars::tileScale); mTexMatSC = shader->getShaderConstHandle(ShaderGenVars::texMat); mToneMapTexSC = shader->getShaderConstHandle(ShaderGenVars::toneMap); mORMConfigSC = shader->getShaderConstHandle(ShaderGenVars::ormConfig); @@ -1142,6 +1143,8 @@ void ProcessedShaderMaterial::_setShaderConstants(SceneRenderState * state, cons shaderConsts->set( handles->mOneOverRTSizeSC, oneOverTargetSize ); } + shaderConsts->setSafe(handles->mTileScaleSC, mMaterial->mTileScale[stageNum]); + // set detail scale shaderConsts->setSafe(handles->mDetailScaleSC, mMaterial->mDetailScale[stageNum]); shaderConsts->setSafe(handles->mDetailBumpStrength, mMaterial->mDetailNormalMapStrength[stageNum]); diff --git a/Engine/source/materials/processedShaderMaterial.h b/Engine/source/materials/processedShaderMaterial.h index e922b61a8..438c879e5 100644 --- a/Engine/source/materials/processedShaderMaterial.h +++ b/Engine/source/materials/processedShaderMaterial.h @@ -45,6 +45,7 @@ class ShaderConstHandles public: GFXShaderConstHandle* mDiffuseColorSC; GFXShaderConstHandle* mToneMapTexSC; + GFXShaderConstHandle* mTileScaleSC; GFXShaderConstHandle* mTexMatSC; GFXShaderConstHandle* mORMConfigSC; GFXShaderConstHandle* mRoughnessSC; diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 6c545b40f..1e13d7805 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -364,6 +364,13 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name, texCoord->setStructName( "OUT" ); texCoord->setType( type ); + // create detail variable + Var* tileScale = new Var; + tileScale->setType("vec2"); + tileScale->setName("tileScale"); + tileScale->uniform = true; + tileScale->constSortPos = cspPotentialPrimitive; + if( useTexAnim ) { inTex->setType( "vec4" ); @@ -377,15 +384,15 @@ Var* ShaderFeatureGLSL::getOutTexCoord( const char *name, // Statement allows for casting of different types which // eliminates vector truncation problems. - String statement = String::ToString( " @ = %s(tMul(@, @).xy);\r\n", type ); - meta->addStatement( new GenOp( statement , texCoord, texMat, inTex ) ); + String statement = String::ToString( " @ = %s(tMul(@, @).xy * @);\r\n", type ); + meta->addStatement( new GenOp( statement , texCoord, texMat, inTex, tileScale) ); } else { // Statement allows for casting of different types which // eliminates vector truncation problems. - String statement = String::ToString( " @ = %s(@);\r\n", type ); - meta->addStatement( new GenOp( statement, texCoord, inTex ) ); + String statement = String::ToString( " @ = %s(@ * @);\r\n", type ); + meta->addStatement( new GenOp( statement, texCoord, inTex, tileScale) ); } } diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 9d6ea1923..0594730e1 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -364,6 +364,13 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name, texCoord->setStructName( "OUT" ); texCoord->setType( type ); + // create detail variable + Var* tileScale = new Var; + tileScale->setType("float2"); + tileScale->setName("tileScale"); + tileScale->uniform = true; + tileScale->constSortPos = cspPotentialPrimitive; + if ( useTexAnim ) { inTex->setType( "float2" ); @@ -377,15 +384,15 @@ Var* ShaderFeatureHLSL::getOutTexCoord( const char *name, // Statement allows for casting of different types which // eliminates vector truncation problems. - String statement = String::ToString(" @ = (%s)mul(@, float4(@,1,1));\r\n", type); - meta->addStatement( new GenOp( statement, texCoord, texMat, inTex ) ); + String statement = String::ToString(" @ = (%s)mul(@, float4(@,1,1))*@;\r\n", type); + meta->addStatement( new GenOp( statement, texCoord, texMat, inTex, tileScale) ); } else { // Statement allows for casting of different types which // eliminates vector truncation problems. - String statement = String::ToString( " @ = (%s)@;\r\n", type ); - meta->addStatement( new GenOp( statement, texCoord, inTex ) ); + String statement = String::ToString( " @ = (%s)(@ * @);\r\n", type ); + meta->addStatement( new GenOp( statement, texCoord, inTex, tileScale) ); } } diff --git a/Engine/source/shaderGen/shaderGenVars.cpp b/Engine/source/shaderGen/shaderGenVars.cpp index e6a334893..4c6787f0a 100644 --- a/Engine/source/shaderGen/shaderGenVars.cpp +++ b/Engine/source/shaderGen/shaderGenVars.cpp @@ -47,6 +47,7 @@ const String ShaderGenVars::fogColor("$fogColor"); const String ShaderGenVars::detailScale("$detailScale"); const String ShaderGenVars::visibility("$visibility"); const String ShaderGenVars::colorMultiply("$colorMultiply"); +const String ShaderGenVars::tileScale("$tileScale"); const String ShaderGenVars::alphaTestValue("$alphaTestValue"); const String ShaderGenVars::texMat("$texMat"); const String ShaderGenVars::accumTime("$accumTime"); diff --git a/Engine/source/shaderGen/shaderGenVars.h b/Engine/source/shaderGen/shaderGenVars.h index 4acc97fa8..0a1fb5310 100644 --- a/Engine/source/shaderGen/shaderGenVars.h +++ b/Engine/source/shaderGen/shaderGenVars.h @@ -56,6 +56,7 @@ struct ShaderGenVars const static String detailScale; const static String visibility; const static String colorMultiply; + const static String tileScale; const static String alphaTestValue; const static String texMat; const static String accumTime;