Fix World Triplanar Texture node to support displacement and float4 value
This commit is contained in:
@@ -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<Node>(), 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user