### Godot version

v4.1.beta1.mono.official [828ec2c5d]

### System information

Kubuntu 22.04 Compatability

### Issue description
<Details>

```
Set emitting
Set emitting
Set sub_emitter_mode
Set sub_emitter_mode
  drivers/gles3/shader_gles3.cpp:242 - ParticlesShaderGLES3: Vertex shader compilation failed:
  0:679(16): error: `EMISSION_FLAG_HAS_POSITION' undeclared
  0:679(45): error: `EMISSION_FLAG_HAS_ROTATION_SCALE' undeclared
  0:679(16): error: LHS of `|' must be an integer
  0:682(11): error: `EMISSION_FLAG_HAS_VELOCITY' undeclared
  0:684(2): error: no function with name 'emit_subparticle'
  
  drivers/gles3/shader_gles3.cpp:336 - Method/function failed.
1: #version 330
2: #define USE_GLES_OVER_GL
3: #define MATERIAL_UNIFORMS_USED
4: #define START_CODE_USED
5: #define PROCESS_CODE_USED
6: 
7: #define MAX_GLOBAL_SHADER_UNIFORMS 256
8: 
9: 
10: #ifdef USE_MULTIVIEW
11: #if defined(GL_OVR_multiview2)
12: #extension GL_OVR_multiview2 : require
13: #elif defined(GL_OVR_multiview)
14: #extension GL_OVR_multiview : require
15: #endif
16: layout(num_views=2) in;
17: #define ViewIndex gl_ViewID_OVR
18: #define MAX_VIEWS 2
19: #else
20: #define ViewIndex uint(0)
21: #define MAX_VIEWS 1
22: #endif
23: precision highp float;
24: precision highp int;
25: 
26: #define SDF_MAX_LENGTH 16384.0
27: 
28: layout(std140) uniform GlobalShaderUniformData { //ubo:1
29: 	vec4 global_shader_uniforms[MAX_GLOBAL_SHADER_UNIFORMS];
30: };
31: 
32: // This needs to be outside clang-format so the ubo comment is in the right place
33: #ifdef MATERIAL_UNIFORMS_USED
34: layout(std140) uniform MaterialUniforms{ //ubo:2
35: 
36: highp vec3 m_direction;
37: highp float m_spread;
38: highp float m_flatness;
39: highp float m_initial_linear_velocity_min;
40: highp float m_initial_angle_min;
41: highp float m_angular_velocity_min;
42: highp float m_orbit_velocity_min;
43: highp float m_linear_accel_min;
44: highp float m_radial_accel_min;
45: highp float m_tangent_accel_min;
46: highp float m_damping_min;
47: highp float m_scale_min;
48: highp float m_hue_variation_min;
49: highp float m_anim_speed_min;
50: highp float m_anim_offset_min;
51: highp float m_initial_linear_velocity_max;
52: highp float m_initial_angle_max;
53: highp float m_angular_velocity_max;
54: highp float m_orbit_velocity_max;
55: highp float m_linear_accel_max;
56: highp float m_radial_accel_max;
57: highp float m_tangent_accel_max;
58: highp float m_damping_max;
59: highp float m_scale_max;
60: highp float m_hue_variation_max;
61: highp float m_anim_speed_max;
62: highp float m_anim_offset_max;
63: highp float m_lifetime_randomness;
64: highp float m_emission_sphere_radius;
65: int m_sub_emitter_amount_at_end;
66: bool m_sub_emitter_keep_velocity;
67: highp vec4 m_color_value;
68: highp vec3 m_gravity;
69: 
70: };
71: #endif
72: 
73: /* clang-format on */
74: 
75: #define MAX_ATTRACTORS 32
76: 
77: #define ATTRACTOR_TYPE_SPHERE uint(0)
78: #define ATTRACTOR_TYPE_BOX uint(1)
79: #define ATTRACTOR_TYPE_VECTOR_FIELD uint(2)
80: 
81: struct Attractor {
82: 	mat4 transform;
83: 	vec4 extents; // Extents or radius. w-channel is padding.
84: 
85: 	uint type;
86: 	float strength;
87: 	float attenuation;
88: 	float directionality;
89: };
90: 
91: #define MAX_COLLIDERS 32
92: 
93: #define COLLIDER_TYPE_SPHERE uint(0)
94: #define COLLIDER_TYPE_BOX uint(1)
95: #define COLLIDER_TYPE_SDF uint(2)
96: #define COLLIDER_TYPE_HEIGHT_FIELD uint(3)
97: #define COLLIDER_TYPE_2D_SDF uint(4)
98: 
99: struct Collider {
100: 	mat4 transform;
101: 	vec4 extents; // Extents or radius. w-channel is padding.
102: 
103: 	uint type;
104: 	float scale;
105: 	float pad0;
106: 	float pad1;
107: };
108: 
109: layout(std140) uniform FrameData { //ubo:0
110: 	bool emitting;
111: 	uint cycle;
112: 	float system_phase;
113: 	float prev_system_phase;
114: 
115: 	float explosiveness;
116: 	float randomness;
117: 	float time;
118: 	float delta;
119: 
120: 	float particle_size;
121: 	float pad0;
122: 	float pad1;
123: 	float pad2;
124: 
125: 	uint random_seed;
126: 	uint attractor_count;
127: 	uint collider_count;
128: 	uint frame;
129: 
130: 	mat4 emission_transform;
131: 
132: 	Attractor attractors[MAX_ATTRACTORS];
133: 	Collider colliders[MAX_COLLIDERS];
134: };
135: 
136: #define PARTICLE_FLAG_ACTIVE uint(1)
137: #define PARTICLE_FLAG_STARTED uint(2)
138: #define PARTICLE_FLAG_TRAILED uint(4)
139: #define PARTICLE_FRAME_MASK uint(0xFFFF)
140: #define PARTICLE_FRAME_SHIFT uint(16)
141: 
142: // ParticleData
143: layout(location = 0) in highp vec4 color;
144: layout(location = 1) in highp vec4 velocity_flags;
145: layout(location = 2) in highp vec4 custom;
146: layout(location = 3) in highp vec4 xform_1;
147: layout(location = 4) in highp vec4 xform_2;
148: #ifdef MODE_3D
149: layout(location = 5) in highp vec4 xform_3;
150: #endif
151: #ifdef USERDATA1_USED
152: layout(location = 6) in highp vec4 userdata1;
153: #endif
154: #ifdef USERDATA2_USED
155: layout(location = 7) in highp vec4 userdata2;
156: #endif
157: #ifdef USERDATA3_USED
158: layout(location = 8) in highp vec4 userdata3;
159: #endif
160: #ifdef USERDATA4_USED
161: layout(location = 9) in highp vec4 userdata4;
162: #endif
163: #ifdef USERDATA5_USED
164: layout(location = 10) in highp vec4 userdata5;
165: #endif
166: #ifdef USERDATA6_USED
167: layout(location = 11) in highp vec4 userdata6;
168: #endif
169: 
170: out highp vec4 out_color; //tfb:
171: out highp vec4 out_velocity_flags; //tfb:
172: out highp vec4 out_custom; //tfb:
173: out highp vec4 out_xform_1; //tfb:
174: out highp vec4 out_xform_2; //tfb:
175: #ifdef MODE_3D
176: out highp vec4 out_xform_3; //tfb:MODE_3D
177: #endif
178: #ifdef USERDATA1_USED
179: out highp vec4 out_userdata1; //tfb:USERDATA1_USED
180: #endif
181: #ifdef USERDATA2_USED
182: out highp vec4 out_userdata2; //tfb:USERDATA2_USED
183: #endif
184: #ifdef USERDATA3_USED
185: out highp vec4 out_userdata3; //tfb:USERDATA3_USED
186: #endif
187: #ifdef USERDATA4_USED
188: out highp vec4 out_userdata4; //tfb:USERDATA4_USED
189: #endif
190: #ifdef USERDATA5_USED
191: out highp vec4 out_userdata5; //tfb:USERDATA5_USED
192: #endif
193: #ifdef USERDATA6_USED
194: out highp vec4 out_userdata6; //tfb:USERDATA6_USED
195: #endif
196: 
197: uniform sampler2D height_field_texture; //texunit:0
198: 
199: uniform float lifetime;
200: uniform bool clear;
201: uniform uint total_particles;
202: uniform bool use_fractional_delta;
203: 
204: uint hash(uint x) {
205: 	x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b);
206: 	x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b);
207: 	x = (x >> uint(16)) ^ x;
208: 	return x;
209: }
210: 
211: vec3 safe_normalize(vec3 direction) {
212: 	const float EPSILON = 0.001;
213: 	if (length(direction) < EPSILON) {
214: 		return vec3(0.0);
215: 	}
216: 	return normalize(direction);
217: }
218: 
219: // Needed whenever 2D sdf texture is read from as it is packed in RGBA8.
220: float vec4_to_float(vec4 p_vec) {
221: 	return dot(p_vec, vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0)) * 2.0 - 1.0;
222: }
223: 
224: 
225: uint m_hash(uint m_x)
226: 	{
227: 		m_x=(((m_x >> 16u) ^ m_x) * 73244475u);
228: 		m_x=(((m_x >> 16u) ^ m_x) * 73244475u);
229: 		m_x=((m_x >> 16u) ^ m_x);
230: return m_x;	}
231: 
232: float m_rand_from_seed(inout uint m_seed)
233: 	{
234: 		int m_k;
235: 		int m_s=int(m_seed);
236: 		if ((m_s == 0))
237: 		{
238: 			m_s=305420679;
239: 		}
240: 		m_k=(m_s / 127773);
241: 		m_s=((16807 * (m_s - (m_k * 127773))) - (2836 * m_k));
242: 		if ((m_s < 0))
243: 		{
244: 			m_s+=2147483647;
245: 		}
246: 		m_seed=uint(m_s);
247: return (float((m_seed % 65536u)) / 65535.0);	}
248: 
249: float m_rand_from_seed_m1_p1(inout uint m_seed)
250: 	{
251: return ((m_rand_from_seed(m_seed) * 2.0) - 1.0);	}
252: 
253: void main() {
254: 	bool apply_forces = true;
255: 	bool apply_velocity = true;
256: 	float local_delta = delta;
257: 
258: 	float mass = 1.0;
259: 
260: 	bool restart = false;
261: 
262: 	bool restart_position = false;
263: 	bool restart_rotation_scale = false;
264: 	bool restart_velocity = false;
265: 	bool restart_color = false;
266: 	bool restart_custom = false;
267: 
268: 	mat4 xform = mat4(1.0);
269: 	uint flags = 0u;
270: 
271: 	if (clear) {
272: 		out_color = vec4(1.0);
273: 		out_custom = vec4(0.0);
274: 		out_velocity_flags = vec4(0.0);
275: 	} else {
276: 		out_color = color;
277: 		out_velocity_flags = velocity_flags;
278: 		out_custom = custom;
279: 		xform[0] = xform_1;
280: 		xform[1] = xform_2;
281: #ifdef MODE_3D
282: 		xform[2] = xform_3;
283: #endif
284: 		xform = transpose(xform);
285: 		flags = floatBitsToUint(velocity_flags.w);
286: 	}
287: 
288: 	//clear started flag if set
289: 	flags &= ~PARTICLE_FLAG_STARTED;
290: 
291: 	bool collided = false;
292: 	vec3 collision_normal = vec3(0.0);
293: 	float collision_depth = 0.0;
294: 
295: 	vec3 attractor_force = vec3(0.0);
296: 
297: #if !defined(DISABLE_VELOCITY)
298: 
299: 	if (bool(flags & PARTICLE_FLAG_ACTIVE)) {
300: 		xform[3].xyz += out_velocity_flags.xyz * local_delta;
301: 	}
302: #endif
303: 	uint index = uint(gl_VertexID);
304: 	if (emitting) {
305: 		float restart_phase = float(index) / float(total_particles);
306: 
307: 		if (randomness > 0.0) {
308: 			uint seed = cycle;
309: 			if (restart_phase >= system_phase) {
310: 				seed -= uint(1);
311: 			}
312: 			seed *= uint(total_particles);
313: 			seed += index;
314: 			float random = float(hash(seed) % uint(65536)) / 65536.0;
315: 			restart_phase += randomness * random * 1.0 / float(total_particles);
316: 		}
317: 
318: 		restart_phase *= (1.0 - explosiveness);
319: 
320: 		if (system_phase > prev_system_phase) {
321: 			// restart_phase >= prev_system_phase is used so particles emit in the first frame they are processed
322: 
323: 			if (restart_phase >= prev_system_phase && restart_phase < system_phase) {
324: 				restart = true;
325: 				if (use_fractional_delta) {
326: 					local_delta = (system_phase - restart_phase) * lifetime;
327: 				}
328: 			}
329: 
330: 		} else if (delta > 0.0) {
331: 			if (restart_phase >= prev_system_phase) {
332: 				restart = true;
333: 				if (use_fractional_delta) {
334: 					local_delta = (1.0 - restart_phase + system_phase) * lifetime;
335: 				}
336: 
337: 			} else if (restart_phase < system_phase) {
338: 				restart = true;
339: 				if (use_fractional_delta) {
340: 					local_delta = (system_phase - restart_phase) * lifetime;
341: 				}
342: 			}
343: 		}
344: 
345: 		if (restart) {
346: 			flags = emitting ? (PARTICLE_FLAG_ACTIVE | PARTICLE_FLAG_STARTED | (cycle << PARTICLE_FRAME_SHIFT)) : 0u;
347: 			restart_position = true;
348: 			restart_rotation_scale = true;
349: 			restart_velocity = true;
350: 			restart_color = true;
351: 			restart_custom = true;
352: 		}
353: 	}
354: 
355: 	bool particle_active = bool(flags & PARTICLE_FLAG_ACTIVE);
356: 
357: 	uint particle_number = (flags >> PARTICLE_FRAME_SHIFT) * uint(total_particles) + index;
358: 
359: 	if (restart && particle_active) {
360: 	{
361: 		uint m_base_number=particle_number;
362: 		uint m_alt_seed=m_hash(((m_base_number + 1u) + random_seed));
363: 		float m_angle_rand=m_rand_from_seed(m_alt_seed);
364: 		float m_scale_rand=m_rand_from_seed(m_alt_seed);
365: 		float m_hue_rot_rand=m_rand_from_seed(m_alt_seed);
366: 		float m_anim_offset_rand=m_rand_from_seed(m_alt_seed);
367: 		float m_pi=3.14159;
368: 		float m_degree_to_rad=(m_pi / 180.0);
369: 		float m_tex_angle=1.0;
370: 		float m_tex_anim_offset=1.0;
371: 		float m_spread_rad=(m_spread * m_degree_to_rad);
372: 		if (restart_velocity)
373: 		{
374: 					{
375: 			float m_tex_linear_velocity=1.0;
376: 					{
377: 			float m_angle1_rad=(m_rand_from_seed_m1_p1(m_alt_seed) * m_spread_rad);
378: 			m_angle1_rad+=((m_direction.x != 0.0)?atan(m_direction.y, m_direction.x):(sign(m_direction.y) * (m_pi / 2.0)));
379: 			vec3 m_rot=vec3(cos(m_angle1_rad), sin(m_angle1_rad), 0.0);
380: 			out_velocity_flags.xyz=(m_rot * mix(m_initial_linear_velocity_min, m_initial_linear_velocity_max, m_rand_from_seed(m_alt_seed)));
381: 		}
382: ;
383: 		}
384: ;
385: 		}
386: 		float m_base_angle=(m_tex_angle * mix(m_initial_angle_min, m_initial_angle_max, m_angle_rand));
387: 		out_custom.x=(m_base_angle * m_degree_to_rad);
388: 		out_custom.y=0.0;
389: 		out_custom.w=(1.0 - (m_lifetime_randomness * m_rand_from_seed(m_alt_seed)));
390: 		out_custom.z=(m_tex_anim_offset * mix(m_anim_offset_min, m_anim_offset_max, m_anim_offset_rand));
391: 		if (restart_position)
392: 		{
393: 					{
394: 			float m_s=((m_rand_from_seed(m_alt_seed) * 2.0) - 1.0);
395: 			float m_t=((m_rand_from_seed(m_alt_seed) * 2.0) * m_pi);
396: 			float m_p=m_rand_from_seed(m_alt_seed);
397: 			float m_radius=(m_emission_sphere_radius * sqrt((1.0 - (m_s * m_s))));
398: 			xform[3].xyz=mix(vec3(0.0,0.0,0.0), vec3((m_radius * cos(m_t)), (m_radius * sin(m_t)), (m_emission_sphere_radius * m_s)), m_p);
399: 			if (restart_velocity)
400: 			{
401: 				out_velocity_flags.xyz=(emission_transform * vec4(out_velocity_flags.xyz, 0.0)).xyz;
402: 			}
403: 			xform=(emission_transform * xform);
404: 			out_velocity_flags.xyz.z=0.0;
405: 			xform[3].z=0.0;
406: 		}
407: ;
408: 		}
409: 	}
410: 	}
411: 
412: 	if (particle_active) {
413: 		for (uint i = 0u; i < attractor_count; i++) {
414: 			vec3 dir;
415: 			float amount;
416: 			vec3 rel_vec = xform[3].xyz - attractors[i].transform[3].xyz;
417: 			vec3 local_pos = rel_vec * mat3(attractors[i].transform);
418: 
419: 			if (attractors[i].type == ATTRACTOR_TYPE_SPHERE) {
420: 				dir = safe_normalize(rel_vec);
421: 				float d = length(local_pos) / attractors[i].extents.x;
422: 				if (d > 1.0) {
423: 					continue;
424: 				}
425: 				amount = max(0.0, 1.0 - d);
426: 			} else if (attractors[i].type == ATTRACTOR_TYPE_BOX) {
427: 				dir = safe_normalize(rel_vec);
428: 
429: 				vec3 abs_pos = abs(local_pos / attractors[i].extents.xyz);
430: 				float d = max(abs_pos.x, max(abs_pos.y, abs_pos.z));
431: 				if (d > 1.0) {
432: 					continue;
433: 				}
434: 				amount = max(0.0, 1.0 - d);
435: 			} else if (attractors[i].type == ATTRACTOR_TYPE_VECTOR_FIELD) {
436: 			}
437: 			amount = pow(amount, attractors[i].attenuation);
438: 			dir = safe_normalize(mix(dir, attractors[i].transform[2].xyz, attractors[i].directionality));
439: 			attractor_force -= amount * dir * attractors[i].strength;
440: 		}
441: 
442: 		float particle_size = particle_size;
443: 
444: #ifdef USE_COLLISION_SCALE
445: 
446: 		particle_size *= dot(vec3(length(xform[0].xyz), length(xform[1].xyz), length(xform[2].xyz)), vec3(0.33333333333));
447: 
448: #endif
449: 
450: 		if (collider_count == 1u && colliders[0].type == COLLIDER_TYPE_2D_SDF) {
451: 			//2D collision
452: 
453: 			vec2 pos = xform[3].xy;
454: 			vec4 to_sdf_x = colliders[0].transform[0];
455: 			vec4 to_sdf_y = colliders[0].transform[1];
456: 			vec2 sdf_pos = vec2(dot(vec4(pos, 0, 1), to_sdf_x), dot(vec4(pos, 0, 1), to_sdf_y));
457: 
458: 			vec4 sdf_to_screen = vec4(colliders[0].extents.xyz, colliders[0].scale);
459: 
460: 			vec2 uv_pos = sdf_pos * sdf_to_screen.xy + sdf_to_screen.zw;
461: 
462: 			if (all(greaterThan(uv_pos, vec2(0.0))) && all(lessThan(uv_pos, vec2(1.0)))) {
463: 				vec2 pos2 = pos + vec2(0, particle_size);
464: 				vec2 sdf_pos2 = vec2(dot(vec4(pos2, 0, 1), to_sdf_x), dot(vec4(pos2, 0, 1), to_sdf_y));
465: 				float sdf_particle_size = distance(sdf_pos, sdf_pos2);
466: 
467: 				float d = vec4_to_float(texture(height_field_texture, uv_pos)) * SDF_MAX_LENGTH;
468: 
469: 				d -= sdf_particle_size;
470: 
471: 				if (d < 0.0) {
472: 					const float EPSILON = 0.001;
473: 					vec2 n = normalize(vec2(
474: 							vec4_to_float(texture(height_field_texture, uv_pos + vec2(EPSILON, 0.0))) - vec4_to_float(texture(height_field_texture, uv_pos - vec2(EPSILON, 0.0))),
475: 							vec4_to_float(texture(height_field_texture, uv_pos + vec2(0.0, EPSILON))) - vec4_to_float(texture(height_field_texture, uv_pos - vec2(0.0, EPSILON)))));
476: 
477: 					collided = true;
478: 					sdf_pos2 = sdf_pos + n * d;
479: 					pos2 = vec2(dot(vec4(sdf_pos2, 0, 1), colliders[0].transform[2]), dot(vec4(sdf_pos2, 0, 1), colliders[0].transform[3]));
480: 
481: 					n = pos - pos2;
482: 
483: 					collision_normal = normalize(vec3(n, 0.0));
484: 					collision_depth = length(n);
485: 				}
486: 			}
487: 
488: 		} else {
489: 			for (uint i = 0u; i < collider_count; i++) {
490: 				vec3 normal;
491: 				float depth;
492: 				bool col = false;
493: 
494: 				vec3 rel_vec = xform[3].xyz - colliders[i].transform[3].xyz;
495: 				vec3 local_pos = rel_vec * mat3(colliders[i].transform);
496: 
497: 				if (colliders[i].type == COLLIDER_TYPE_SPHERE) {
498: 					float d = length(rel_vec) - (particle_size + colliders[i].extents.x);
499: 
500: 					if (d < 0.0) {
501: 						col = true;
502: 						depth = -d;
503: 						normal = normalize(rel_vec);
504: 					}
505: 				} else if (colliders[i].type == COLLIDER_TYPE_BOX) {
506: 					vec3 abs_pos = abs(local_pos);
507: 					vec3 sgn_pos = sign(local_pos);
508: 
509: 					if (any(greaterThan(abs_pos, colliders[i].extents.xyz))) {
510: 						//point outside box
511: 
512: 						vec3 closest = min(abs_pos, colliders[i].extents.xyz);
513: 						vec3 rel = abs_pos - closest;
514: 						depth = length(rel) - particle_size;
515: 						if (depth < 0.0) {
516: 							col = true;
517: 							normal = mat3(colliders[i].transform) * (normalize(rel) * sgn_pos);
518: 							depth = -depth;
519: 						}
520: 					} else {
521: 						//point inside box
522: 						vec3 axis_len = colliders[i].extents.xyz - abs_pos;
523: 						// there has to be a faster way to do this?
524: 						if (all(lessThan(axis_len.xx, axis_len.yz))) {
525: 							normal = vec3(1, 0, 0);
526: 						} else if (all(lessThan(axis_len.yy, axis_len.xz))) {
527: 							normal = vec3(0, 1, 0);
528: 						} else {
529: 							normal = vec3(0, 0, 1);
530: 						}
531: 
532: 						col = true;
533: 						depth = dot(normal * axis_len, vec3(1)) + particle_size;
534: 						normal = mat3(colliders[i].transform) * (normal * sgn_pos);
535: 					}
536: 				} else if (colliders[i].type == COLLIDER_TYPE_SDF) {
537: 				} else if (colliders[i].type == COLLIDER_TYPE_HEIGHT_FIELD) {
538: 					vec3 local_pos_bottom = local_pos;
539: 					local_pos_bottom.y -= particle_size;
540: 
541: 					if (any(greaterThan(abs(local_pos_bottom), colliders[i].extents.xyz))) {
542: 						continue;
543: 					}
544: 					const float DELTA = 1.0 / 8192.0;
545: 
546: 					vec3 uvw_pos = vec3(local_pos_bottom / colliders[i].extents.xyz) * 0.5 + 0.5;
547: 
548: 					float y = 1.0 - texture(height_field_texture, uvw_pos.xz).r;
549: 
550: 					if (y > uvw_pos.y) {
551: 						//inside heightfield
552: 
553: 						vec3 pos1 = (vec3(uvw_pos.x, y, uvw_pos.z) * 2.0 - 1.0) * colliders[i].extents.xyz;
554: 						vec3 pos2 = (vec3(uvw_pos.x + DELTA, 1.0 - texture(height_field_texture, uvw_pos.xz + vec2(DELTA, 0)).r, uvw_pos.z) * 2.0 - 1.0) * colliders[i].extents.xyz;
555: 						vec3 pos3 = (vec3(uvw_pos.x, 1.0 - texture(height_field_texture, uvw_pos.xz + vec2(0, DELTA)).r, uvw_pos.z + DELTA) * 2.0 - 1.0) * colliders[i].extents.xyz;
556: 
557: 						normal = normalize(cross(pos1 - pos2, pos1 - pos3));
558: 						float local_y = (vec3(local_pos / colliders[i].extents.xyz) * 0.5 + 0.5).y;
559: 
560: 						col = true;
561: 						depth = dot(normal, pos1) - dot(normal, local_pos_bottom);
562: 					}
563: 				}
564: 
565: 				if (col) {
566: 					if (!collided) {
567: 						collided = true;
568: 						collision_normal = normal;
569: 						collision_depth = depth;
570: 					} else {
571: 						vec3 c = collision_normal * collision_depth;
572: 						c += normal * max(0.0, depth - dot(normal, c));
573: 						collision_normal = normalize(c);
574: 						collision_depth = length(c);
575: 					}
576: 				}
577: 			}
578: 		}
579: 	}
580: 
581: 	if (particle_active) {
582: 	{
583: 		uint m_base_number=particle_number;
584: 		uint m_alt_seed=m_hash(((m_base_number + 1u) + random_seed));
585: 		float m_angle_rand=m_rand_from_seed(m_alt_seed);
586: 		float m_scale_rand=m_rand_from_seed(m_alt_seed);
587: 		float m_hue_rot_rand=m_rand_from_seed(m_alt_seed);
588: 		float m_anim_offset_rand=m_rand_from_seed(m_alt_seed);
589: 		float m_pi=3.14159;
590: 		float m_degree_to_rad=(m_pi / 180.0);
591: 		out_custom.y+=(local_delta / lifetime);
592: 		float m_tv=(out_custom.y / out_custom.w);
593: 		float m_tex_linear_velocity=1.0;
594: 		float m_tex_orbit_velocity=1.0;
595: 		float m_tex_angular_velocity=1.0;
596: 		float m_tex_linear_accel=1.0;
597: 		float m_tex_radial_accel=1.0;
598: 		float m_tex_tangent_accel=1.0;
599: 		float m_tex_damping=1.0;
600: 		float m_tex_angle=1.0;
601: 		float m_tex_anim_speed=1.0;
602: 		float m_tex_anim_offset=1.0;
603: 		vec3 m_force=m_gravity;
604: 		vec3 m_pos=xform[3].xyz;
605: 		m_pos.z=0.0;
606: 		m_force+=((length(out_velocity_flags.xyz) > 0.0)?((normalize(out_velocity_flags.xyz) * m_tex_linear_accel) * mix(m_linear_accel_min, m_linear_accel_max, m_rand_from_seed(m_alt_seed))):vec3(0.0,0.0,0.0));
607: 		vec3 m_org=emission_transform[3].xyz;
608: 		vec3 m_diff=(m_pos - m_org);
609: 		m_force+=((length(m_diff) > 0.0)?((normalize(m_diff) * m_tex_radial_accel) * mix(m_radial_accel_min, m_radial_accel_max, m_rand_from_seed(m_alt_seed))):vec3(0.0,0.0,0.0));
610: 		float m_tangent_accel_val=(m_tex_tangent_accel * mix(m_tangent_accel_min, m_tangent_accel_max, m_rand_from_seed(m_alt_seed)));
611: 		m_force+=((length(m_diff.yx) > 0.0)?(vec3(normalize((m_diff.yx * vec2(-1.0,1.0))), 0.0) * m_tangent_accel_val):vec3(0.0,0.0,0.0));
612: 		m_force+=attractor_force;
613: 		out_velocity_flags.xyz+=(m_force * local_delta);
614: 		float m_orbit_amount=(m_tex_orbit_velocity * mix(m_orbit_velocity_min, m_orbit_velocity_max, m_rand_from_seed(m_alt_seed)));
615: 		if ((m_orbit_amount != 0.0))
616: 		{
617: 					{
618: 			float m_ang=(((m_orbit_amount * local_delta) * m_pi) * 2.0);
619: 			mat2 m_rot=mat2(vec2(cos(m_ang), -sin(m_ang)), vec2(sin(m_ang), cos(m_ang)));
620: 			xform[3].xy-=m_diff.xy;
621: 			xform[3].xy+=(m_rot * m_diff.xy);
622: 		}
623: ;
624: 		}
625: 		float m_dmp=mix(m_damping_min, m_damping_max, m_rand_from_seed(m_alt_seed));
626: 		if (((m_dmp * m_tex_damping) > 0.0))
627: 		{
628: 					{
629: 			float m_v=length(out_velocity_flags.xyz);
630: 			float m_damp=(m_tex_damping * m_dmp);
631: 			m_v-=(m_damp * local_delta);
632: 			if ((m_v < 0.0))
633: 			{
634: 							{
635: 				out_velocity_flags.xyz=vec3(0.0,0.0,0.0);
636: 			}
637: ;
638: 			}
639: 			else
640: 			{
641: 							{
642: 				out_velocity_flags.xyz=(normalize(out_velocity_flags.xyz) * m_v);
643: 			}
644: ;
645: 			}
646: 		}
647: ;
648: 		}
649: 		float m_base_angle=(m_tex_angle * mix(m_initial_angle_min, m_initial_angle_max, m_angle_rand));
650: 		m_base_angle+=(((out_custom.y * lifetime) * m_tex_angular_velocity) * mix(m_angular_velocity_min, m_angular_velocity_max, m_rand_from_seed(m_alt_seed)));
651: 		out_custom.x=(m_base_angle * m_degree_to_rad);
652: 		out_custom.z=((m_tex_anim_offset * mix(m_anim_offset_min, m_anim_offset_max, m_rand_from_seed(m_alt_seed))) + ((m_tv * m_tex_anim_speed) * mix(m_anim_speed_min, m_anim_speed_max, m_rand_from_seed(m_alt_seed))));
653: 		vec3 m_tex_scale=vec3(1.0,1.0,1.0);
654: 		float m_tex_hue_variation=1.0;
655: 		float m_hue_rot_angle=(((m_tex_hue_variation * m_pi) * 2.0) * mix(m_hue_variation_min, m_hue_variation_max, m_rand_from_seed(m_alt_seed)));
656: 		float m_hue_rot_c=cos(m_hue_rot_angle);
657: 		float m_hue_rot_s=sin(m_hue_rot_angle);
658: 		mat4 m_hue_rot_mat=((mat4(0.299,0.587,0.114,0.0,0.299,0.587,0.114,0.0,0.299,0.587,0.114,0.0,0.0,0.0,0.0,1.0) + (mat4(0.701,-0.587,-0.114,0.0,-0.299,0.413,-0.114,0.0,-0.3,-0.588,0.886,0.0,0.0,0.0,0.0,0.0) * m_hue_rot_c)) + (mat4(0.168,0.33,-0.497,0.0,-0.328,0.035,0.292,0.0,1.25,-1.05,-0.203,0.0,0.0,0.0,0.0,0.0) * m_hue_rot_s));
659: 		out_color=(m_hue_rot_mat * m_color_value);
660: 		xform[0]=vec4(cos(out_custom.x), -sin(out_custom.x), 0.0, 0.0);
661: 		xform[1]=vec4(sin(out_custom.x), cos(out_custom.x), 0.0, 0.0);
662: 		xform[2]=vec4(0.0,0.0,1.0,0.0);
663: 		xform[3].z=0.0;
664: 		float m_base_scale=mix(m_scale_min, m_scale_max, m_scale_rand);
665: 		m_base_scale=(sign(m_base_scale) * max(abs(m_base_scale), 0.001));
666: 		xform[0].xyz*=((m_base_scale * sign(m_tex_scale.r)) * max(abs(m_tex_scale.r), 0.001));
667: 		xform[1].xyz*=((m_base_scale * sign(m_tex_scale.g)) * max(abs(m_tex_scale.g), 0.001));
668: 		xform[2].xyz*=((m_base_scale * sign(m_tex_scale.b)) * max(abs(m_tex_scale.b), 0.001));
669: 		int m_emit_count=0;
670: 		float m_unit_delta=(local_delta / lifetime);
671: 		float m_end_time=(out_custom.w * 0.95);
672: 		if (((out_custom.y < m_end_time) && ((out_custom.y + m_unit_delta) >= m_end_time)))
673: 		{
674: 			m_emit_count=m_sub_emitter_amount_at_end;
675: 		}
676: 		for (int m_i=0;(m_i < m_emit_count);m_i++)
677: 		{
678: 					{
679: 			uint m_flags=(EMISSION_FLAG_HAS_POSITION | EMISSION_FLAG_HAS_ROTATION_SCALE);
680: 			if (m_sub_emitter_keep_velocity)
681: 			{
682: 				m_flags|=EMISSION_FLAG_HAS_VELOCITY;
683: 			}
684: 			emit_subparticle(xform, out_velocity_flags.xyz, vec4(0.0,0.0,0.0,0.0), vec4(0.0,0.0,0.0,0.0), m_flags);
685: 		}
686: ;
687: 		}
688: 		if ((out_custom.y > out_custom.w))
689: 		{
690: 					{
691: 			particle_active=false;
692: 		}
693: ;
694: 		}
695: 	}
696: 	}
697: 
698: 	flags &= ~PARTICLE_FLAG_ACTIVE;
699: 	if (particle_active) {
700: 		flags |= PARTICLE_FLAG_ACTIVE;
701: 	}
702: 
703: 	xform = transpose(xform);
704: 	out_xform_1 = xform[0];
705: 	out_xform_2 = xform[1];
706: #ifdef MODE_3D
707: 	out_xform_3 = xform[2];
708: #endif
709: 	out_velocity_flags.w = uintBitsToFloat(flags);
710: }
711: 
712: /* clang-format off */
713: 
714: 
```
</Details>

### Steps to reproduce

- Create two GPUParticles2D Effect1 and Effect2
- Set Effect1 Amount to 24
- Set Effect1 Sub Emitter to Effect2
- Set Effect1 Process Material to a new ParticleProcessMaterial
- Set Effect1 Process Material to use emission  shape Sphere
- Set Effect1 Gravity to 0, 98, 0
- Set Effect1 Animation SpeedMin to 7
- Set Effect1 Animation SpeedMax to 7
- Set Effect1 Sub Emitter to Mode => AtEnd
- Set Effect1 Amount at end to 2
- Set Effect1 Texture to a  7 frame 8x8 animation
- Set Effect1 Lifetime to 2
- Set Effect1 Oneshot to true
- Set Effect1 Material to a new CanvasItemMaterial
- Set Effect1 Material to use Particle Animation
- Set Effect1 Anim H Frames to 7
--------------------------------
- Set Effect2 Amount to 1
- Set Effect2 Process Material to a new ParticleProcessMaterial
- Set Effect2 Gravity to 0, -64, 0
- Set Effect2 Animation SpeedMin to 5
- Set Effect2 Animation SpeedMax to 5
- Set Effect2 Texture to a  5 frame 8x8 animation
- Set Effect2 Lifetime to 4
- Set Effect2 Oneshot to true
- Set Effect2 Material to a new CanvasItemMaterial
- Set Effect2 Material to use Particle Animation
- Set Effect2 Anim H Frames to 5
------------------------------
- Now enable Effect1 Emitting

### Minimal reproduction project

[SubEmiiterBug.zip](https://github.com/godotengine/godot/files/11804736/SubEmiiterBug.zip)

int h = img->get_height();
	int tsize = 0;
	for (int i = 0; i < mipmaps; i++) {
		int size, ofs;
		img->get_mipmap_offset_and_size(i, ofs, size);
		if (compressed) {
			glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
			int bw = w;
			int bh = h;
			glCompressedTexImage2D(blit_target, i, internal_format, bw, bh, 0, size, &read[ofs]);
		} else {
			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
			if (texture->target == GL_TEXTURE_2D_ARRAY) {
				if (initialize) {
					glTexImage3D(GL_TEXTURE_2D_ARRAY, i, internal_format, w, h, texture->layers, 0, format, type, nullptr);
				}
				glTexSubImage3D(GL_TEXTURE_2D_ARRAY, i, 0, 0, p_layer, w, h, 1, format, type, &read[ofs]);
			} else {
				glTexImage2D(blit_target, i, internal_format, w, h, 0, format, type, &read[ofs]);
			}
		}
		tsize += size;
		w = MAX(1, w >> 1);
		h = MAX(1, h >> 1);
	}
	texture->total_data_size = tsize;
	texture->stored_cube_sides |= (1 << p_layer);
	texture->mipmaps = mipmaps;
}
Image::Format TextureStorage::texture_get_format(RID p_texture) const {