Merge pull request #30357 from simonpuchert/spheres
Particles / CPUParticles: Return uniform density spheres.
This commit is contained in:
commit
1fa26b969c
3 changed files with 10 additions and 4 deletions
|
@ -661,8 +661,9 @@ void CPUParticles2D::_particles_process(float p_delta) {
|
||||||
//do none
|
//do none
|
||||||
} break;
|
} break;
|
||||||
case EMISSION_SHAPE_SPHERE: {
|
case EMISSION_SHAPE_SPHERE: {
|
||||||
Vector3 sphere_shape = 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 = Math::randf(), t = 2.0 * Math_PI * Math::randf();
|
||||||
p.transform[2] = Vector2(sphere_shape.x, sphere_shape.y);
|
float radius = emission_sphere_radius * Math::sqrt(1.0 - s * s);
|
||||||
|
p.transform[2] = Vector2(Math::cos(t), Math::sin(t)) * radius;
|
||||||
} break;
|
} break;
|
||||||
case EMISSION_SHAPE_RECTANGLE: {
|
case EMISSION_SHAPE_RECTANGLE: {
|
||||||
p.transform[2] = Vector2(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_rect_extents;
|
p.transform[2] = Vector2(Math::randf() * 2.0 - 1.0, Math::randf() * 2.0 - 1.0) * emission_rect_extents;
|
||||||
|
|
|
@ -643,7 +643,9 @@ void CPUParticles::_particles_process(float p_delta) {
|
||||||
//do none
|
//do none
|
||||||
} break;
|
} break;
|
||||||
case EMISSION_SHAPE_SPHERE: {
|
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;
|
} break;
|
||||||
case EMISSION_SHAPE_BOX: {
|
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;
|
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;
|
||||||
|
|
|
@ -332,7 +332,10 @@ void ParticlesMaterial::_update_shader() {
|
||||||
//do none
|
//do none
|
||||||
} break;
|
} break;
|
||||||
case EMISSION_SHAPE_SPHERE: {
|
case EMISSION_SHAPE_SPHERE: {
|
||||||
code += " TRANSFORM[3].xyz = normalize(vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0)) * emission_sphere_radius;\n";
|
code += " float s = rand_from_seed(alt_seed) * 2.0 - 1.0;\n";
|
||||||
|
code += " float t = rand_from_seed(alt_seed) * 2.0 * pi;\n";
|
||||||
|
code += " float radius = emission_sphere_radius * sqrt(1.0 - s * s);\n";
|
||||||
|
code += " TRANSFORM[3].xyz = vec3(radius * cos(t), radius * sin(t), emission_sphere_radius * s);\n";
|
||||||
} break;
|
} break;
|
||||||
case EMISSION_SHAPE_BOX: {
|
case EMISSION_SHAPE_BOX: {
|
||||||
code += " TRANSFORM[3].xyz = vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0) * emission_box_extents;\n";
|
code += " TRANSFORM[3].xyz = vec3(rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, rand_from_seed(alt_seed) * 2.0 - 1.0) * emission_box_extents;\n";
|
||||||
|
|
Loading…
Reference in a new issue