31
31
#include " cpu_particles_3d.h"
32
32
#include " cpu_particles_3d.compat.inc"
33
33
34
+ #include " core/math/random_number_generator.h"
34
35
#include " scene/3d/camera_3d.h"
35
36
#include " scene/3d/gpu_particles_3d.h"
36
37
#include " scene/main/viewport.h"
@@ -818,27 +819,27 @@ void CPUParticles3D::_particles_process(double p_delta) {
818
819
tex_anim_offset = curve_parameters[PARAM_ANGLE]->sample (tv);
819
820
}
820
821
821
- p.seed = seed;
822
- uint32_t _seed = seed + uint32_t ( 1 ) + i + cycle ;
823
- p.angle_rand = rand_from_seed (_seed );
824
- p.scale_rand = rand_from_seed (_seed );
825
- p.hue_rot_rand = rand_from_seed (_seed );
826
- p.anim_offset_rand = rand_from_seed (_seed );
822
+ p.seed = seed + uint32_t ( 1 ) + i + cycle ;
823
+ rng-> set_seed (p. seed ) ;
824
+ p.angle_rand = rng-> randf ( );
825
+ p.scale_rand = rng-> randf ( );
826
+ p.hue_rot_rand = rng-> randf ( );
827
+ p.anim_offset_rand = rng-> randf ( );
827
828
828
829
if (color_initial_ramp.is_valid ()) {
829
- p.start_color_rand = color_initial_ramp->get_color_at_offset (rand_from_seed (_seed ));
830
+ p.start_color_rand = color_initial_ramp->get_color_at_offset (rng-> randf ( ));
830
831
} else {
831
832
p.start_color_rand = Color (1 , 1 , 1 , 1 );
832
833
}
833
834
834
835
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
835
- real_t angle1_rad = Math::atan2 (direction.y , direction.x ) + Math::deg_to_rad ((rand_from_seed (_seed ) * 2.0 - 1.0 ) * spread);
836
+ real_t angle1_rad = Math::atan2 (direction.y , direction.x ) + Math::deg_to_rad ((rng-> randf ( ) * 2.0 - 1.0 ) * spread);
836
837
Vector3 rot = Vector3 (Math::cos (angle1_rad), Math::sin (angle1_rad), 0.0 );
837
- p.velocity = rot * Math::lerp (parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], rand_from_seed (_seed ));
838
+ p.velocity = rot * Math::lerp (parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], rng-> randf ( ));
838
839
} else {
839
840
// initiate velocity spread in 3D
840
- real_t angle1_rad = Math::deg_to_rad ((rand_from_seed (_seed ) * (real_t )2.0 - (real_t )1.0 ) * spread);
841
- real_t angle2_rad = Math::deg_to_rad ((rand_from_seed (_seed ) * (real_t )2.0 - (real_t )1.0 ) * ((real_t )1.0 - flatness) * spread);
841
+ real_t angle1_rad = Math::deg_to_rad ((rng-> randf ( ) * (real_t )2.0 - (real_t )1.0 ) * spread);
842
+ real_t angle2_rad = Math::deg_to_rad ((rng-> randf ( ) * (real_t )2.0 - (real_t )1.0 ) * ((real_t )1.0 - flatness) * spread);
842
843
843
844
Vector3 direction_xz = Vector3 (Math::sin (angle1_rad), 0 , Math::cos (angle1_rad));
844
845
Vector3 direction_yz = Vector3 (0 , Math::sin (angle2_rad), Math::cos (angle2_rad));
@@ -858,14 +859,14 @@ void CPUParticles3D::_particles_process(double p_delta) {
858
859
binormal.normalize ();
859
860
Vector3 normal = binormal.cross (direction_nrm);
860
861
spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z ;
861
- p.velocity = spread_direction * Math::lerp (parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], rand_from_seed (_seed ));
862
+ p.velocity = spread_direction * Math::lerp (parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], rng-> randf ( ));
862
863
}
863
864
864
865
real_t base_angle = tex_angle * Math::lerp (parameters_min[PARAM_ANGLE], parameters_max[PARAM_ANGLE], p.angle_rand );
865
866
p.custom [0 ] = Math::deg_to_rad (base_angle); // angle
866
867
p.custom [1 ] = 0.0 ; // phase
867
868
p.custom [2 ] = tex_anim_offset * Math::lerp (parameters_min[PARAM_ANIM_OFFSET], parameters_max[PARAM_ANIM_OFFSET], p.anim_offset_rand ); // animation offset (0-1)
868
- p.custom [3 ] = (1.0 - rand_from_seed (_seed ) * lifetime_randomness);
869
+ p.custom [3 ] = (1.0 - rng-> randf ( ) * lifetime_randomness);
869
870
p.transform = Transform3D ();
870
871
p.time = 0 ;
871
872
p.lifetime = lifetime * p.custom [3 ];
@@ -876,20 +877,20 @@ void CPUParticles3D::_particles_process(double p_delta) {
876
877
// do none
877
878
} break ;
878
879
case EMISSION_SHAPE_SPHERE: {
879
- real_t s = 2.0 * rand_from_seed (_seed ) - 1.0 ;
880
- real_t t = Math_TAU * rand_from_seed (_seed );
881
- real_t x = rand_from_seed (_seed );
880
+ real_t s = 2.0 * rng-> randf ( ) - 1.0 ;
881
+ real_t t = Math_TAU * rng-> randf ( );
882
+ real_t x = rng-> randf ( );
882
883
real_t radius = emission_sphere_radius * Math::sqrt (1.0 - s * s);
883
884
p.transform .origin = Vector3 (0 , 0 , 0 ).lerp (Vector3 (radius * Math::cos (t), radius * Math::sin (t), emission_sphere_radius * s), x);
884
885
} break ;
885
886
case EMISSION_SHAPE_SPHERE_SURFACE: {
886
- real_t s = 2.0 * rand_from_seed (_seed ) - 1.0 ;
887
- real_t t = Math_TAU * rand_from_seed (_seed );
887
+ real_t s = 2.0 * rng-> randf ( ) - 1.0 ;
888
+ real_t t = Math_TAU * rng-> randf ( );
888
889
real_t radius = emission_sphere_radius * Math::sqrt (1.0 - s * s);
889
890
p.transform .origin = Vector3 (radius * Math::cos (t), radius * Math::sin (t), emission_sphere_radius * s);
890
891
} break ;
891
892
case EMISSION_SHAPE_BOX: {
892
- p.transform .origin = Vector3 (rand_from_seed (_seed ) * 2.0 - 1.0 , rand_from_seed (_seed ) * 2.0 - 1.0 , rand_from_seed (_seed ) * 2.0 - 1.0 ) * emission_box_extents;
893
+ p.transform .origin = Vector3 (rng-> randf ( ) * 2.0 - 1.0 , rng-> randf ( ) * 2.0 - 1.0 , rng-> randf ( ) * 2.0 - 1.0 ) * emission_box_extents;
893
894
} break ;
894
895
case EMISSION_SHAPE_POINTS:
895
896
case EMISSION_SHAPE_DIRECTED_POINTS: {
@@ -933,11 +934,11 @@ void CPUParticles3D::_particles_process(double p_delta) {
933
934
case EMISSION_SHAPE_RING: {
934
935
real_t radius_clamped = MAX (0.001 , emission_ring_radius);
935
936
real_t top_radius = MAX (radius_clamped - Math::tan (Math::deg_to_rad (90.0 - emission_ring_cone_angle)) * emission_ring_height, 0.0 );
936
- real_t y_pos = rand_from_seed (_seed );
937
+ real_t y_pos = rng-> randf ( );
937
938
real_t skew = MAX (MIN (radius_clamped, top_radius) / MAX (radius_clamped, top_radius), 0.5 );
938
939
y_pos = radius_clamped < top_radius ? Math::pow (y_pos, skew) : 1.0 - Math::pow (y_pos, skew);
939
- real_t ring_random_angle = rand_from_seed (_seed ) * Math_TAU;
940
- real_t ring_random_radius = Math::sqrt (rand_from_seed (_seed ) * (radius_clamped * radius_clamped - emission_ring_inner_radius * emission_ring_inner_radius) + emission_ring_inner_radius * emission_ring_inner_radius);
940
+ real_t ring_random_angle = rng-> randf ( ) * Math_TAU;
941
+ real_t ring_random_radius = Math::sqrt (rng-> randf ( ) * (radius_clamped * radius_clamped - emission_ring_inner_radius * emission_ring_inner_radius) + emission_ring_inner_radius * emission_ring_inner_radius);
941
942
ring_random_radius = Math::lerp (ring_random_radius, ring_random_radius * (top_radius / radius_clamped), y_pos);
942
943
Vector3 axis = emission_ring_axis == Vector3 (0.0 , 0.0 , 0.0 ) ? Vector3 (0.0 , 0.0 , 1.0 ) : emission_ring_axis.normalized ();
943
944
Vector3 ortho_axis;
@@ -1764,6 +1765,8 @@ CPUParticles3D::CPUParticles3D() {
1764
1765
set_emitting (true );
1765
1766
set_amount (8 );
1766
1767
1768
+ rng.instantiate ();
1769
+
1767
1770
set_param_min (PARAM_INITIAL_LINEAR_VELOCITY, 0 );
1768
1771
set_param_min (PARAM_ANGULAR_VELOCITY, 0 );
1769
1772
set_param_min (PARAM_ORBIT_VELOCITY, 0 );
0 commit comments