Repository: godot
Issue: Unknown identifier in expression: scale_texture
Labels: bug,topic:rendering,needs testing

### 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:

<details>

```
    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)
```

</details>

### 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:
- https://github.com/godotengine/godot/blob/3.5/scene/resources/particles_material.cpp#L250
- https://github.com/godotengine/godot/blob/3.5/scene/resources/particles_material.cpp#L573

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_