Add **Sample Global SDF** node to particles
This commit is contained in:
@@ -363,7 +363,7 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
TypeID = 14,
|
||||
Title = "Sample Global SDF",
|
||||
Description = "Samples the Global SDF to get the distance to the closest surface (in world-space). Requires models SDF to be generated and checking `Enable Global SDF` in Graphics Settings.",
|
||||
Flags = NodeFlags.MaterialGraph,
|
||||
Flags = NodeFlags.MaterialGraph | NodeFlags.ParticleEmitterGraph,
|
||||
Size = new Vector2(200, 20),
|
||||
Elements = new[]
|
||||
{
|
||||
|
||||
@@ -124,6 +124,13 @@ void ParticleEmitterGraphCPUExecutor::ProcessGroupTextures(Box* box, Node* node,
|
||||
value = Value::Zero;
|
||||
break;
|
||||
}
|
||||
// Sample Global SDF
|
||||
case 14:
|
||||
{
|
||||
// Not supported
|
||||
value = Value::Zero;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -303,6 +303,15 @@ void ParticleEmitterGPUGenerator::ProcessGroupTextures(Box* box, Node* node, Val
|
||||
loadTexture(node, box, copy, value);
|
||||
break;
|
||||
}
|
||||
// Sample Global SDF
|
||||
case 14:
|
||||
{
|
||||
auto param = findOrAddGlobalSDF();
|
||||
Value worldPosition = tryGetValue(node->GetBox(1), Value(VariantType::Vector3, TEXT("input.WorldPosition.xyz"))).Cast(VariantType::Vector3);
|
||||
value = writeLocal(VariantType::Float, String::Format(TEXT("SampleGlobalSDF({0}, {0}_Tex, {1})"), param.ShaderName, worldPosition.Value), node);
|
||||
_includes.Add(TEXT("./Flax/GlobalSignDistanceField.hlsl"));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ void GlobalSignDistanceFieldPass::Dispose()
|
||||
bool GlobalSignDistanceFieldPass::Get(const RenderBuffers* buffers, BindingData& result)
|
||||
{
|
||||
auto* sdfData = buffers ? buffers->FindCustomBuffer<GlobalSignDistanceFieldCustomBuffer>(TEXT("GlobalSignDistanceField")) : nullptr;
|
||||
if (sdfData && sdfData->LastFrameUsed == Engine::FrameCount)
|
||||
if (sdfData && sdfData->LastFrameUsed + 1 >= Engine::FrameCount) // Allow to use SDF from the previous frame (eg. particles in Editor using the Editor viewport in Game viewport - Game render task runs first)
|
||||
{
|
||||
result = sdfData->Result;
|
||||
return false;
|
||||
|
||||
@@ -427,7 +427,6 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
|
||||
Value worldPosition = tryGetValue(node->GetBox(1), Value(VariantType::Vector3, TEXT("input.WorldPosition.xyz"))).Cast(VariantType::Vector3);
|
||||
value = writeLocal(VariantType::Float, String::Format(TEXT("SampleGlobalSDF({0}, {0}_Tex, {1})"), param.ShaderName, worldPosition.Value), node);
|
||||
_includes.Add(TEXT("./Flax/GlobalSignDistanceField.hlsl"));
|
||||
//float SampleGlobalSDF(const GlobalSDFData data, Texture3D<float> tex[4], float3 worldPosition, uint minCascade = 0)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user