Add Position (Global SDF) particle module

This commit is contained in:
Wojciech Figat
2022-03-28 10:27:33 +02:00
parent f608d2537f
commit bcc4a2c0a4
4 changed files with 43 additions and 2 deletions

View File

@@ -610,6 +610,27 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
), positionAttr.Value, velocityAttr.Value, center.Value, rotationSpeed.Value, velocityScale.Value, customDataOffset);
break;
}
// Position (Global SDF)
case 215:
{
auto position = AccessParticleAttribute(node, nodeGpu->Attributes[0], AccessMode::ReadWrite);
auto param = findOrAddGlobalSDF();
String wsPos = position.Value;
if (((ParticleEmitterGraphGPU*)_graphStack.Peek())->SimulationSpace == ParticlesSimulationSpace::Local)
wsPos = String::Format(TEXT("mul(float4({0}, 1), WorldMatrix).xyz"), wsPos);
_includes.Add(TEXT("./Flax/GlobalSignDistanceField.hlsl"));
_writer.Write(
TEXT(
" {{\n"
" // Position (Global SDF)\n"
" float3 wsPos = {2};\n"
" float dist;\n"
" float3 dir = -normalize(SampleGlobalSDFGradient({1}, {1}_Tex, wsPos, dist));\n"
" {0} += dir * dist;\n"
" }}\n"
), position.Value, param.ShaderName, wsPos);
break;
}
// Helper macros for collision modules to share the code
#define COLLISION_BEGIN() \