Add safety checks for particles data to prevent division by 0
This commit is contained in:
@@ -177,7 +177,7 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
|
||||
" {{\n"
|
||||
" // Linear Drag\n"
|
||||
" float drag = {2} * {3}.x * {3}.y;\n"
|
||||
" {0} *= max(0.0f, 1.0f - (drag * DeltaTime) / {1});\n"
|
||||
" {0} *= max(0.0f, 1.0f - (drag * DeltaTime) / max({1}, PARTICLE_THRESHOLD));\n"
|
||||
" }}\n"
|
||||
), velocity.Value, mass.Value, drag.Value, spriteSize.Value);
|
||||
}
|
||||
@@ -188,7 +188,7 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
|
||||
" {{\n"
|
||||
" // Linear Drag\n"
|
||||
" float drag = {2};\n"
|
||||
" {0} *= max(0.0f, 1.0f - (drag * DeltaTime) / {1});\n"
|
||||
" {0} *= max(0.0f, 1.0f - (drag * DeltaTime) / max({1}, PARTICLE_THRESHOLD));\n"
|
||||
" }}\n"
|
||||
), velocity.Value, mass.Value, drag.Value);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
|
||||
" float3 vectorFieldUVW = mul(invFieldTransformMatrix, float4({0}, 1.0f)).xyz;\n"
|
||||
" float3 force = Noise3D(vectorFieldUVW + 0.5f, {8}, {6});\n"
|
||||
" force = mul(fieldTransformMatrix, float4(force, 0.0f)).xyz * {7};\n"
|
||||
" {1} += force * (DeltaTime / {2});\n"
|
||||
" {1} += force * (DeltaTime / max({2}, PARTICLE_THRESHOLD));\n"
|
||||
" }}\n"
|
||||
), position.Value, velocity.Value, mass.Value, fieldPosition.Value, fieldRotation.Value, fieldScale.Value, roughness.Value, intensity.Value, octavesCount.Value);
|
||||
break;
|
||||
@@ -486,21 +486,21 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
|
||||
" float3 u = RAND3;\n"
|
||||
" float sinTheta, cosTheta;\n"
|
||||
" sincos(u.x * PI * 2.0f, sinTheta, cosTheta);\n"
|
||||
" float r = saturate((float){4} / {3});\n"
|
||||
" float2 s1_1 = r * float2( cosTheta, sinTheta) + float2(1, 0);\n"
|
||||
" float2 s1_2 = r * float2(-cosTheta, sinTheta) + float2(1, 0);\n"
|
||||
" float w = s1_1.x / (s1_1.x + s1_2.x);\n"
|
||||
" float r = saturate((float){4} / max({3}, PARTICLE_THRESHOLD));\n"
|
||||
" float2 s11 = r * float2( cosTheta, sinTheta) + float2(1, 0);\n"
|
||||
" float2 s12 = r * float2(-cosTheta, sinTheta) + float2(1, 0);\n"
|
||||
" float w = s11.x / (s11.x + s12.x);\n"
|
||||
" float3 t;\n"
|
||||
" float phi;\n"
|
||||
" if (u.y < w)\n"
|
||||
" {{\n"
|
||||
" phi = radians({5}) * u.y / w;\n"
|
||||
" t = float3(s1_1.x, 0, s1_1.y);\n"
|
||||
" t = float3(s11.x, 0, s11.y);\n"
|
||||
" }}\n"
|
||||
" else\n"
|
||||
" {{\n"
|
||||
" phi = radians({5}) * (u.y - w) / (1.0f - w);\n"
|
||||
" t = float3(s1_2.x, 0, s1_2.y);\n"
|
||||
" t = float3(s12.x, 0, s12.y);\n"
|
||||
" }}\n"
|
||||
" float s, c;\n"
|
||||
" sincos(phi, c, s);\n"
|
||||
@@ -693,7 +693,7 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
|
||||
" if ({4} * sqrLength <= {4} * totalRadius * totalRadius)\n"
|
||||
" {{\n"
|
||||
" float dist = sqrt(sqrLength);\n"
|
||||
" float3 n = {4} * dir / dist;\n"
|
||||
" float3 n = {4} * dir / max(dist, PARTICLE_THRESHOLD);\n"
|
||||
" {0} -= n * (dist - totalRadius) * {4};\n"
|
||||
COLLISION_LOGIC()
|
||||
" }}\n"
|
||||
@@ -787,7 +787,7 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node)
|
||||
" collision = abs(dir.y) > halfHeight || sqrLength > cylinderRadiusT * cylinderRadiusT;\n"
|
||||
" if (collision)\n"
|
||||
" {{\n"
|
||||
" float dist = sqrt(sqrLength);\n"
|
||||
" float dist = max(sqrt(sqrLength), PARTICLE_THRESHOLD);\n"
|
||||
" float distToCap = {4} * (halfHeight - abs(dir.y));\n"
|
||||
" float distToSide = {4} * (cylinderRadiusT - dist);\n"
|
||||
" float3 n = float3(dir.x / dist, sign(dir.y), dir.z / dist) * {4};\n"
|
||||
|
||||
Reference in New Issue
Block a user