summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorSimon Puchert <simonpuchert@alice.de>2019-07-06 00:13:03 +0200
committerSimon Puchert <simonpuchert@alice.de>2019-07-06 00:13:03 +0200
commit18ba1bc824fd4739a34ad78a3c95df1fb552ff1b (patch)
tree3868c88ce05b2dc000e007b926914ee82c095732 /scene/3d
parentd897131ac555de84afe9ca6845abf87c26957895 (diff)
cpu_particles: Return uniform density spheres.
The current implementation normalizes points from a uniform distribution on a cube. This creates a non-uniform distribution on the sphere.
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/cpu_particles.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp
index 358c4bdb44..86b407b9e6 100644
--- a/scene/3d/cpu_particles.cpp
+++ b/scene/3d/cpu_particles.cpp
@@ -643,7 +643,9 @@ void CPUParticles::_particles_process(float p_delta) {
//do none
} break;
case EMISSION_SHAPE_SPHERE: {
- p.transform.origin = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0).normalized() * emission_sphere_radius;
+ float s = 2.0 * Math::randf() - 1.0, t = 2.0 * Math_PI * Math::randf();
+ float radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
+ p.transform.origin = Vector3(radius * Math::cos(t), radius * Math::sin(t), emission_sphere_radius * s);
} break;
case EMISSION_SHAPE_BOX: {
p.transform.origin = Vector3(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_box_extents;