From 54f73fe35a2a4ed8edb05ea9d547669fd7b7630f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 28 Mar 2025 11:15:14 +0100 Subject: [PATCH] Fix regression in new triplanar to still support scale as `Float3` for per-axis scaling --- Source/Editor/Surface/Archetypes/Textures.cs | 8 ++++---- .../MaterialGenerator/MaterialGenerator.Textures.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Textures.cs b/Source/Editor/Surface/Archetypes/Textures.cs index ff041f5b6..b34c9e821 100644 --- a/Source/Editor/Surface/Archetypes/Textures.cs +++ b/Source/Editor/Surface/Archetypes/Textures.cs @@ -408,7 +408,7 @@ namespace FlaxEditor.Surface.Archetypes Size = new Float2(280, 100), DefaultValues = new object[] { - 1.0f, // Scale + Float3.One, // Scale 1.0f, // Blend Float2.Zero, // Offset 2, // Sampler @@ -417,7 +417,7 @@ namespace FlaxEditor.Surface.Archetypes Elements = new[] { NodeElementArchetype.Factory.Input(0, "Texture", true, typeof(FlaxEngine.Object), 0), - NodeElementArchetype.Factory.Input(1, "Scale", true, typeof(float), 1, 0), + NodeElementArchetype.Factory.Input(1, "Scale", true, typeof(Float3), 1, 0), NodeElementArchetype.Factory.Input(2, "Blend", true, typeof(float), 2, 1), NodeElementArchetype.Factory.Input(3, "Offset", true, typeof(Float2), 6, 2), NodeElementArchetype.Factory.Output(0, "Color", typeof(Float4), 3), @@ -474,7 +474,7 @@ namespace FlaxEditor.Surface.Archetypes Size = new Float2(280, 100), DefaultValues = new object[] { - 1.0f, // Scale + Float3.One, // Scale 1.0f, // Blend Float2.Zero, // Offset 2, // Sampler @@ -483,7 +483,7 @@ namespace FlaxEditor.Surface.Archetypes Elements = new[] { NodeElementArchetype.Factory.Input(0, "Texture", true, typeof(FlaxEngine.Object), 0), - NodeElementArchetype.Factory.Input(1, "Scale", true, typeof(float), 1, 0), + NodeElementArchetype.Factory.Input(1, "Scale", true, typeof(Float3), 1, 0), NodeElementArchetype.Factory.Input(2, "Blend", true, typeof(float), 2, 1), NodeElementArchetype.Factory.Input(3, "Offset", true, typeof(Float2), 6, 2), NodeElementArchetype.Factory.Output(0, "Vector", typeof(Float3), 3), diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp index 1805445c4..fe6f04b7b 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp @@ -704,7 +704,7 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) } const bool canUseSample = CanUseSample(_treeType); const auto texture = eatBox(textureBox->GetParent(), textureBox->FirstConnection()); - const auto scale = tryGetValue(node->GetBox(1), node->Values[0]).AsFloat(); + const auto scale = tryGetValue(node->GetBox(1), node->Values[0]).AsFloat3(); const auto blend = tryGetValue(node->GetBox(2), node->Values[1]).AsFloat(); const auto offset = tryGetValue(node->TryGetBox(6), node->Values.Count() >= 3 ? node->Values[2] : Float2::Zero).AsFloat2(); const bool local = node->Values.Count() >= 5 ? node->Values[4].AsBool : false; @@ -732,8 +732,8 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) .Code(TEXT(R"( { // Get world position and normal - float tiling = %SCALE% * 0.001f; - float3 position = ((%POSITION%) + GetLargeWorldsTileOffset(1.0f / tiling)) * tiling; + float3 tiling = %SCALE% * 0.001f; + float3 position = ((%POSITION%) + GetLargeWorldsTileOffset(1.0f / length(tiling))) * tiling; float3 normal = normalize(%NORMAL%); // Compute triplanar blend weights using power distribution @@ -793,7 +793,7 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) } const bool canUseSample = CanUseSample(_treeType); const auto texture = eatBox(textureBox->GetParent(), textureBox->FirstConnection()); - const auto scale = tryGetValue(node->GetBox(1), node->Values[0]).AsFloat(); + const auto scale = tryGetValue(node->GetBox(1), node->Values[0]).AsFloat3(); const auto blend = tryGetValue(node->GetBox(2), node->Values[1]).AsFloat(); const auto offset = tryGetValue(node->GetBox(6), node->Values[2]).AsFloat2(); const bool local = node->Values.Count() >= 5 ? node->Values[4].AsBool : false; @@ -822,8 +822,8 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) .Code(TEXT(R"( { // Get world position and normal - float tiling = %SCALE% * 0.001f; - float3 position = ((%POSITION%) + GetLargeWorldsTileOffset(1.0f / tiling)) * tiling; + float3 tiling = %SCALE% * 0.001f; + float3 position = ((%POSITION%) + GetLargeWorldsTileOffset(1.0f / length(tiling))) * tiling; float3 normal = normalize(%NORMAL%); // Compute triplanar blend weights using power distribution