Merge pull request #101162 from timoschwarzer/fix/gpu-particles-2d-emission-textures
Fix ParticleProcessMaterial not using same offsets for emission textures
This commit is contained in:
commit
33c0fc5508
@ -523,6 +523,7 @@ void ParticleProcessMaterial::_update_shader() {
|
||||
code += " float animation_offset;\n";
|
||||
code += " float lifetime;\n";
|
||||
code += " vec4 color;\n";
|
||||
code += " float emission_texture_position;\n";
|
||||
code += "};\n\n";
|
||||
|
||||
code += "struct DynamicsParameters {\n";
|
||||
@ -579,11 +580,15 @@ void ParticleProcessMaterial::_update_shader() {
|
||||
if (color_initial_ramp.is_valid()) {
|
||||
code += " params.color *= texture(color_initial_ramp, vec2(rand_from_seed(alt_seed)));\n";
|
||||
}
|
||||
if (emission_color_texture.is_valid() && (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS)) {
|
||||
code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n";
|
||||
code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
|
||||
code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
|
||||
code += " params.color *= texelFetch(emission_texture_color, emission_tex_ofs, 0);\n";
|
||||
if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
|
||||
code += " params.emission_texture_position = rand_from_seed(alt_seed);\n";
|
||||
|
||||
if (emission_color_texture.is_valid()) {
|
||||
code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n";
|
||||
code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
|
||||
code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
|
||||
code += " params.color *= texelFetch(emission_texture_color, emission_tex_ofs, 0);\n";
|
||||
}
|
||||
}
|
||||
code += "}\n\n";
|
||||
|
||||
@ -614,7 +619,7 @@ void ParticleProcessMaterial::_update_shader() {
|
||||
}
|
||||
code += "}\n\n";
|
||||
|
||||
code += "vec3 calculate_initial_position(inout uint alt_seed) {\n";
|
||||
code += "vec3 calculate_initial_position(inout DisplayParameters params, inout uint alt_seed) {\n";
|
||||
code += " float pi = 3.14159;\n";
|
||||
code += " vec3 pos = vec3(0.0);\n";
|
||||
code += " { // Emission shape.\n";
|
||||
@ -639,7 +644,7 @@ void ParticleProcessMaterial::_update_shader() {
|
||||
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";
|
||||
}
|
||||
if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
|
||||
code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n";
|
||||
code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n";
|
||||
code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
|
||||
code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
|
||||
code += " pos = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz;\n";
|
||||
@ -860,7 +865,7 @@ void ParticleProcessMaterial::_update_shader() {
|
||||
code += " TRANSFORM[2].xyz = vec3(0.0, 0.0, 1.0);\n";
|
||||
code += " }\n";
|
||||
code += " if (RESTART_POSITION) {\n";
|
||||
code += " TRANSFORM[3].xyz = calculate_initial_position(alt_seed);\n";
|
||||
code += " TRANSFORM[3].xyz = calculate_initial_position(params, alt_seed);\n";
|
||||
if (turbulence_enabled) {
|
||||
code += " float initial_turbulence_displacement = mix(turbulence_initial_displacement_min, turbulence_initial_displacement_max, rand_from_seed(alt_seed));\n";
|
||||
code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n";
|
||||
@ -871,7 +876,7 @@ void ParticleProcessMaterial::_update_shader() {
|
||||
code += " if (RESTART_VELOCITY) {\n";
|
||||
code += " VELOCITY = get_random_direction_from_spread(alt_seed, spread) * dynamic_params.initial_velocity_multiplier;\n";
|
||||
if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
|
||||
code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n";
|
||||
code += " int point = min(emission_texture_point_count - 1, int(params.emission_texture_position * float(emission_texture_point_count)));\n";
|
||||
code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
|
||||
code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
|
||||
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user