@@ -523,6 +523,7 @@ void ParticleProcessMaterial::_update_shader() {
523523 code += " float animation_offset;\n " ;
524524 code += " float lifetime;\n " ;
525525 code += " vec4 color;\n " ;
526+ code += " float emission_texture_position;\n " ;
526527 code += " };\n\n " ;
527528
528529 code += " struct DynamicsParameters {\n " ;
@@ -579,11 +580,15 @@ void ParticleProcessMaterial::_update_shader() {
579580 if (color_initial_ramp.is_valid ()) {
580581 code += " params.color *= texture(color_initial_ramp, vec2(rand_from_seed(alt_seed)));\n " ;
581582 }
582- if (emission_color_texture.is_valid () && (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS)) {
583- code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n " ;
584- code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n " ;
585- code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n " ;
586- code += " params.color *= texelFetch(emission_texture_color, emission_tex_ofs, 0);\n " ;
583+ if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
584+ code += " params.emission_texture_position = rand_from_seed(alt_seed);\n " ;
585+
586+ if (emission_color_texture.is_valid ()) {
587+ code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n " ;
588+ code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n " ;
589+ code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n " ;
590+ code += " params.color *= texelFetch(emission_texture_color, emission_tex_ofs, 0);\n " ;
591+ }
587592 }
588593 code += " }\n\n " ;
589594
@@ -614,7 +619,7 @@ void ParticleProcessMaterial::_update_shader() {
614619 }
615620 code += " }\n\n " ;
616621
617- code += " vec3 calculate_initial_position(inout uint alt_seed) {\n " ;
622+ code += " vec3 calculate_initial_position(inout DisplayParameters params, inout uint alt_seed) {\n " ;
618623 code += " float pi = 3.14159;\n " ;
619624 code += " vec3 pos = vec3(0.0);\n " ;
620625 code += " { // Emission shape.\n " ;
@@ -639,7 +644,7 @@ void ParticleProcessMaterial::_update_shader() {
639644 code += " pos = 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 " ;
640645 }
641646 if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
642- code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n " ;
647+ code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n " ;
643648 code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n " ;
644649 code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n " ;
645650 code += " pos = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz;\n " ;
@@ -860,7 +865,7 @@ void ParticleProcessMaterial::_update_shader() {
860865 code += " TRANSFORM[2].xyz = vec3(0.0, 0.0, 1.0);\n " ;
861866 code += " }\n " ;
862867 code += " if (RESTART_POSITION) {\n " ;
863- code += " TRANSFORM[3].xyz = calculate_initial_position(alt_seed);\n " ;
868+ code += " TRANSFORM[3].xyz = calculate_initial_position(params, alt_seed);\n " ;
864869 if (turbulence_enabled) {
865870 code += " float initial_turbulence_displacement = mix(turbulence_initial_displacement_min, turbulence_initial_displacement_max, rand_from_seed(alt_seed));\n " ;
866871 code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n " ;
@@ -871,7 +876,7 @@ void ParticleProcessMaterial::_update_shader() {
871876 code += " if (RESTART_VELOCITY) {\n " ;
872877 code += " VELOCITY = get_random_direction_from_spread(alt_seed, spread) * dynamic_params.initial_velocity_multiplier;\n " ;
873878 if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
874- code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n " ;
879+ code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n " ;
875880 code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n " ;
876881 code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n " ;
877882 if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
0 commit comments