godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.45k stars 21.27k forks source link

Unknown identifier in expression: scale_texture #64993

Open and3rson opened 2 years ago

and3rson commented 2 years ago

Godot version

3.5.stable

System information

ArchLinux

Issue description

Every time when I run the project first time after reopening Godot, the following error is printed:

``` 1 | // NOTE: Shader automatically converted from Godot Engine 3.5.stable's ParticlesMaterial. 2 | 3 | shader_type particles; 4 | uniform vec3 direction; 5 | uniform float spread; 6 | uniform float flatness; 7 | uniform float initial_linear_velocity; 8 | uniform float initial_angle; 9 | uniform float angular_velocity; 10 | uniform float orbit_velocity; 11 | uniform float linear_accel; 12 | uniform float radial_accel; 13 | uniform float tangent_accel; 14 | uniform float damping; 15 | uniform float scale; 16 | uniform float hue_variation; 17 | uniform float anim_speed; 18 | uniform float anim_offset; 19 | uniform float initial_linear_velocity_random; 20 | uniform float initial_angle_random; 21 | uniform float angular_velocity_random; 22 | uniform float orbit_velocity_random; 23 | uniform float linear_accel_random; 24 | uniform float radial_accel_random; 25 | uniform float tangent_accel_random; 26 | uniform float damping_random; 27 | uniform float scale_random; 28 | uniform float hue_variation_random; 29 | uniform float anim_speed_random; 30 | uniform float anim_offset_random; 31 | uniform float lifetime_randomness; 32 | uniform vec4 color_value : hint_color; 33 | uniform int trail_divisor; 34 | uniform vec3 gravity; 35 | 36 | 37 | float rand_from_seed(inout uint seed) { 38 | int k; 39 | int s = int(seed); 40 | if (s == 0) 41 | s = 305420679; 42 | k = s / 127773; 43 | s = 16807 * (s - k * 127773) - 2836 * k; 44 | if (s < 0) 45 | s += 2147483647; 46 | seed = uint(s); 47 | return float(seed % uint(65536)) / 65535.0; 48 | } 49 | 50 | float rand_from_seed_m1_p1(inout uint seed) { 51 | return rand_from_seed(seed) * 2.0 - 1.0; 52 | } 53 | 54 | uint hash(uint x) { 55 | x = ((x >> uint(16)) ^ x) * uint(73244475); 56 | x = ((x >> uint(16)) ^ x) * uint(73244475); 57 | x = (x >> uint(16)) ^ x; 58 | return x; 59 | } 60 | 61 | void vertex() { 62 | uint base_number = NUMBER / uint(trail_divisor); 63 | uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED); 64 | float angle_rand = rand_from_seed(alt_seed); 65 | float scale_rand = rand_from_seed(alt_seed); 66 | float hue_rot_rand = rand_from_seed(alt_seed); 67 | float anim_offset_rand = rand_from_seed(alt_seed); 68 | float pi = 3.14159; 69 | float degree_to_rad = pi / 180.0; 70 | 71 | bool restart = false; 72 | float tv = 0.0; 73 | if (CUSTOM.y > CUSTOM.w) { 74 | restart = true; 75 | tv = 1.0; 76 | } 77 | 78 | if (RESTART || restart) { 79 | uint alt_restart_seed = hash(base_number + uint(301184) + RANDOM_SEED); 80 | float tex_linear_velocity = 0.0; 81 | float tex_angle = 0.0; 82 | float tex_anim_offset = 0.0; 83 | float spread_rad = spread * degree_to_rad; 84 | { 85 | float angle1_rad = rand_from_seed_m1_p1(alt_restart_seed) * spread_rad; 86 | angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0); 87 | vec3 rot = vec3(cos(angle1_rad), sin(angle1_rad), 0.0); 88 | VELOCITY = rot * initial_linear_velocity * mix(1.0, rand_from_seed(alt_restart_seed), initial_linear_velocity_random); 89 | } 90 | float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random); 91 | CUSTOM.x = base_angle * degree_to_rad; 92 | CUSTOM.y = 0.0; 93 | CUSTOM.w = (1.0 - lifetime_randomness * rand_from_seed(alt_restart_seed)); 94 | CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random); 95 | VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz; 96 | TRANSFORM = EMISSION_TRANSFORM * TRANSFORM; 97 | VELOCITY.z = 0.0; 98 | TRANSFORM[3].z = 0.0; 99 | } else { 100 | CUSTOM.y += DELTA / LIFETIME; 101 | tv = CUSTOM.y / CUSTOM.w; 102 | float tex_linear_velocity = 0.0; 103 | float tex_orbit_velocity = 0.0; 104 | float tex_angular_velocity = 0.0; 105 | float tex_linear_accel = 0.0; 106 | float tex_radial_accel = 0.0; 107 | float tex_tangent_accel = 0.0; 108 | float tex_damping = 0.0; 109 | float tex_angle = 0.0; 110 | float tex_anim_speed = 0.0; 111 | float tex_anim_offset = 0.0; 112 | vec3 force = gravity; 113 | vec3 pos = TRANSFORM[3].xyz; 114 | pos.z = 0.0; 115 | // apply linear acceleration 116 | force += length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel + tex_linear_accel) * mix(1.0, rand_from_seed(alt_seed), linear_accel_random) : vec3(0.0); 117 | // apply radial acceleration 118 | vec3 org = EMISSION_TRANSFORM[3].xyz; 119 | vec3 diff = pos - org; 120 | force += length(diff) > 0.0 ? normalize(diff) * (radial_accel + tex_radial_accel) * mix(1.0, rand_from_seed(alt_seed), radial_accel_random) : vec3(0.0); 121 | // apply tangential acceleration; 122 | force += length(diff.yx) > 0.0 ? vec3(normalize(diff.yx * vec2(-1.0, 1.0)), 0.0) * ((tangent_accel + tex_tangent_accel) * mix(1.0, rand_from_seed(alt_seed), tangent_accel_random)) : vec3(0.0); 123 | // apply attractor forces 124 | VELOCITY += force * DELTA; 125 | // orbit velocity 126 | float orbit_amount = (orbit_velocity + tex_orbit_velocity) * mix(1.0, rand_from_seed(alt_seed), orbit_velocity_random); 127 | if (orbit_amount != 0.0) { 128 | float ang = orbit_amount * DELTA * pi * 2.0; 129 | mat2 rot = mat2(vec2(cos(ang), -sin(ang)), vec2(sin(ang), cos(ang))); 130 | TRANSFORM[3].xy -= diff.xy; 131 | TRANSFORM[3].xy += rot * diff.xy; 132 | } 133 | if (damping + tex_damping > 0.0) { 134 | float v = length(VELOCITY); 135 | float damp = (damping + tex_damping) * mix(1.0, rand_from_seed(alt_seed), damping_random); 136 | v -= damp * DELTA; 137 | if (v < 0.0) { 138 | VELOCITY = vec3(0.0); 139 | } else { 140 | VELOCITY = normalize(VELOCITY) * v; 141 | } 142 | } 143 | float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random); 144 | base_angle += CUSTOM.y * LIFETIME * (angular_velocity + tex_angular_velocity) * mix(1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, angular_velocity_random); 145 | CUSTOM.x = base_angle * degree_to_rad; 146 | CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random) + tv * (anim_speed + tex_anim_speed) * mix(1.0, rand_from_seed(alt_seed), anim_speed_random); 147 | } E 148-> float tex_scale = textureLod(scale_texture, vec2(tv, 0.0), 0.0).r; 149 | float tex_hue_variation = 0.0; 150 | float hue_rot_angle = (hue_variation + tex_hue_variation) * pi * 2.0 * mix(1.0, hue_rot_rand * 2.0 - 1.0, hue_variation_random); 151 | float hue_rot_c = cos(hue_rot_angle); 152 | float hue_rot_s = sin(hue_rot_angle); 153 | mat4 hue_rot_mat = mat4(vec4(0.299, 0.587, 0.114, 0.0), 154 | vec4(0.299, 0.587, 0.114, 0.0), 155 | vec4(0.299, 0.587, 0.114, 0.0), 156 | vec4(0.000, 0.000, 0.000, 1.0)) + 157 | mat4(vec4(0.701, -0.587, -0.114, 0.0), 158 | vec4(-0.299, 0.413, -0.114, 0.0), 159 | vec4(-0.300, -0.588, 0.886, 0.0), 160 | vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_c + 161 | mat4(vec4(0.168, 0.330, -0.497, 0.0), 162 | vec4(-0.328, 0.035, 0.292, 0.0), 163 | vec4(1.250, -1.050, -0.203, 0.0), 164 | vec4(0.000, 0.000, 0.000, 0.0)) * hue_rot_s; 165 | COLOR = hue_rot_mat * color_value; 166 | 167 | TRANSFORM[0] = vec4(cos(CUSTOM.x), -sin(CUSTOM.x), 0.0, 0.0); 168 | TRANSFORM[1] = vec4(sin(CUSTOM.x), cos(CUSTOM.x), 0.0, 0.0); 169 | TRANSFORM[2] = vec4(0.0, 0.0, 1.0, 0.0); 170 | float base_scale = tex_scale * mix(scale, 1.0, scale_random * scale_rand); 171 | if (base_scale < 0.000001) { 172 | base_scale = 0.000001; 173 | } 174 | TRANSFORM[0].xyz *= base_scale; 175 | TRANSFORM[1].xyz *= base_scale; 176 | TRANSFORM[2].xyz *= base_scale; 177 | VELOCITY.z = 0.0; 178 | TRANSFORM[3].z = 0.0; 179 | if (CUSTOM.y > CUSTOM.w) { ACTIVE = false; 180 | } 181 | } 182 | 183 | SHADER ERROR: Unknown identifier in expression: scale_texture at: (null) (:148) ```

Steps to reproduce

I'm not sure how to reproduce this since the project is pretty big and no information about shader location is printed.

I've grepped my entire project and there's not a single mention of scale_texture.

I'll need some pointers in order to be able to reproduce this.

Update: just found the relevant lines in Godot sources:

It seems like return value from tex_parameters[PARAM_SCALE].is_valid() is different throughout the ParticlesMaterial::_update_shader function.

Update 2: this happens only when running the project. I've opened every scene that contains particles in editor and did not get the error.

Update 3: I can no longer reproduce this issue...

Minimal reproduction project

No response

Calinou commented 2 years ago

Update 3: I can no longer reproduce this issue...

The issue has a high change of being related to uninitialized variables. To find it more easily, try building the editor with one of the sanitizers enabled:

image

h0lley commented 2 years ago

I've been getting this too when starting my project and it's not a recent thing, has been there since a couple of months at least. just haven't come around to reporting it because it doesn't seem to directly inhibit anything.

currently I'm getting 1 - 3 Unknown identifier in expression: 'tex_orbit_velocity'./'scale_texture' errors on opening project in editor each accompanied with shader code that begins with // NOTE: Shader automatically converted from Godot Engine 4.0.alpha's ParticleProcessMaterial.. also there's a --Main Shader-- notice before that.

just like in and3rson's case, I cannot pinpoint this to any particles material that is actually used in my project.

I've compiled with UBSAN but then the editor crashes when loading the project.

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.alpha.custom_build (9142904c248cb4c9de8776f9abe995fc22335c2c)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f6b948fc520] (??:0)
[2] Object::get_class_name() const (??:0)
[3] Object::emit_signalp(StringName const&, Variant const**, int) (??:0)
[4] Error Object::emit_signal<>(StringName const&) (??:0)
[5] Resource::emit_changed() (??:0)
[6] NoiseTexture2D::_set_texture_image(Ref<Image> const&) (??:0)
[7] NoiseTexture2D::_update_texture() (??:0)
[8] void call_with_variant_args_helper<__UnexistingClass>(__UnexistingClass*, void (__UnexistingClass::*)(), Variant const**, Callable::CallError&, IndexSequence<>) (??:0)
[9] void call_with_variant_args_dv<__UnexistingClass>(__UnexistingClass*, void (__UnexistingClass::*)(), Variant const**, int, Callable::CallError&, Vector<Variant> const&) (??:0)
[10] MethodBindT<>::call(Object*, Variant const**, int, Callable::CallError&) (??:0)
[11] Object::callp(StringName const&, Variant const**, int, Callable::CallError&) (??:0)
[12] Callable::callp(Variant const**, int, Variant&, Callable::CallError&) const (??:0)
[13] MessageQueue::_call_function(Callable const&, Variant const*, int, bool) (??:0)
[14] MessageQueue::flush() (??:0)
[15] Main::iteration() (??:0)
[16] OS_LinuxBSD::run() (??:0)
[17] /media/holly/Workspace/Projects/Godot/godot/bin/godot.linuxbsd.tools.x86_64.llvm.dev.san(main+0x56f) [0x5612995ddf6f] (??:0)
[18] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f6b948e3d90] (??:0)
[19] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f6b948e3e40] (??:0)
[20] /media/holly/Workspace/Projects/Godot/godot/bin/godot.linuxbsd.tools.x86_64.llvm.dev.san(_start+0x25) [0x5612995b3e45] (??:0)
-- END OF BACKTRACE --
================================================================

here's the full output

oh, and I've just realized this was reported for 3.5.stable I'm getting this with 4 alpha/master

felbecker commented 1 year ago

I'm getting this in 4.0.2. In my case scale_texture can also be replaced by a number of other (apparently random) properties of the particle material.

It happens when loading GPUParticles2D from a thread. The error disappears in a test scene if I remove GPUParticles2D from my nodes in a scene that is loaded async. It also disappears if I load the scene normally.