diff --git a/Source/Editor/Surface/Archetypes/Textures.cs b/Source/Editor/Surface/Archetypes/Textures.cs index 53b2ccf04..967ea1682 100644 --- a/Source/Editor/Surface/Archetypes/Textures.cs +++ b/Source/Editor/Surface/Archetypes/Textures.cs @@ -404,9 +404,9 @@ namespace FlaxEditor.Surface.Archetypes Elements = new[] { NodeElementArchetype.Factory.Input(0, "Texture", true, typeof(FlaxEngine.Object), 0), - NodeElementArchetype.Factory.Input(1, "Scale", true, typeof(Float3), 1, 0), + NodeElementArchetype.Factory.Input(1, "Scale", true, typeof(Float4), 1, 0), NodeElementArchetype.Factory.Input(2, "Blend", true, typeof(float), 2, 1), - NodeElementArchetype.Factory.Output(0, "Color", typeof(Float3), 3) + NodeElementArchetype.Factory.Output(0, "Color", typeof(Float4), 3) } }, new NodeArchetype diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp index 8083718dd..1ed776646 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp @@ -687,51 +687,41 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) // World Triplanar Texture case 16: { - // Get input boxes auto textureBox = node->GetBox(0); auto scaleBox = node->GetBox(1); auto blendBox = node->GetBox(2); - if (!textureBox->HasConnection()) { // No texture to sample value = Value::Zero; break; } - - if (!CanUseSample(_treeType)) - { - // Must sample texture in pixel shader - value = Value::Zero; - break; - } - + const bool canUseSample = CanUseSample(_treeType); const auto texture = eatBox(textureBox->GetParent(), textureBox->FirstConnection()); - const auto scale = tryGetValue(scaleBox, node->Values[0]).AsFloat3(); + const auto scale = tryGetValue(scaleBox, node->Values[0]).AsFloat4(); const auto blend = tryGetValue(blendBox, node->Values[1]).AsFloat(); - auto result = writeLocal(Value::InitForZero(ValueType::Float4), node); - const String triplanarTexture = String::Format(TEXT( " {{\n" " float3 worldPos = input.WorldPosition.xyz * ({1} * 0.001f);\n" " float3 normal = abs(input.TBN[2]);\n" " normal = pow(normal, {2});\n" " normal = normal / (normal.x + normal.y + normal.z);\n" - - " {3} += {0}.Sample(SamplerLinearWrap, worldPos.yz) * normal.x;\n" - " {3} += {0}.Sample(SamplerLinearWrap, worldPos.xz) * normal.y;\n" - " {3} += {0}.Sample(SamplerLinearWrap, worldPos.xy) * normal.z;\n" + " {3} += {0}.{4}(SamplerLinearWrap, worldPos.yz{5}) * normal.x;\n" + " {3} += {0}.{4}(SamplerLinearWrap, worldPos.xz{5}) * normal.y;\n" + " {3} += {0}.{4}(SamplerLinearWrap, worldPos.xy{5}) * normal.z;\n" " }}\n" ), texture.Value, // {0} scale.Value, // {1} blend.Value, // {2} - result.Value // {3} + result.Value, // {3} + canUseSample ? TEXT("Sample") : TEXT("SampleLevel"), // {4} + canUseSample ? TEXT("") : TEXT(", 0") // {5} ); - _writer.Write(*triplanarTexture); value = result; + break; } // Get Lightmap UV case 18: @@ -746,9 +736,7 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) "#endif\n" "}}\n" ), output.Value); - _writer.Write(*lightmapUV); - value = output; break; }