Random output of an entire engine script

4.3

Suddenly I got this beast as an output while loading a level, happened two times in a row, now I can’t reproduce it. Does someone know why?

–Main Shader–
1 | // NOTE: Shader automatically converted from Godot Engine 4.3.stable’s ParticleProcessMaterial.
2 |
3 | shader_type particles;
4 | render_mode disable_velocity;
5 |
6 | uniform vec3 direction;
7 | uniform float spread;
8 | uniform float flatness;
9 | uniform float inherit_emitter_velocity_ratio = 0.0;
10 | uniform float initial_linear_velocity_min;
11 | uniform float initial_linear_velocity_max;
12 | uniform float directional_velocity_min;
13 | uniform float directional_velocity_max;
14 | uniform float angular_velocity_min;
15 | uniform float angular_velocity_max;
16 | uniform float orbit_velocity_min;
17 | uniform float orbit_velocity_max;
18 | uniform float radial_velocity_min;
19 | uniform float radial_velocity_max;
20 | uniform float linear_accel_min;
21 | uniform float linear_accel_max;
22 | uniform float radial_accel_min;
23 | uniform float radial_accel_max;
24 | uniform float tangent_accel_min;
25 | uniform float tangent_accel_max;
26 | uniform float damping_min;
27 | uniform float damping_max;
28 | uniform float initial_angle_min;
29 | uniform float initial_angle_max;
30 | uniform float scale_min;
31 | uniform float scale_max;
32 | uniform float hue_variation_min;
33 | uniform float hue_variation_max;
34 | uniform float anim_speed_min;
35 | uniform float anim_speed_max;
36 | uniform float anim_offset_min;
37 | uniform float anim_offset_max;
38 | uniform float lifetime_randomness;
39 | uniform vec3 emission_shape_offset = vec3(0.0);
40 | uniform vec3 emission_shape_scale = vec3(1.0);
41 | uniform vec3 velocity_pivot = vec3(0.0);
42 | uniform vec4 color_value : source_color;
43 | uniform vec3 gravity;
44 |
45 | vec4 rotate_hue(vec4 current_color, float hue_rot_angle) {
46 | float hue_rot_c = cos(hue_rot_angle);
47 | float hue_rot_s = sin(hue_rot_angle);
48 | mat4 hue_rot_mat =
49 | mat4(vec4(0.299, 0.587, 0.114, 0.0),
50 | vec4(0.299, 0.587, 0.114, 0.0),
51 | vec4(0.299, 0.587, 0.114, 0.0),
52 | vec4(0.000, 0.000, 0.000, 1.0)) +
53 | mat4(vec4(0.701, -0.587, -0.114, 0.0),
54 | vec4(-0.299, 0.413, -0.114, 0.0),
55 | vec4(-0.300, -0.588, 0.886, 0.0),
56 | vec4(0.000, 0.000, 0.000, 0.0)) *
57 | hue_rot_c +
58 | mat4(vec4(0.168, 0.330, -0.497, 0.0),
59 | vec4(-0.328, 0.035, 0.292, 0.0),
60 | vec4(1.250, -1.050, -0.203, 0.0),
61 | vec4(0.000, 0.000, 0.000, 0.0)) *
62 | hue_rot_s;
63 | return hue_rot_mat * current_color;
64 | }
65 |
66 | float rand_from_seed(inout uint seed) {
67 | int k;
68 | int s = int(seed);
69 | if (s == 0) {
70 | s = 305420679;
71 | }
72 | k = s / 127773;
73 | s = 16807 * (s - k * 127773) - 2836 * k;
74 | if (s < 0) {
75 | s += 2147483647;
76 | }
77 | seed = uint(s);
78 | return float(seed % uint(65536)) / 65535.0;
79 | }
80 |
81 | float rand_from_seed_m1_p1(inout uint seed) {
82 | return rand_from_seed(seed) * 2.0 - 1.0;
83 | }
84 |
85 | uint hash(uint x) {
86 | x = ((x >> uint(16)) ^ x) * uint(73244475);
87 | x = ((x >> uint(16)) ^ x) * uint(73244475);
88 | x = (x >> uint(16)) ^ x;
89 | return x;
90 | }
91 |
92 | struct DisplayParameters {
93 | vec3 scale;
94 | float hue_rotation;
95 | float animation_speed;
96 | float animation_offset;
97 | float lifetime;
98 | vec4 color;
99 | };
100 |
101 | struct DynamicsParameters {
102 | float angle;
103 | float angular_velocity;
104 | float initial_velocity_multiplier;
105 | float directional_velocity;
106 | float radial_velocity;
107 | float orbit_velocity;
108 | };
109 |
110 | struct PhysicalParameters {
111 | float linear_accel;
112 | float radial_accel;
113 | float tangent_accel;
114 | float damping;
115 | };
116 |
117 | void calculate_initial_physical_params(inout PhysicalParameters params, inout uint alt_seed) {
118 | params.linear_accel = mix(linear_accel_min, linear_accel_max, rand_from_seed(alt_seed));
119 | params.radial_accel = mix(radial_accel_min, radial_accel_max, rand_from_seed(alt_seed));
120 | params.tangent_accel = mix(tangent_accel_min, tangent_accel_max, rand_from_seed(alt_seed));
121 | params.damping = mix(damping_min, damping_max, rand_from_seed(alt_seed));
122 | }
123 |
124 | void calculate_initial_dynamics_params(inout DynamicsParameters params, inout uint alt_seed) {
125 | // -------------------- DO NOT REORDER OPERATIONS, IT BREAKS VISUAL COMPATIBILITY
126 | // -------------------- ADD NEW OPERATIONS AT THE BOTTOM
127 | params.angle = mix(initial_angle_min, initial_angle_max, rand_from_seed(alt_seed));
128 | params.angular_velocity = mix(angular_velocity_min, angular_velocity_max, rand_from_seed(alt_seed));
129 | params.initial_velocity_multiplier = mix(initial_linear_velocity_min, initial_linear_velocity_max, rand_from_seed(alt_seed));
130 | params.directional_velocity = mix(directional_velocity_min, directional_velocity_max, rand_from_seed(alt_seed));
131 | params.radial_velocity = mix(radial_velocity_min, radial_velocity_max, rand_from_seed(alt_seed));
132 | params.orbit_velocity = mix(orbit_velocity_min, orbit_velocity_max, rand_from_seed(alt_seed));
133 | }
134 |
135 | void calculate_initial_display_params(inout DisplayParameters params, inout uint alt_seed) {
136 | // -------------------- DO NOT REORDER OPERATIONS, IT BREAKS VISUAL COMPATIBILITY
137 | // -------------------- ADD NEW OPERATIONS AT THE BOTTOM
138 | float pi = 3.14159;
139 | params.scale = vec3(mix(scale_min, scale_max, rand_from_seed(alt_seed)));
140 | params.scale = sign(params.scale) * max(abs(params.scale), 0.001);
141 | params.hue_rotation = pi * 2.0 * mix(hue_variation_min, hue_variation_max, rand_from_seed(alt_seed));
142 | params.animation_speed = mix(anim_speed_min, anim_speed_max, rand_from_seed(alt_seed));
143 | params.animation_offset = mix(anim_offset_min, anim_offset_max, rand_from_seed(alt_seed));
144 | params.lifetime = (1.0 - lifetime_randomness * rand_from_seed(alt_seed));
145 | params.color = color_value;
146 | }
147 |
148 | void process_display_param(inout DisplayParameters parameters, float lifetime) {
149 | // Compile-time add textures.
150 | parameters.color = rotate_hue(parameters.color, parameters.hue_rotation);
151 | }
152 |
153 | vec3 calculate_initial_position(inout uint alt_seed) {
154 | float pi = 3.14159;
155 | vec3 pos = vec3(0.0);
156 | { // Emission shape.
157 | pos = vec3(0.0);
158 | }
159 | return pos * emission_shape_scale + emission_shape_offset;
160 | }
161 |
162 | vec3 get_random_direction_from_spread(inout uint alt_seed, float spread_angle) {
163 | float pi = 3.14159;
164 | float degree_to_rad = pi / 180.0;
165 | float spread_rad = spread_angle * degree_to_rad;
166 | float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;
167 | float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);
168 | vec3 direction_xz = vec3(sin(angle1_rad), 0.0, cos(angle1_rad));
169 | vec3 direction_yz = vec3(0.0, sin(angle2_rad), cos(angle2_rad));
170 | direction_yz.z = direction_yz.z / max(0.0001, sqrt(abs(direction_yz.z))); // Better uniform distribution.
171 | vec3 spread_direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);
172 | vec3 direction_nrm = length(direction) > 0.0 ? normalize(direction) : vec3(0.0, 0.0, 1.0);
173 | // Rotate spread to direction.
174 | vec3 binormal = cross(vec3(0.0, 1.0, 0.0), direction_nrm);
175 | if (length(binormal) < 0.0001) {
176 | // Direction is parallel to Y. Choose Z as the binormal.
177 | binormal = vec3(0.0, 0.0, 1.0);
178 | }
179 | binormal = normalize(binormal);
180 | vec3 normal = cross(binormal, direction_nrm);
181 | spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;
182 | return normalize(spread_direction);
183 | }
184 |
185 | vec3 process_radial_displacement(DynamicsParameters param, float lifetime, inout uint alt_seed, mat4 transform, mat4 emission_transform, float delta) {
186 | vec3 radial_displacement = vec3(0.0);
187 | if (delta < 0.001) {
188 | return radial_displacement;
189 | }
190 | float radial_displacement_multiplier = 1.0;
191 | vec3 global_pivot = (emission_transform * vec4(velocity_pivot, 1.0)).xyz;
192 | if (length(transform[3].xyz - global_pivot) > 0.01) {
193 | radial_displacement = normalize(transform[3].xyz - global_pivot) * radial_displacement_multiplier * param.radial_velocity;
194 | } else {
195 | radial_displacement = get_random_direction_from_spread(alt_seed, 360.0) * param.radial_velocity;
196 | }
197 | if (radial_displacement_multiplier * param.radial_velocity < 0.0) {
198 | // Prevent inwards velocity to flicker once the point is reached.
199 | radial_displacement = normalize(radial_displacement) * min(abs(radial_displacement_multiplier * param.radial_velocity), length(transform[3].xyz - global_pivot) / delta);
200 | }
201 | return radial_displacement;
202 | }
203 |
204 | void process_physical_parameters(inout PhysicalParameters params, float lifetime_percent) {
205 | }
206 |
207 | void start() {
208 | uint base_number = NUMBER;
209 | uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);
210 | DisplayParameters params;
211 | calculate_initial_display_params(params, alt_seed);
212 | // Reset alt seed?
213 | //alt_seed = hash(base_number + uint(1) + RANDOM_SEED);
214 | DynamicsParameters dynamic_params;
215 | calculate_initial_dynamics_params(dynamic_params, alt_seed);
216 | PhysicalParameters physics_params;
217 | calculate_initial_physical_params(physics_params, alt_seed);
218 | process_display_param(params, 0.0);
219 | if (rand_from_seed(alt_seed) > AMOUNT_RATIO) {
220 | ACTIVE = false;
221 | }
222 |
223 | if (RESTART_CUSTOM) {
224 | CUSTOM = vec4(0.0);
225 | CUSTOM.w = params.lifetime;
226 | CUSTOM.x = dynamic_params.angle;
227 | }
228 | if (RESTART_COLOR) {
229 | COLOR = params.color;
230 | }
231 | if (RESTART_ROT_SCALE) {
232 | TRANSFORM[0].xyz = vec3(1.0, 0.0, 0.0);
233 | TRANSFORM[1].xyz = vec3(0.0, 1.0, 0.0);
234 | TRANSFORM[2].xyz = vec3(0.0, 0.0, 1.0);
235 | }
236 | if (RESTART_POSITION) {
237 | TRANSFORM[3].xyz = calculate_initial_position(alt_seed);
238 | TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;
239 | }
240 | if (RESTART_VELOCITY) {
241 | VELOCITY = get_random_direction_from_spread(alt_seed, spread) * dynamic_params.initial_velocity_multiplier;
242 | }
243 |
244 | process_display_param(params, 0.0);
245 |
246 | VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;
247 | VELOCITY += EMITTER_VELOCITY * inherit_emitter_velocity_ratio;
248 | }
249 |
250 | void process() {
251 | uint base_number = NUMBER;
252 | //if (repeatable) {
253 | // base_number = INDEX;
254 | //}
255 | uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);
256 | DisplayParameters params;
257 | calculate_initial_display_params(params, alt_seed);
258 | DynamicsParameters dynamic_params;
259 | calculate_initial_dynamics_params(dynamic_params, alt_seed);
260 | PhysicalParameters physics_params;
261 | calculate_initial_physical_params(physics_params, alt_seed);
262 |
263 | float pi = 3.14159;
264 | float degree_to_rad = pi / 180.0;
265 |
266 | CUSTOM.y += DELTA / LIFETIME;
267 | CUSTOM.y = mix(CUSTOM.y, 1.0, INTERPOLATE_TO_END);
268 | float lifetime_percent = CUSTOM.y / params.lifetime;
269 | if (CUSTOM.y > CUSTOM.w) {
270 | ACTIVE = false;
271 | }
272 |
273 | // Calculate all velocity.
274 | vec3 controlled_displacement = vec3(0.0);
E 275-> controlled_displacement += process_orbit_displacement(dynamic_params, lifetime_percent, alt_seed, TRANSFORM, EMISSION_TRANSFORM, DELTA, params.lifetime * LIFETIME);
276 | controlled_displacement += process_radial_displacement(dynamic_params, lifetime_percent, alt_seed, TRANSFORM, EMISSION_TRANSFORM, DELTA);
277 |
278 | process_physical_parameters(physics_params, lifetime_percent);
279 | vec3 force;
280 | {
281 | // Copied from previous version.
282 | vec3 pos = TRANSFORM[3].xyz;
283 | force = gravity;
284 | // Apply linear acceleration.
285 | force += length(VELOCITY) > 0.0 ? normalize(VELOCITY) * physics_params.linear_accel : vec3(0.0);
286 | // Apply radial acceleration.
287 | vec3 org = EMISSION_TRANSFORM[3].xyz;
288 | vec3 diff = pos - org;
289 | force += length(diff) > 0.0 ? normalize(diff) * physics_params.radial_accel : vec3(0.0);
290 | // Apply tangential acceleration.
291 | float tangent_accel_val = physics_params.tangent_accel;
292 | vec3 crossDiff = cross(normalize(diff), normalize(gravity));
293 | force += length(crossDiff) > 0.0 ? normalize(crossDiff) * tangent_accel_val : vec3(0.0);
294 | // Apply attractor forces.
295 | VELOCITY += force * DELTA;
296 | }
297 | {
298 | // Copied from previous version.
299 | if (physics_params.damping > 0.0) {
300 | float v = length(VELOCITY);
301 | v -= physics_params.damping * DELTA;
302 | if (v < 0.0) {
303 | VELOCITY = vec3(0.0);
304 | } else {
305 | VELOCITY = normalize(VELOCITY) * v;
306 | }
307 | }
308 | }
309 |
310 | // Turbulence before limiting.
311 | vec3 final_velocity = controlled_displacement + VELOCITY;
312 |
313 | TRANSFORM[3].xyz += final_velocity * DELTA;
314 |
315 | process_display_param(params, lifetime_percent);
316 |
317 | float base_angle = dynamic_params.angle;
318 | base_angle += CUSTOM.y * LIFETIME * dynamic_params.angular_velocity;
319 | CUSTOM.x = base_angle * degree_to_rad;
320 | COLOR = params.color;
321 |
322 | TRANSFORM[0].xyz = normalize(TRANSFORM[0].xyz);
323 | TRANSFORM[1].xyz = normalize(TRANSFORM[1].xyz);
324 | TRANSFORM[2].xyz = normalize(TRANSFORM[2].xyz);
325 | TRANSFORM[0].xyz *= sign(params.scale.x) * max(abs(params.scale.x), 0.001);
326 | TRANSFORM[1].xyz *= sign(params.scale.y) * max(abs(params.scale.y), 0.001);
327 | TRANSFORM[2].xyz *= sign(params.scale.z) * max(abs(params.scale.z), 0.001);
328 |
329 | CUSTOM.z = params.animation_offset + lifetime_percent * params.animation_speed;
330 |
331 | if (CUSTOM.y > CUSTOM.w) {
332 | ACTIVE = false;
333 | }
334 | }
335 |