Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPUParticles2D: Generated emission mask is too random #97567

Closed
MelPeslier opened this issue Sep 28, 2024 · 0 comments · Fixed by #101162
Closed

GPUParticles2D: Generated emission mask is too random #97567

MelPeslier opened this issue Sep 28, 2024 · 0 comments · Fixed by #101162

Comments

@MelPeslier
Copy link

MelPeslier commented Sep 28, 2024

Tested versions

4.3

System information

Godot v4.3.stable - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3060 (NVIDIA; 32.0.15.6109) - 12th Gen Intel(R) Core(TM) i7-12700KF (20 Threads)

Issue description

When loading emission mask, particles use (diferent !) randomness for each of the components (position, color, normal).
I would expect that each pixel at a posiiton have the corect coor value and not a random one. Same for normals, that each pixel keep the normal he own, and not just a random value.

What's missing is to writte on the shader a variable 'custom_seed', that's passed to all of theses 3 parameters when loading from an emission mask.

And also, let 'generate emission mask' be a function that's available via script so we can generate from any textures !

  • What it should do COLORS:

Capture d'écran 2024-09-28 002700

  • What it does COLORS :

Capture d'écran 2024-09-28 002952

  • What it should do NORMAL:
demo_should.mp4
  • What it does NORMAL:
demo_should_NOT.mp4

I made a litle tool where I do as in the godot engine, but in GDScript to generate it from a viewport texture, and I altered the shader code to have a common 'custom_seed' shared between theses params.

Here is a part of the shader :

vec3 calculate_initial_position(inout uint alt_seed, in float custom_seed) {
	...
		int point = min(emission_texture_point_count - 1, int(custom_seed * float(emission_texture_point_count)));
		ivec2 emission_tex_size = textureSize(emission_texture_points, 0);
		ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);
		pos = texelFetch(emission_texture_points, emission_tex_ofs, 0).xyz;
	}
...
}
void calculate_initial_display_params(inout DisplayParameters params, inout uint alt_seed, in float custom_seed) {
   ...
	int point = min(emission_texture_point_count - 1, int(custom_seed * float(emission_texture_point_count)));
	ivec2 emission_tex_size = textureSize(emission_texture_points, 0);
	ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);
	params.color *= texelFetch(emission_texture_color, emission_tex_ofs, 0);
}

void start() {
   ...
	**float custom_seed = rand_from_seed(alt_seed);**

	calculate_initial_display_params(params, alt_seed, **custom_seed**);

	if (RESTART_POSITION) {
		TRANSFORM[3].xyz = calculate_initial_position(alt_seed, **custom_seed**);
		TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;
	}

	if (RESTART_VELOCITY) {
		...
		int point = min(emission_texture_point_count - 1, int(**custom_seed** * float(emission_texture_point_count)));
		ivec2 emission_tex_size = textureSize(emission_texture_points, 0);
		ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);
		{
			mat2 rotm;
			rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;
			rotm[1] = rotm[0].yx * vec2(1.0, -1.0);
			VELOCITY.xy = rotm * VELOCITY.xy;
		}

Steps to reproduce

  1. Add a gpu particle 2D to your scene
  2. Choose 'Load emission mask'
  3. Select pixel color
  4. Select emission border oriented

Minimal reproduction project (MRP)

N/A

@akien-mga akien-mga added this to the 4.4 milestone Jan 7, 2025
@akien-mga akien-mga changed the title GPUParticles2D : Genererate emission mask is too random GPUParticles2D: Generated emission mask is too random Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants