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

Casting a uniform bool to an integer or float breaks the renderer in GLSL shaders #72466

Closed
obfuscatedgenerated opened this issue Jan 31, 2023 · 9 comments · Fixed by #72494
Closed
Assignees
Milestone

Comments

@obfuscatedgenerated
Copy link

Godot version

3.5.1.stable

System information

Windows 10 x64, GLES2, GTX 1660 (528.02)

Issue description

I have a shader that takes a boolean input with uniform bool. I want to cast this to a float and multiply it by -1 to avoid branching. When I add in a line to perform the cast, I get an internal error to do with GL and the entire editor preview turns white.

Before:
image

After:
image

The full error (it's long as it has the contents of some internal files) is as follows:

   1 | #version 120
   2 | #define USE_GLES_OVER_GL
   3 | #define USE_TEXTURE_RECT
   4 | #define COLOR_USED
   5 | 
   6 | #ifdef USE_GLES_OVER_GL
   7 | #define lowp
   8 | #define mediump
   9 | #define highp
  10 | #else
  11 | precision highp float;
  12 | precision highp int;
  13 | #endif
  14 | 
  15 | uniform highp mat4 projection_matrix;
  16 | /* clang-format on */
  17 | 
  18 | 
  19 | vec2 select2(vec2 a, vec2 b, bvec2 c) {
  20 | 	vec2 ret;
  21 | 
  22 | 	ret.x = c.x ? b.x : a.x;
  23 | 	ret.y = c.y ? b.y : a.y;
  24 | 
  25 | 	return ret;
  26 | }
  27 | 
  28 | vec3 select3(vec3 a, vec3 b, bvec3 c) {
  29 | 	vec3 ret;
  30 | 
  31 | 	ret.x = c.x ? b.x : a.x;
  32 | 	ret.y = c.y ? b.y : a.y;
  33 | 	ret.z = c.z ? b.z : a.z;
  34 | 
  35 | 	return ret;
  36 | }
  37 | 
  38 | vec4 select4(vec4 a, vec4 b, bvec4 c) {
  39 | 	vec4 ret;
  40 | 
  41 | 	ret.x = c.x ? b.x : a.x;
  42 | 	ret.y = c.y ? b.y : a.y;
  43 | 	ret.z = c.z ? b.z : a.z;
  44 | 	ret.w = c.w ? b.w : a.w;
  45 | 
  46 | 	return ret;
  47 | }
  48 | 
  49 | highp vec4 texel2DFetch(highp sampler2D tex, ivec2 size, ivec2 coord) {
  50 | 	float x_coord = float(2 * coord.x + 1) / float(size.x * 2);
  51 | 	float y_coord = float(2 * coord.y + 1) / float(size.y * 2);
  52 | 
  53 | 	return texture2DLod(tex, vec2(x_coord, y_coord), 0.0);
  54 | }
  55 | 
  56 | #if defined(SINH_USED)
  57 | 
  58 | highp float sinh(highp float x) {
  59 | 	return 0.5 * (exp(x) - exp(-x));
  60 | }
  61 | 
  62 | highp vec2 sinh(highp vec2 x) {
  63 | 	return 0.5 * vec2(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y));
  64 | }
  65 | 
  66 | highp vec3 sinh(highp vec3 x) {
  67 | 	return 0.5 * vec3(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z));
  68 | }
  69 | 
  70 | highp vec4 sinh(highp vec4 x) {
  71 | 	return 0.5 * vec4(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z), exp(x.w) - exp(-x.w));
  72 | }
  73 | 
  74 | #endif
  75 | 
  76 | #if defined(COSH_USED)
  77 | 
  78 | highp float cosh(highp float x) {
  79 | 	return 0.5 * (exp(x) + exp(-x));
  80 | }
  81 | 
  82 | highp vec2 cosh(highp vec2 x) {
  83 | 	return 0.5 * vec2(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y));
  84 | }
  85 | 
  86 | highp vec3 cosh(highp vec3 x) {
  87 | 	return 0.5 * vec3(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z));
  88 | }
  89 | 
  90 | highp vec4 cosh(highp vec4 x) {
  91 | 	return 0.5 * vec4(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z), exp(x.w) + exp(-x.w));
  92 | }
  93 | 
  94 | #endif
  95 | 
  96 | #if defined(TANH_USED)
  97 | 
  98 | highp float tanh(highp float x) {
  99 | 	highp float exp2x = exp(2.0 * x);
 100 | 	return (exp2x - 1.0) / (exp2x + 1.0);
 101 | }
 102 | 
 103 | highp vec2 tanh(highp vec2 x) {
 104 | 	highp float exp2x = exp(2.0 * x.x);
 105 | 	highp float exp2y = exp(2.0 * x.y);
 106 | 	return vec2((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0));
 107 | }
 108 | 
 109 | highp vec3 tanh(highp vec3 x) {
 110 | 	highp float exp2x = exp(2.0 * x.x);
 111 | 	highp float exp2y = exp(2.0 * x.y);
 112 | 	highp float exp2z = exp(2.0 * x.z);
 113 | 	return vec3((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0));
 114 | }
 115 | 
 116 | highp vec4 tanh(highp vec4 x) {
 117 | 	highp float exp2x = exp(2.0 * x.x);
 118 | 	highp float exp2y = exp(2.0 * x.y);
 119 | 	highp float exp2z = exp(2.0 * x.z);
 120 | 	highp float exp2w = exp(2.0 * x.w);
 121 | 	return vec4((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0), (exp2w - 1.0) / (exp2w + 1.0));
 122 | }
 123 | 
 124 | #endif
 125 | 
 126 | #if defined(ASINH_USED)
 127 | 
 128 | highp float asinh(highp float x) {
 129 | 	return sign(x) * log(abs(x) + sqrt(1.0 + x * x));
 130 | }
 131 | 
 132 | highp vec2 asinh(highp vec2 x) {
 133 | 	return vec2(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)));
 134 | }
 135 | 
 136 | highp vec3 asinh(highp vec3 x) {
 137 | 	return vec3(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)));
 138 | }
 139 | 
 140 | highp vec4 asinh(highp vec4 x) {
 141 | 	return vec4(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)), sign(x.w) * log(abs(x.w) + sqrt(1.0 + x.w * x.w)));
 142 | }
 143 | 
 144 | #endif
 145 | 
 146 | #if defined(ACOSH_USED)
 147 | 
 148 | highp float acosh(highp float x) {
 149 | 	return log(x + sqrt(x * x - 1.0));
 150 | }
 151 | 
 152 | highp vec2 acosh(highp vec2 x) {
 153 | 	return vec2(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)));
 154 | }
 155 | 
 156 | highp vec3 acosh(highp vec3 x) {
 157 | 	return vec3(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)));
 158 | }
 159 | 
 160 | highp vec4 acosh(highp vec4 x) {
 161 | 	return vec4(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)), log(x.w + sqrt(x.w * x.w - 1.0)));
 162 | }
 163 | 
 164 | #endif
 165 | 
 166 | #if defined(ATANH_USED)
 167 | 
 168 | highp float atanh(highp float x) {
 169 | 	return 0.5 * log((1.0 + x) / (1.0 - x));
 170 | }
 171 | 
 172 | highp vec2 atanh(highp vec2 x) {
 173 | 	return 0.5 * vec2(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)));
 174 | }
 175 | 
 176 | highp vec3 atanh(highp vec3 x) {
 177 | 	return 0.5 * vec3(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)));
 178 | }
 179 | 
 180 | highp vec4 atanh(highp vec4 x) {
 181 | 	return 0.5 * vec4(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)), log((1.0 + x.w) / (1.0 - x.w)));
 182 | }
 183 | 
 184 | #endif
 185 | 
 186 | #if defined(ROUND_USED)
 187 | 
 188 | highp float round(highp float x) {
 189 | 	return floor(x + 0.5);
 190 | }
 191 | 
 192 | highp vec2 round(highp vec2 x) {
 193 | 	return floor(x + vec2(0.5));
 194 | }
 195 | 
 196 | highp vec3 round(highp vec3 x) {
 197 | 	return floor(x + vec3(0.5));
 198 | }
 199 | 
 200 | highp vec4 round(highp vec4 x) {
 201 | 	return floor(x + vec4(0.5));
 202 | }
 203 | 
 204 | #endif
 205 | 
 206 | #if defined(ROUND_EVEN_USED)
 207 | 
 208 | highp float roundEven(highp float x) {
 209 | 	highp float t = x + 0.5;
 210 | 	highp float f = floor(t);
 211 | 	highp float r;
 212 | 	if (t == f) {
 213 | 		if (x > 0)
 214 | 			r = f - mod(f, 2);
 215 | 		else
 216 | 			r = f + mod(f, 2);
 217 | 	} else
 218 | 		r = f;
 219 | 	return r;
 220 | }
 221 | 
 222 | highp vec2 roundEven(highp vec2 x) {
 223 | 	return vec2(roundEven(x.x), roundEven(x.y));
 224 | }
 225 | 
 226 | highp vec3 roundEven(highp vec3 x) {
 227 | 	return vec3(roundEven(x.x), roundEven(x.y), roundEven(x.z));
 228 | }
 229 | 
 230 | highp vec4 roundEven(highp vec4 x) {
 231 | 	return vec4(roundEven(x.x), roundEven(x.y), roundEven(x.z), roundEven(x.w));
 232 | }
 233 | 
 234 | #endif
 235 | 
 236 | #if defined(IS_INF_USED)
 237 | 
 238 | bool isinf(highp float x) {
 239 | 	return (2 * x == x) && (x != 0);
 240 | }
 241 | 
 242 | bvec2 isinf(highp vec2 x) {
 243 | 	return bvec2((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0));
 244 | }
 245 | 
 246 | bvec3 isinf(highp vec3 x) {
 247 | 	return bvec3((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0));
 248 | }
 249 | 
 250 | bvec4 isinf(highp vec4 x) {
 251 | 	return bvec4((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0), (2 * x.w == x.w) && (x.w != 0));
 252 | }
 253 | 
 254 | #endif
 255 | 
 256 | #if defined(IS_NAN_USED)
 257 | 
 258 | bool isnan(highp float x) {
 259 | 	return x != x;
 260 | }
 261 | 
 262 | bvec2 isnan(highp vec2 x) {
 263 | 	return bvec2(x.x != x.x, x.y != x.y);
 264 | }
 265 | 
 266 | bvec3 isnan(highp vec3 x) {
 267 | 	return bvec3(x.x != x.x, x.y != x.y, x.z != x.z);
 268 | }
 269 | 
 270 | bvec4 isnan(highp vec4 x) {
 271 | 	return bvec4(x.x != x.x, x.y != x.y, x.z != x.z, x.w != x.w);
 272 | }
 273 | 
 274 | #endif
 275 | 
 276 | #if defined(TRUNC_USED)
 277 | 
 278 | highp float trunc(highp float x) {
 279 | 	return x < 0.0 ? -floor(-x) : floor(x);
 280 | }
 281 | 
 282 | highp vec2 trunc(highp vec2 x) {
 283 | 	return vec2(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y));
 284 | }
 285 | 
 286 | highp vec3 trunc(highp vec3 x) {
 287 | 	return vec3(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z));
 288 | }
 289 | 
 290 | highp vec4 trunc(highp vec4 x) {
 291 | 	return vec4(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z), x.w < 0.0 ? -floor(-x.w) : floor(x.w));
 292 | }
 293 | 
 294 | #endif
 295 | 
 296 | #if defined(DETERMINANT_USED)
 297 | 
 298 | highp float determinant(highp mat2 m) {
 299 | 	return m[0].x * m[1].y - m[1].x * m[0].y;
 300 | }
 301 | 
 302 | highp float determinant(highp mat3 m) {
 303 | 	return m[0].x * (m[1].y * m[2].z - m[2].y * m[1].z) - m[1].x * (m[0].y * m[2].z - m[2].y * m[0].z) + m[2].x * (m[0].y * m[1].z - m[1].y * m[0].z);
 304 | }
 305 | 
 306 | highp float determinant(highp mat4 m) {
 307 | 	highp float s00 = m[2].z * m[3].w - m[3].z * m[2].w;
 308 | 	highp float s01 = m[2].y * m[3].w - m[3].y * m[2].w;
 309 | 	highp float s02 = m[2].y * m[3].z - m[3].y * m[2].z;
 310 | 	highp float s03 = m[2].x * m[3].w - m[3].x * m[2].w;
 311 | 	highp float s04 = m[2].x * m[3].z - m[3].x * m[2].z;
 312 | 	highp float s05 = m[2].x * m[3].y - m[3].x * m[2].y;
 313 | 	highp vec4 c = vec4((m[1].y * s00 - m[1].z * s01 + m[1].w * s02), -(m[1].x * s00 - m[1].z * s03 + m[1].w * s04), (m[1].x * s01 - m[1].y * s03 + m[1].w * s05), -(m[1].x * s02 - m[1].y * s04 + m[1].z * s05));
 314 | 	return m[0].x * c.x + m[0].y * c.y + m[0].z * c.z + m[0].w * c.w;
 315 | }
 316 | 
 317 | #endif
 318 | 
 319 | #if defined(INVERSE_USED)
 320 | 
 321 | highp mat2 inverse(highp mat2 m) {
 322 | 	highp float d = 1.0 / (m[0].x * m[1].y - m[1].x * m[0].y);
 323 | 	return mat2(
 324 | 			vec2(m[1].y * d, -m[0].y * d),
 325 | 			vec2(-m[1].x * d, m[0].x * d));
 326 | }
 327 | 
 328 | highp mat3 inverse(highp mat3 m) {
 329 | 	highp float c01 = m[2].z * m[1].y - m[1].z * m[2].y;
 330 | 	highp float c11 = -m[2].z * m[1].x + m[1].z * m[2].x;
 331 | 	highp float c21 = m[2].y * m[1].x - m[1].y * m[2].x;
 332 | 	highp float d = 1.0 / (m[0].x * c01 + m[0].y * c11 + m[0].z * c21);
 333 | 
 334 | 	return mat3(c01, (-m[2].z * m[0].y + m[0].z * m[2].y), (m[1].z * m[0].y - m[0].z * m[1].y),
 335 | 				   c11, (m[2].z * m[0].x - m[0].z * m[2].x), (-m[1].z * m[0].x + m[0].z * m[1].x),
 336 | 				   c21, (-m[2].y * m[0].x + m[0].y * m[2].x), (m[1].y * m[0].x - m[0].y * m[1].x)) *
 337 | 			d;
 338 | }
 339 | 
 340 | highp mat4 inverse(highp mat4 m) {
 341 | 	highp float c00 = m[2].z * m[3].w - m[3].z * m[2].w;
 342 | 	highp float c02 = m[1].z * m[3].w - m[3].z * m[1].w;
 343 | 	highp float c03 = m[1].z * m[2].w - m[2].z * m[1].w;
 344 | 
 345 | 	highp float c04 = m[2].y * m[3].w - m[3].y * m[2].w;
 346 | 	highp float c06 = m[1].y * m[3].w - m[3].y * m[1].w;
 347 | 	highp float c07 = m[1].y * m[2].w - m[2].y * m[1].w;
 348 | 
 349 | 	highp float c08 = m[2].y * m[3].z - m[3].y * m[2].z;
 350 | 	highp float c10 = m[1].y * m[3].z - m[3].y * m[1].z;
 351 | 	highp float c11 = m[1].y * m[2].z - m[2].y * m[1].z;
 352 | 
 353 | 	highp float c12 = m[2].x * m[3].w - m[3].x * m[2].w;
 354 | 	highp float c14 = m[1].x * m[3].w - m[3].x * m[1].w;
 355 | 	highp float c15 = m[1].x * m[2].w - m[2].x * m[1].w;
 356 | 
 357 | 	highp float c16 = m[2].x * m[3].z - m[3].x * m[2].z;
 358 | 	highp float c18 = m[1].x * m[3].z - m[3].x * m[1].z;
 359 | 	highp float c19 = m[1].x * m[2].z - m[2].x * m[1].z;
 360 | 
 361 | 	highp float c20 = m[2].x * m[3].y - m[3].x * m[2].y;
 362 | 	highp float c22 = m[1].x * m[3].y - m[3].x * m[1].y;
 363 | 	highp float c23 = m[1].x * m[2].y - m[2].x * m[1].y;
 364 | 
 365 | 	vec4 f0 = vec4(c00, c00, c02, c03);
 366 | 	vec4 f1 = vec4(c04, c04, c06, c07);
 367 | 	vec4 f2 = vec4(c08, c08, c10, c11);
 368 | 	vec4 f3 = vec4(c12, c12, c14, c15);
 369 | 	vec4 f4 = vec4(c16, c16, c18, c19);
 370 | 	vec4 f5 = vec4(c20, c20, c22, c23);
 371 | 
 372 | 	vec4 v0 = vec4(m[1].x, m[0].x, m[0].x, m[0].x);
 373 | 	vec4 v1 = vec4(m[1].y, m[0].y, m[0].y, m[0].y);
 374 | 	vec4 v2 = vec4(m[1].z, m[0].z, m[0].z, m[0].z);
 375 | 	vec4 v3 = vec4(m[1].w, m[0].w, m[0].w, m[0].w);
 376 | 
 377 | 	vec4 inv0 = vec4(v1 * f0 - v2 * f1 + v3 * f2);
 378 | 	vec4 inv1 = vec4(v0 * f0 - v2 * f3 + v3 * f4);
 379 | 	vec4 inv2 = vec4(v0 * f1 - v1 * f3 + v3 * f5);
 380 | 	vec4 inv3 = vec4(v0 * f2 - v1 * f4 + v2 * f5);
 381 | 
 382 | 	vec4 sa = vec4(+1, -1, +1, -1);
 383 | 	vec4 sb = vec4(-1, +1, -1, +1);
 384 | 
 385 | 	mat4 inv = mat4(inv0 * sa, inv1 * sb, inv2 * sa, inv3 * sb);
 386 | 
 387 | 	vec4 r0 = vec4(inv[0].x, inv[1].x, inv[2].x, inv[3].x);
 388 | 	vec4 d0 = vec4(m[0] * r0);
 389 | 
 390 | 	highp float d1 = (d0.x + d0.y) + (d0.z + d0.w);
 391 | 	highp float d = 1.0 / d1;
 392 | 
 393 | 	return inv * d;
 394 | }
 395 | 
 396 | #endif
 397 | 
 398 | #ifndef USE_GLES_OVER_GL
 399 | 
 400 | #if defined(TRANSPOSE_USED)
 401 | 
 402 | highp mat2 transpose(highp mat2 m) {
 403 | 	return mat2(
 404 | 			vec2(m[0].x, m[1].x),
 405 | 			vec2(m[0].y, m[1].y));
 406 | }
 407 | 
 408 | highp mat3 transpose(highp mat3 m) {
 409 | 	return mat3(
 410 | 			vec3(m[0].x, m[1].x, m[2].x),
 411 | 			vec3(m[0].y, m[1].y, m[2].y),
 412 | 			vec3(m[0].z, m[1].z, m[2].z));
 413 | }
 414 | 
 415 | #endif
 416 | 
 417 | highp mat4 transpose(highp mat4 m) {
 418 | 	return mat4(
 419 | 			vec4(m[0].x, m[1].x, m[2].x, m[3].x),
 420 | 			vec4(m[0].y, m[1].y, m[2].y, m[3].y),
 421 | 			vec4(m[0].z, m[1].z, m[2].z, m[3].z),
 422 | 			vec4(m[0].w, m[1].w, m[2].w, m[3].w));
 423 | }
 424 | 
 425 | #if defined(OUTER_PRODUCT_USED)
 426 | 
 427 | highp mat2 outerProduct(highp vec2 c, highp vec2 r) {
 428 | 	return mat2(c * r.x, c * r.y);
 429 | }
 430 | 
 431 | highp mat3 outerProduct(highp vec3 c, highp vec3 r) {
 432 | 	return mat3(c * r.x, c * r.y, c * r.z);
 433 | }
 434 | 
 435 | highp mat4 outerProduct(highp vec4 c, highp vec4 r) {
 436 | 	return mat4(c * r.x, c * r.y, c * r.z, c * r.w);
 437 | }
 438 | 
 439 | #endif
 440 | 
 441 | #endif
 442 | 
 443 | uniform highp mat4 modelview_matrix;
 444 | uniform highp mat4 extra_matrix;
 445 | attribute highp vec2 vertex; // attrib:0
 446 | 
 447 | #ifdef USE_ATTRIB_LIGHT_ANGLE
 448 | // shared with tangent, not used in canvas shader
 449 | attribute highp float light_angle; // attrib:2
 450 | #endif
 451 | 
 452 | attribute vec4 color_attrib; // attrib:3
 453 | attribute vec2 uv_attrib; // attrib:4
 454 | 
 455 | #ifdef USE_ATTRIB_MODULATE
 456 | attribute highp vec4 modulate_attrib; // attrib:5
 457 | #endif
 458 | 
 459 | // Usually, final_modulate is passed as a uniform. However during batching
 460 | // If larger fvfs are used, final_modulate is passed as an attribute.
 461 | // we need to read from the attribute in custom vertex shader
 462 | // rather than the uniform. We do this by specifying final_modulate_alias
 463 | // in shaders rather than final_modulate directly.
 464 | #ifdef USE_ATTRIB_MODULATE
 465 | #define final_modulate_alias modulate_attrib
 466 | #else
 467 | #define final_modulate_alias final_modulate
 468 | #endif
 469 | 
 470 | #ifdef USE_ATTRIB_LARGE_VERTEX
 471 | // shared with skeleton attributes, not used in batched shader
 472 | attribute highp vec2 translate_attrib; // attrib:6
 473 | attribute highp vec4 basis_attrib; // attrib:7
 474 | #endif
 475 | 
 476 | #ifdef USE_SKELETON
 477 | attribute highp vec4 bone_indices; // attrib:6
 478 | attribute highp vec4 bone_weights; // attrib:7
 479 | #endif
 480 | 
 481 | #ifdef USE_INSTANCING
 482 | 
 483 | attribute highp vec4 instance_xform0; //attrib:8
 484 | attribute highp vec4 instance_xform1; //attrib:9
 485 | attribute highp vec4 instance_xform2; //attrib:10
 486 | attribute highp vec4 instance_color; //attrib:11
 487 | 
 488 | #ifdef USE_INSTANCE_CUSTOM
 489 | attribute highp vec4 instance_custom_data; //attrib:12
 490 | #endif
 491 | 
 492 | #endif
 493 | 
 494 | #ifdef USE_SKELETON
 495 | uniform highp sampler2D skeleton_texture; // texunit:-3
 496 | uniform highp ivec2 skeleton_texture_size;
 497 | uniform highp mat4 skeleton_transform;
 498 | uniform highp mat4 skeleton_transform_inverse;
 499 | #endif
 500 | 
 501 | varying vec2 uv_interp;
 502 | varying vec4 color_interp;
 503 | 
 504 | #ifdef USE_ATTRIB_MODULATE
 505 | // modulate doesn't need interpolating but we need to send it to the fragment shader
 506 | varying vec4 modulate_interp;
 507 | #endif
 508 | 
 509 | #ifdef MODULATE_USED
 510 | uniform vec4 final_modulate;
 511 | #endif
 512 | 
 513 | uniform highp vec2 color_texpixel_size;
 514 | 
 515 | #ifdef USE_TEXTURE_RECT
 516 | 
 517 | uniform vec4 dst_rect;
 518 | uniform vec4 src_rect;
 519 | 
 520 | #endif
 521 | 
 522 | uniform highp float time;
 523 | 
 524 | #ifdef USE_LIGHTING
 525 | 
 526 | // light matrices
 527 | uniform highp mat4 light_matrix;
 528 | uniform highp mat4 light_matrix_inverse;
 529 | uniform highp mat4 light_local_matrix;
 530 | uniform highp mat4 shadow_matrix;
 531 | uniform highp vec4 light_color;
 532 | uniform highp vec4 light_shadow_color;
 533 | uniform highp vec2 light_pos;
 534 | uniform highp float shadowpixel_size;
 535 | uniform highp float shadow_gradient;
 536 | uniform highp float light_height;
 537 | uniform highp float light_outside_alpha;
 538 | uniform highp float shadow_distance_mult;
 539 | 
 540 | varying vec4 light_uv_interp;
 541 | varying vec2 transformed_light_uv;
 542 | varying vec4 local_rot;
 543 | 
 544 | #ifdef USE_SHADOWS
 545 | varying highp vec2 pos;
 546 | #endif
 547 | 
 548 | const bool at_light_pass = true;
 549 | #else
 550 | const bool at_light_pass = false;
 551 | #endif
 552 | 
 553 | /* clang-format off */
 554 | uniform highp float m_effect_start;
 555 | uniform highp float m_effect_width;
 556 | uniform highp float m_smoothness;
 557 | uniform bool m_invert_effect;
 558 | const float m_alpha_multiplier=(float(m_invert_effect) * -1.0);
 559 | 
 560 | 
 561 | /* clang-format on */
 562 | 
 563 | vec2 select(vec2 a, vec2 b, bvec2 c) {
 564 | 	vec2 ret;
 565 | 
 566 | 	ret.x = c.x ? b.x : a.x;
 567 | 	ret.y = c.y ? b.y : a.y;
 568 | 
 569 | 	return ret;
 570 | }
 571 | 
 572 | void main() {
 573 | 	vec4 color = color_attrib;
 574 | 	vec2 uv;
 575 | 
 576 | #ifdef USE_INSTANCING
 577 | 	mat4 extra_matrix_instance = extra_matrix * transpose(mat4(instance_xform0, instance_xform1, instance_xform2, vec4(0.0, 0.0, 0.0, 1.0)));
 578 | 	color *= instance_color;
 579 | 
 580 | #ifdef USE_INSTANCE_CUSTOM
 581 | 	vec4 instance_custom = instance_custom_data;
 582 | #else
 583 | 	vec4 instance_custom = vec4(0.0);
 584 | #endif
 585 | 
 586 | #else
 587 | 	mat4 extra_matrix_instance = extra_matrix;
 588 | 	vec4 instance_custom = vec4(0.0);
 589 | #endif
 590 | 
 591 | #ifdef USE_TEXTURE_RECT
 592 | 
 593 | 	if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z
 594 | 		uv = src_rect.xy + abs(src_rect.zw) * vertex.yx;
 595 | 	} else {
 596 | 		uv = src_rect.xy + abs(src_rect.zw) * vertex;
 597 | 	}
 598 | 
 599 | 	vec4 outvec = vec4(0.0, 0.0, 0.0, 1.0);
 600 | 
 601 | 	// This is what is done in the GLES 3 bindings and should
 602 | 	// take care of flipped rects.
 603 | 	//
 604 | 	// But it doesn't.
 605 | 	// I don't know why, will need to investigate further.
 606 | 
 607 | 	outvec.xy = dst_rect.xy + abs(dst_rect.zw) * select(vertex, vec2(1.0, 1.0) - vertex, lessThan(src_rect.zw, vec2(0.0, 0.0)));
 608 | 
 609 | 	// outvec.xy = dst_rect.xy + abs(dst_rect.zw) * vertex;
 610 | #else
 611 | 	vec4 outvec = vec4(vertex.xy, 0.0, 1.0);
 612 | 
 613 | 	uv = uv_attrib;
 614 | #endif
 615 | 
 616 | 	float point_size = 1.0;
 617 | 
 618 | 	{
 619 | 		vec2 src_vtx = outvec.xy;
 620 | 		/* clang-format off */
 621 | 
 622 | 
 623 | 		/* clang-format on */
 624 | 	}
 625 | 
 626 | 	gl_PointSize = point_size;
 627 | 
 628 | #ifdef USE_ATTRIB_MODULATE
 629 | 	// modulate doesn't need interpolating but we need to send it to the fragment shader
 630 | 	modulate_interp = modulate_attrib;
 631 | #endif
 632 | 
 633 | #ifdef USE_ATTRIB_LARGE_VERTEX
 634 | 	// transform is in attributes
 635 | 	vec2 temp;
 636 | 
 637 | 	temp = outvec.xy;
 638 | 	temp.x = (outvec.x * basis_attrib.x) + (outvec.y * basis_attrib.z);
 639 | 	temp.y = (outvec.x * basis_attrib.y) + (outvec.y * basis_attrib.w);
 640 | 
 641 | 	temp += translate_attrib;
 642 | 	outvec.xy = temp;
 643 | 
 644 | #else
 645 | 
 646 | 	// transform is in uniforms
 647 | #if !defined(SKIP_TRANSFORM_USED)
 648 | 	outvec = extra_matrix_instance * outvec;
 649 | 	outvec = modelview_matrix * outvec;
 650 | #endif
 651 | 
 652 | #endif // not large integer
 653 | 
 654 | 	color_interp = color;
 655 | 
 656 | #ifdef USE_PIXEL_SNAP
 657 | 	outvec.xy = floor(outvec + 0.5).xy;
 658 | 	// precision issue on some hardware creates artifacts within texture
 659 | 	// offset uv by a small amount to avoid
 660 | 	uv += 1e-5;
 661 | #endif
 662 | 
 663 | #ifdef USE_SKELETON
 664 | 
 665 | 	// look up transform from the "pose texture"
 666 | 	if (bone_weights != vec4(0.0)) {
 667 | 		highp mat4 bone_transform = mat4(0.0);
 668 | 
 669 | 		for (int i = 0; i < 4; i++) {
 670 | 			ivec2 tex_ofs = ivec2(int(bone_indices[i]) * 2, 0);
 671 | 
 672 | 			highp mat4 b = mat4(
 673 | 					texel2DFetch(skeleton_texture, skeleton_texture_size, tex_ofs + ivec2(0, 0)),
 674 | 					texel2DFetch(skeleton_texture, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
 675 | 					vec4(0.0, 0.0, 1.0, 0.0),
 676 | 					vec4(0.0, 0.0, 0.0, 1.0));
 677 | 
 678 | 			bone_transform += b * bone_weights[i];
 679 | 		}
 680 | 
 681 | 		mat4 bone_matrix = skeleton_transform * transpose(bone_transform) * skeleton_transform_inverse;
 682 | 
 683 | 		outvec = bone_matrix * outvec;
 684 | 	}
 685 | 
 686 | #endif
 687 | 
 688 | 	uv_interp = uv;
 689 | 	gl_Position = projection_matrix * outvec;
 690 | 
 691 | #ifdef USE_LIGHTING
 692 | 
 693 | 	light_uv_interp.xy = (light_matrix * outvec).xy;
 694 | 	light_uv_interp.zw = (light_local_matrix * outvec).xy;
 695 | 
 696 | 	transformed_light_uv = (mat3(light_matrix_inverse) * vec3(light_uv_interp.zw, 0.0)).xy; //for normal mapping
 697 | 
 698 | #ifdef USE_SHADOWS
 699 | 	pos = outvec.xy;
 700 | #endif
 701 | 
 702 | #ifdef USE_ATTRIB_LIGHT_ANGLE
 703 | 	// we add a fixed offset because we are using the sign later,
 704 | 	// and don't want floating point error around 0.0
 705 | 	float la = abs(light_angle) - 1.0;
 706 | 
 707 | 	// vector light angle
 708 | 	vec4 vla;
 709 | 	vla.xy = vec2(cos(la), sin(la));
 710 | 	vla.zw = vec2(-vla.y, vla.x);
 711 | 
 712 | 	// vertical flip encoded in the sign
 713 | 	vla.zw *= sign(light_angle);
 714 | 
 715 | 	// apply the transform matrix.
 716 | 	// The rotate will be encoded in the transform matrix for single rects,
 717 | 	// and just the flips in the light angle.
 718 | 	// For batching we will encode the rotation and the flips
 719 | 	// in the light angle, and can use the same shader.
 720 | 	local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.xy, 0.0, 0.0))).xy);
 721 | 	local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.zw, 0.0, 0.0))).xy);
 722 | #else
 723 | 	local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(1.0, 0.0, 0.0, 0.0))).xy);
 724 | 	local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(0.0, 1.0, 0.0, 0.0))).xy);
 725 | #ifdef USE_TEXTURE_RECT
 726 | 	local_rot.xy *= sign(src_rect.z);
 727 | 	local_rot.zw *= sign(src_rect.w);
 728 | #endif
 729 | #endif // not using light angle
 730 | 
 731 | #endif
 732 | }
 733 | 
 734 | /* clang-format off */
 735 | 
 drivers/gles2/shader_gles2.cpp:126 - CanvasShaderGLES2: Vertex shader compilation failed:
0(558) : error C1059: non constant expression in initialization

 drivers/gles2/shader_gles2.cpp:296 - Method failed. Returning: nullptr
 drivers/gles2/shader_gles2.cpp:87 - Condition "!version" is true. Returned: false
   1 | #version 120
   2 | #define USE_GLES_OVER_GL
   3 | #define COLOR_USED
   4 | 
   5 | #ifdef USE_GLES_OVER_GL
   6 | #define lowp
   7 | #define mediump
   8 | #define highp
   9 | #else
  10 | precision highp float;
  11 | precision highp int;
  12 | #endif
  13 | 
  14 | uniform highp mat4 projection_matrix;
  15 | /* clang-format on */
  16 | 
  17 | 
  18 | vec2 select2(vec2 a, vec2 b, bvec2 c) {
  19 | 	vec2 ret;
  20 | 
  21 | 	ret.x = c.x ? b.x : a.x;
  22 | 	ret.y = c.y ? b.y : a.y;
  23 | 
  24 | 	return ret;
  25 | }
  26 | 
  27 | vec3 select3(vec3 a, vec3 b, bvec3 c) {
  28 | 	vec3 ret;
  29 | 
  30 | 	ret.x = c.x ? b.x : a.x;
  31 | 	ret.y = c.y ? b.y : a.y;
  32 | 	ret.z = c.z ? b.z : a.z;
  33 | 
  34 | 	return ret;
  35 | }
  36 | 
  37 | vec4 select4(vec4 a, vec4 b, bvec4 c) {
  38 | 	vec4 ret;
  39 | 
  40 | 	ret.x = c.x ? b.x : a.x;
  41 | 	ret.y = c.y ? b.y : a.y;
  42 | 	ret.z = c.z ? b.z : a.z;
  43 | 	ret.w = c.w ? b.w : a.w;
  44 | 
  45 | 	return ret;
  46 | }
  47 | 
  48 | highp vec4 texel2DFetch(highp sampler2D tex, ivec2 size, ivec2 coord) {
  49 | 	float x_coord = float(2 * coord.x + 1) / float(size.x * 2);
  50 | 	float y_coord = float(2 * coord.y + 1) / float(size.y * 2);
  51 | 
  52 | 	return texture2DLod(tex, vec2(x_coord, y_coord), 0.0);
  53 | }
  54 | 
  55 | #if defined(SINH_USED)
  56 | 
  57 | highp float sinh(highp float x) {
  58 | 	return 0.5 * (exp(x) - exp(-x));
  59 | }
  60 | 
  61 | highp vec2 sinh(highp vec2 x) {
  62 | 	return 0.5 * vec2(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y));
  63 | }
  64 | 
  65 | highp vec3 sinh(highp vec3 x) {
  66 | 	return 0.5 * vec3(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z));
  67 | }
  68 | 
  69 | highp vec4 sinh(highp vec4 x) {
  70 | 	return 0.5 * vec4(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z), exp(x.w) - exp(-x.w));
  71 | }
  72 | 
  73 | #endif
  74 | 
  75 | #if defined(COSH_USED)
  76 | 
  77 | highp float cosh(highp float x) {
  78 | 	return 0.5 * (exp(x) + exp(-x));
  79 | }
  80 | 
  81 | highp vec2 cosh(highp vec2 x) {
  82 | 	return 0.5 * vec2(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y));
  83 | }
  84 | 
  85 | highp vec3 cosh(highp vec3 x) {
  86 | 	return 0.5 * vec3(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z));
  87 | }
  88 | 
  89 | highp vec4 cosh(highp vec4 x) {
  90 | 	return 0.5 * vec4(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z), exp(x.w) + exp(-x.w));
  91 | }
  92 | 
  93 | #endif
  94 | 
  95 | #if defined(TANH_USED)
  96 | 
  97 | highp float tanh(highp float x) {
  98 | 	highp float exp2x = exp(2.0 * x);
  99 | 	return (exp2x - 1.0) / (exp2x + 1.0);
 100 | }
 101 | 
 102 | highp vec2 tanh(highp vec2 x) {
 103 | 	highp float exp2x = exp(2.0 * x.x);
 104 | 	highp float exp2y = exp(2.0 * x.y);
 105 | 	return vec2((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0));
 106 | }
 107 | 
 108 | highp vec3 tanh(highp vec3 x) {
 109 | 	highp float exp2x = exp(2.0 * x.x);
 110 | 	highp float exp2y = exp(2.0 * x.y);
 111 | 	highp float exp2z = exp(2.0 * x.z);
 112 | 	return vec3((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0));
 113 | }
 114 | 
 115 | highp vec4 tanh(highp vec4 x) {
 116 | 	highp float exp2x = exp(2.0 * x.x);
 117 | 	highp float exp2y = exp(2.0 * x.y);
 118 | 	highp float exp2z = exp(2.0 * x.z);
 119 | 	highp float exp2w = exp(2.0 * x.w);
 120 | 	return vec4((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0), (exp2w - 1.0) / (exp2w + 1.0));
 121 | }
 122 | 
 123 | #endif
 124 | 
 125 | #if defined(ASINH_USED)
 126 | 
 127 | highp float asinh(highp float x) {
 128 | 	return sign(x) * log(abs(x) + sqrt(1.0 + x * x));
 129 | }
 130 | 
 131 | highp vec2 asinh(highp vec2 x) {
 132 | 	return vec2(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)));
 133 | }
 134 | 
 135 | highp vec3 asinh(highp vec3 x) {
 136 | 	return vec3(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)));
 137 | }
 138 | 
 139 | highp vec4 asinh(highp vec4 x) {
 140 | 	return vec4(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)), sign(x.w) * log(abs(x.w) + sqrt(1.0 + x.w * x.w)));
 141 | }
 142 | 
 143 | #endif
 144 | 
 145 | #if defined(ACOSH_USED)
 146 | 
 147 | highp float acosh(highp float x) {
 148 | 	return log(x + sqrt(x * x - 1.0));
 149 | }
 150 | 
 151 | highp vec2 acosh(highp vec2 x) {
 152 | 	return vec2(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)));
 153 | }
 154 | 
 155 | highp vec3 acosh(highp vec3 x) {
 156 | 	return vec3(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)));
 157 | }
 158 | 
 159 | highp vec4 acosh(highp vec4 x) {
 160 | 	return vec4(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)), log(x.w + sqrt(x.w * x.w - 1.0)));
 161 | }
 162 | 
 163 | #endif
 164 | 
 165 | #if defined(ATANH_USED)
 166 | 
 167 | highp float atanh(highp float x) {
 168 | 	return 0.5 * log((1.0 + x) / (1.0 - x));
 169 | }
 170 | 
 171 | highp vec2 atanh(highp vec2 x) {
 172 | 	return 0.5 * vec2(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)));
 173 | }
 174 | 
 175 | highp vec3 atanh(highp vec3 x) {
 176 | 	return 0.5 * vec3(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)));
 177 | }
 178 | 
 179 | highp vec4 atanh(highp vec4 x) {
 180 | 	return 0.5 * vec4(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)), log((1.0 + x.w) / (1.0 - x.w)));
 181 | }
 182 | 
 183 | #endif
 184 | 
 185 | #if defined(ROUND_USED)
 186 | 
 187 | highp float round(highp float x) {
 188 | 	return floor(x + 0.5);
 189 | }
 190 | 
 191 | highp vec2 round(highp vec2 x) {
 192 | 	return floor(x + vec2(0.5));
 193 | }
 194 | 
 195 | highp vec3 round(highp vec3 x) {
 196 | 	return floor(x + vec3(0.5));
 197 | }
 198 | 
 199 | highp vec4 round(highp vec4 x) {
 200 | 	return floor(x + vec4(0.5));
 201 | }
 202 | 
 203 | #endif
 204 | 
 205 | #if defined(ROUND_EVEN_USED)
 206 | 
 207 | highp float roundEven(highp float x) {
 208 | 	highp float t = x + 0.5;
 209 | 	highp float f = floor(t);
 210 | 	highp float r;
 211 | 	if (t == f) {
 212 | 		if (x > 0)
 213 | 			r = f - mod(f, 2);
 214 | 		else
 215 | 			r = f + mod(f, 2);
 216 | 	} else
 217 | 		r = f;
 218 | 	return r;
 219 | }
 220 | 
 221 | highp vec2 roundEven(highp vec2 x) {
 222 | 	return vec2(roundEven(x.x), roundEven(x.y));
 223 | }
 224 | 
 225 | highp vec3 roundEven(highp vec3 x) {
 226 | 	return vec3(roundEven(x.x), roundEven(x.y), roundEven(x.z));
 227 | }
 228 | 
 229 | highp vec4 roundEven(highp vec4 x) {
 230 | 	return vec4(roundEven(x.x), roundEven(x.y), roundEven(x.z), roundEven(x.w));
 231 | }
 232 | 
 233 | #endif
 234 | 
 235 | #if defined(IS_INF_USED)
 236 | 
 237 | bool isinf(highp float x) {
 238 | 	return (2 * x == x) && (x != 0);
 239 | }
 240 | 
 241 | bvec2 isinf(highp vec2 x) {
 242 | 	return bvec2((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0));
 243 | }
 244 | 
 245 | bvec3 isinf(highp vec3 x) {
 246 | 	return bvec3((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0));
 247 | }
 248 | 
 249 | bvec4 isinf(highp vec4 x) {
 250 | 	return bvec4((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0), (2 * x.w == x.w) && (x.w != 0));
 251 | }
 252 | 
 253 | #endif
 254 | 
 255 | #if defined(IS_NAN_USED)
 256 | 
 257 | bool isnan(highp float x) {
 258 | 	return x != x;
 259 | }
 260 | 
 261 | bvec2 isnan(highp vec2 x) {
 262 | 	return bvec2(x.x != x.x, x.y != x.y);
 263 | }
 264 | 
 265 | bvec3 isnan(highp vec3 x) {
 266 | 	return bvec3(x.x != x.x, x.y != x.y, x.z != x.z);
 267 | }
 268 | 
 269 | bvec4 isnan(highp vec4 x) {
 270 | 	return bvec4(x.x != x.x, x.y != x.y, x.z != x.z, x.w != x.w);
 271 | }
 272 | 
 273 | #endif
 274 | 
 275 | #if defined(TRUNC_USED)
 276 | 
 277 | highp float trunc(highp float x) {
 278 | 	return x < 0.0 ? -floor(-x) : floor(x);
 279 | }
 280 | 
 281 | highp vec2 trunc(highp vec2 x) {
 282 | 	return vec2(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y));
 283 | }
 284 | 
 285 | highp vec3 trunc(highp vec3 x) {
 286 | 	return vec3(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z));
 287 | }
 288 | 
 289 | highp vec4 trunc(highp vec4 x) {
 290 | 	return vec4(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z), x.w < 0.0 ? -floor(-x.w) : floor(x.w));
 291 | }
 292 | 
 293 | #endif
 294 | 
 295 | #if defined(DETERMINANT_USED)
 296 | 
 297 | highp float determinant(highp mat2 m) {
 298 | 	return m[0].x * m[1].y - m[1].x * m[0].y;
 299 | }
 300 | 
 301 | highp float determinant(highp mat3 m) {
 302 | 	return m[0].x * (m[1].y * m[2].z - m[2].y * m[1].z) - m[1].x * (m[0].y * m[2].z - m[2].y * m[0].z) + m[2].x * (m[0].y * m[1].z - m[1].y * m[0].z);
 303 | }
 304 | 
 305 | highp float determinant(highp mat4 m) {
 306 | 	highp float s00 = m[2].z * m[3].w - m[3].z * m[2].w;
 307 | 	highp float s01 = m[2].y * m[3].w - m[3].y * m[2].w;
 308 | 	highp float s02 = m[2].y * m[3].z - m[3].y * m[2].z;
 309 | 	highp float s03 = m[2].x * m[3].w - m[3].x * m[2].w;
 310 | 	highp float s04 = m[2].x * m[3].z - m[3].x * m[2].z;
 311 | 	highp float s05 = m[2].x * m[3].y - m[3].x * m[2].y;
 312 | 	highp vec4 c = vec4((m[1].y * s00 - m[1].z * s01 + m[1].w * s02), -(m[1].x * s00 - m[1].z * s03 + m[1].w * s04), (m[1].x * s01 - m[1].y * s03 + m[1].w * s05), -(m[1].x * s02 - m[1].y * s04 + m[1].z * s05));
 313 | 	return m[0].x * c.x + m[0].y * c.y + m[0].z * c.z + m[0].w * c.w;
 314 | }
 315 | 
 316 | #endif
 317 | 
 318 | #if defined(INVERSE_USED)
 319 | 
 320 | highp mat2 inverse(highp mat2 m) {
 321 | 	highp float d = 1.0 / (m[0].x * m[1].y - m[1].x * m[0].y);
 322 | 	return mat2(
 323 | 			vec2(m[1].y * d, -m[0].y * d),
 324 | 			vec2(-m[1].x * d, m[0].x * d));
 325 | }
 326 | 
 327 | highp mat3 inverse(highp mat3 m) {
 328 | 	highp float c01 = m[2].z * m[1].y - m[1].z * m[2].y;
 329 | 	highp float c11 = -m[2].z * m[1].x + m[1].z * m[2].x;
 330 | 	highp float c21 = m[2].y * m[1].x - m[1].y * m[2].x;
 331 | 	highp float d = 1.0 / (m[0].x * c01 + m[0].y * c11 + m[0].z * c21);
 332 | 
 333 | 	return mat3(c01, (-m[2].z * m[0].y + m[0].z * m[2].y), (m[1].z * m[0].y - m[0].z * m[1].y),
 334 | 				   c11, (m[2].z * m[0].x - m[0].z * m[2].x), (-m[1].z * m[0].x + m[0].z * m[1].x),
 335 | 				   c21, (-m[2].y * m[0].x + m[0].y * m[2].x), (m[1].y * m[0].x - m[0].y * m[1].x)) *
 336 | 			d;
 337 | }
 338 | 
 339 | highp mat4 inverse(highp mat4 m) {
 340 | 	highp float c00 = m[2].z * m[3].w - m[3].z * m[2].w;
 341 | 	highp float c02 = m[1].z * m[3].w - m[3].z * m[1].w;
 342 | 	highp float c03 = m[1].z * m[2].w - m[2].z * m[1].w;
 343 | 
 344 | 	highp float c04 = m[2].y * m[3].w - m[3].y * m[2].w;
 345 | 	highp float c06 = m[1].y * m[3].w - m[3].y * m[1].w;
 346 | 	highp float c07 = m[1].y * m[2].w - m[2].y * m[1].w;
 347 | 
 348 | 	highp float c08 = m[2].y * m[3].z - m[3].y * m[2].z;
 349 | 	highp float c10 = m[1].y * m[3].z - m[3].y * m[1].z;
 350 | 	highp float c11 = m[1].y * m[2].z - m[2].y * m[1].z;
 351 | 
 352 | 	highp float c12 = m[2].x * m[3].w - m[3].x * m[2].w;
 353 | 	highp float c14 = m[1].x * m[3].w - m[3].x * m[1].w;
 354 | 	highp float c15 = m[1].x * m[2].w - m[2].x * m[1].w;
 355 | 
 356 | 	highp float c16 = m[2].x * m[3].z - m[3].x * m[2].z;
 357 | 	highp float c18 = m[1].x * m[3].z - m[3].x * m[1].z;
 358 | 	highp float c19 = m[1].x * m[2].z - m[2].x * m[1].z;
 359 | 
 360 | 	highp float c20 = m[2].x * m[3].y - m[3].x * m[2].y;
 361 | 	highp float c22 = m[1].x * m[3].y - m[3].x * m[1].y;
 362 | 	highp float c23 = m[1].x * m[2].y - m[2].x * m[1].y;
 363 | 
 364 | 	vec4 f0 = vec4(c00, c00, c02, c03);
 365 | 	vec4 f1 = vec4(c04, c04, c06, c07);
 366 | 	vec4 f2 = vec4(c08, c08, c10, c11);
 367 | 	vec4 f3 = vec4(c12, c12, c14, c15);
 368 | 	vec4 f4 = vec4(c16, c16, c18, c19);
 369 | 	vec4 f5 = vec4(c20, c20, c22, c23);
 370 | 
 371 | 	vec4 v0 = vec4(m[1].x, m[0].x, m[0].x, m[0].x);
 372 | 	vec4 v1 = vec4(m[1].y, m[0].y, m[0].y, m[0].y);
 373 | 	vec4 v2 = vec4(m[1].z, m[0].z, m[0].z, m[0].z);
 374 | 	vec4 v3 = vec4(m[1].w, m[0].w, m[0].w, m[0].w);
 375 | 
 376 | 	vec4 inv0 = vec4(v1 * f0 - v2 * f1 + v3 * f2);
 377 | 	vec4 inv1 = vec4(v0 * f0 - v2 * f3 + v3 * f4);
 378 | 	vec4 inv2 = vec4(v0 * f1 - v1 * f3 + v3 * f5);
 379 | 	vec4 inv3 = vec4(v0 * f2 - v1 * f4 + v2 * f5);
 380 | 
 381 | 	vec4 sa = vec4(+1, -1, +1, -1);
 382 | 	vec4 sb = vec4(-1, +1, -1, +1);
 383 | 
 384 | 	mat4 inv = mat4(inv0 * sa, inv1 * sb, inv2 * sa, inv3 * sb);
 385 | 
 386 | 	vec4 r0 = vec4(inv[0].x, inv[1].x, inv[2].x, inv[3].x);
 387 | 	vec4 d0 = vec4(m[0] * r0);
 388 | 
 389 | 	highp float d1 = (d0.x + d0.y) + (d0.z + d0.w);
 390 | 	highp float d = 1.0 / d1;
 391 | 
 392 | 	return inv * d;
 393 | }
 394 | 
 395 | #endif
 396 | 
 397 | #ifndef USE_GLES_OVER_GL
 398 | 
 399 | #if defined(TRANSPOSE_USED)
 400 | 
 401 | highp mat2 transpose(highp mat2 m) {
 402 | 	return mat2(
 403 | 			vec2(m[0].x, m[1].x),
 404 | 			vec2(m[0].y, m[1].y));
 405 | }
 406 | 
 407 | highp mat3 transpose(highp mat3 m) {
 408 | 	return mat3(
 409 | 			vec3(m[0].x, m[1].x, m[2].x),
 410 | 			vec3(m[0].y, m[1].y, m[2].y),
 411 | 			vec3(m[0].z, m[1].z, m[2].z));
 412 | }
 413 | 
 414 | #endif
 415 | 
 416 | highp mat4 transpose(highp mat4 m) {
 417 | 	return mat4(
 418 | 			vec4(m[0].x, m[1].x, m[2].x, m[3].x),
 419 | 			vec4(m[0].y, m[1].y, m[2].y, m[3].y),
 420 | 			vec4(m[0].z, m[1].z, m[2].z, m[3].z),
 421 | 			vec4(m[0].w, m[1].w, m[2].w, m[3].w));
 422 | }
 423 | 
 424 | #if defined(OUTER_PRODUCT_USED)
 425 | 
 426 | highp mat2 outerProduct(highp vec2 c, highp vec2 r) {
 427 | 	return mat2(c * r.x, c * r.y);
 428 | }
 429 | 
 430 | highp mat3 outerProduct(highp vec3 c, highp vec3 r) {
 431 | 	return mat3(c * r.x, c * r.y, c * r.z);
 432 | }
 433 | 
 434 | highp mat4 outerProduct(highp vec4 c, highp vec4 r) {
 435 | 	return mat4(c * r.x, c * r.y, c * r.z, c * r.w);
 436 | }
 437 | 
 438 | #endif
 439 | 
 440 | #endif
 441 | 
 442 | uniform highp mat4 modelview_matrix;
 443 | uniform highp mat4 extra_matrix;
 444 | attribute highp vec2 vertex; // attrib:0
 445 | 
 446 | #ifdef USE_ATTRIB_LIGHT_ANGLE
 447 | // shared with tangent, not used in canvas shader
 448 | attribute highp float light_angle; // attrib:2
 449 | #endif
 450 | 
 451 | attribute vec4 color_attrib; // attrib:3
 452 | attribute vec2 uv_attrib; // attrib:4
 453 | 
 454 | #ifdef USE_ATTRIB_MODULATE
 455 | attribute highp vec4 modulate_attrib; // attrib:5
 456 | #endif
 457 | 
 458 | // Usually, final_modulate is passed as a uniform. However during batching
 459 | // If larger fvfs are used, final_modulate is passed as an attribute.
 460 | // we need to read from the attribute in custom vertex shader
 461 | // rather than the uniform. We do this by specifying final_modulate_alias
 462 | // in shaders rather than final_modulate directly.
 463 | #ifdef USE_ATTRIB_MODULATE
 464 | #define final_modulate_alias modulate_attrib
 465 | #else
 466 | #define final_modulate_alias final_modulate
 467 | #endif
 468 | 
 469 | #ifdef USE_ATTRIB_LARGE_VERTEX
 470 | // shared with skeleton attributes, not used in batched shader
 471 | attribute highp vec2 translate_attrib; // attrib:6
 472 | attribute highp vec4 basis_attrib; // attrib:7
 473 | #endif
 474 | 
 475 | #ifdef USE_SKELETON
 476 | attribute highp vec4 bone_indices; // attrib:6
 477 | attribute highp vec4 bone_weights; // attrib:7
 478 | #endif
 479 | 
 480 | #ifdef USE_INSTANCING
 481 | 
 482 | attribute highp vec4 instance_xform0; //attrib:8
 483 | attribute highp vec4 instance_xform1; //attrib:9
 484 | attribute highp vec4 instance_xform2; //attrib:10
 485 | attribute highp vec4 instance_color; //attrib:11
 486 | 
 487 | #ifdef USE_INSTANCE_CUSTOM
 488 | attribute highp vec4 instance_custom_data; //attrib:12
 489 | #endif
 490 | 
 491 | #endif
 492 | 
 493 | #ifdef USE_SKELETON
 494 | uniform highp sampler2D skeleton_texture; // texunit:-3
 495 | uniform highp ivec2 skeleton_texture_size;
 496 | uniform highp mat4 skeleton_transform;
 497 | uniform highp mat4 skeleton_transform_inverse;
 498 | #endif
 499 | 
 500 | varying vec2 uv_interp;
 501 | varying vec4 color_interp;
 502 | 
 503 | #ifdef USE_ATTRIB_MODULATE
 504 | // modulate doesn't need interpolating but we need to send it to the fragment shader
 505 | varying vec4 modulate_interp;
 506 | #endif
 507 | 
 508 | #ifdef MODULATE_USED
 509 | uniform vec4 final_modulate;
 510 | #endif
 511 | 
 512 | uniform highp vec2 color_texpixel_size;
 513 | 
 514 | #ifdef USE_TEXTURE_RECT
 515 | 
 516 | uniform vec4 dst_rect;
 517 | uniform vec4 src_rect;
 518 | 
 519 | #endif
 520 | 
 521 | uniform highp float time;
 522 | 
 523 | #ifdef USE_LIGHTING
 524 | 
 525 | // light matrices
 526 | uniform highp mat4 light_matrix;
 527 | uniform highp mat4 light_matrix_inverse;
 528 | uniform highp mat4 light_local_matrix;
 529 | uniform highp mat4 shadow_matrix;
 530 | uniform highp vec4 light_color;
 531 | uniform highp vec4 light_shadow_color;
 532 | uniform highp vec2 light_pos;
 533 | uniform highp float shadowpixel_size;
 534 | uniform highp float shadow_gradient;
 535 | uniform highp float light_height;
 536 | uniform highp float light_outside_alpha;
 537 | uniform highp float shadow_distance_mult;
 538 | 
 539 | varying vec4 light_uv_interp;
 540 | varying vec2 transformed_light_uv;
 541 | varying vec4 local_rot;
 542 | 
 543 | #ifdef USE_SHADOWS
 544 | varying highp vec2 pos;
 545 | #endif
 546 | 
 547 | const bool at_light_pass = true;
 548 | #else
 549 | const bool at_light_pass = false;
 550 | #endif
 551 | 
 552 | /* clang-format off */
 553 | uniform highp float m_effect_start;
 554 | uniform highp float m_effect_width;
 555 | uniform highp float m_smoothness;
 556 | uniform bool m_invert_effect;
 557 | const float m_alpha_multiplier=(float(m_invert_effect) * -1.0);
 558 | 
 559 | 
 560 | /* clang-format on */
 561 | 
 562 | vec2 select(vec2 a, vec2 b, bvec2 c) {
 563 | 	vec2 ret;
 564 | 
 565 | 	ret.x = c.x ? b.x : a.x;
 566 | 	ret.y = c.y ? b.y : a.y;
 567 | 
 568 | 	return ret;
 569 | }
 570 | 
 571 | void main() {
 572 | 	vec4 color = color_attrib;
 573 | 	vec2 uv;
 574 | 
 575 | #ifdef USE_INSTANCING
 576 | 	mat4 extra_matrix_instance = extra_matrix * transpose(mat4(instance_xform0, instance_xform1, instance_xform2, vec4(0.0, 0.0, 0.0, 1.0)));
 577 | 	color *= instance_color;
 578 | 
 579 | #ifdef USE_INSTANCE_CUSTOM
 580 | 	vec4 instance_custom = instance_custom_data;
 581 | #else
 582 | 	vec4 instance_custom = vec4(0.0);
 583 | #endif
 584 | 
 585 | #else
 586 | 	mat4 extra_matrix_instance = extra_matrix;
 587 | 	vec4 instance_custom = vec4(0.0);
 588 | #endif
 589 | 
 590 | #ifdef USE_TEXTURE_RECT
 591 | 
 592 | 	if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z
 593 | 		uv = src_rect.xy + abs(src_rect.zw) * vertex.yx;
 594 | 	} else {
 595 | 		uv = src_rect.xy + abs(src_rect.zw) * vertex;
 596 | 	}
 597 | 
 598 | 	vec4 outvec = vec4(0.0, 0.0, 0.0, 1.0);
 599 | 
 600 | 	// This is what is done in the GLES 3 bindings and should
 601 | 	// take care of flipped rects.
 602 | 	//
 603 | 	// But it doesn't.
 604 | 	// I don't know why, will need to investigate further.
 605 | 
 606 | 	outvec.xy = dst_rect.xy + abs(dst_rect.zw) * select(vertex, vec2(1.0, 1.0) - vertex, lessThan(src_rect.zw, vec2(0.0, 0.0)));
 607 | 
 608 | 	// outvec.xy = dst_rect.xy + abs(dst_rect.zw) * vertex;
 609 | #else
 610 | 	vec4 outvec = vec4(vertex.xy, 0.0, 1.0);
 611 | 
 612 | 	uv = uv_attrib;
 613 | #endif
 614 | 
 615 | 	float point_size = 1.0;
 616 | 
 617 | 	{
 618 | 		vec2 src_vtx = outvec.xy;
 619 | 		/* clang-format off */
 620 | 
 621 | 
 622 | 		/* clang-format on */
 623 | 	}
 624 | 
 625 | 	gl_PointSize = point_size;
 626 | 
 627 | #ifdef USE_ATTRIB_MODULATE
 628 | 	// modulate doesn't need interpolating but we need to send it to the fragment shader
 629 | 	modulate_interp = modulate_attrib;
 630 | #endif
 631 | 
 632 | #ifdef USE_ATTRIB_LARGE_VERTEX
 633 | 	// transform is in attributes
 634 | 	vec2 temp;
 635 | 
 636 | 	temp = outvec.xy;
 637 | 	temp.x = (outvec.x * basis_attrib.x) + (outvec.y * basis_attrib.z);
 638 | 	temp.y = (outvec.x * basis_attrib.y) + (outvec.y * basis_attrib.w);
 639 | 
 640 | 	temp += translate_attrib;
 641 | 	outvec.xy = temp;
 642 | 
 643 | #else
 644 | 
 645 | 	// transform is in uniforms
 646 | #if !defined(SKIP_TRANSFORM_USED)
 647 | 	outvec = extra_matrix_instance * outvec;
 648 | 	outvec = modelview_matrix * outvec;
 649 | #endif
 650 | 
 651 | #endif // not large integer
 652 | 
 653 | 	color_interp = color;
 654 | 
 655 | #ifdef USE_PIXEL_SNAP
 656 | 	outvec.xy = floor(outvec + 0.5).xy;
 657 | 	// precision issue on some hardware creates artifacts within texture
 658 | 	// offset uv by a small amount to avoid
 659 | 	uv += 1e-5;
 660 | #endif
 661 | 
 662 | #ifdef USE_SKELETON
 663 | 
 664 | 	// look up transform from the "pose texture"
 665 | 	if (bone_weights != vec4(0.0)) {
 666 | 		highp mat4 bone_transform = mat4(0.0);
 667 | 
 668 | 		for (int i = 0; i < 4; i++) {
 669 | 			ivec2 tex_ofs = ivec2(int(bone_indices[i]) * 2, 0);
 670 | 
 671 | 			highp mat4 b = mat4(
 672 | 					texel2DFetch(skeleton_texture, skeleton_texture_size, tex_ofs + ivec2(0, 0)),
 673 | 					texel2DFetch(skeleton_texture, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
 674 | 					vec4(0.0, 0.0, 1.0, 0.0),
 675 | 					vec4(0.0, 0.0, 0.0, 1.0));
 676 | 
 677 | 			bone_transform += b * bone_weights[i];
 678 | 		}
 679 | 
 680 | 		mat4 bone_matrix = skeleton_transform * transpose(bone_transform) * skeleton_transform_inverse;
 681 | 
 682 | 		outvec = bone_matrix * outvec;
 683 | 	}
 684 | 
 685 | #endif
 686 | 
 687 | 	uv_interp = uv;
 688 | 	gl_Position = projection_matrix * outvec;
 689 | 
 690 | #ifdef USE_LIGHTING
 691 | 
 692 | 	light_uv_interp.xy = (light_matrix * outvec).xy;
 693 | 	light_uv_interp.zw = (light_local_matrix * outvec).xy;
 694 | 
 695 | 	transformed_light_uv = (mat3(light_matrix_inverse) * vec3(light_uv_interp.zw, 0.0)).xy; //for normal mapping
 696 | 
 697 | #ifdef USE_SHADOWS
 698 | 	pos = outvec.xy;
 699 | #endif
 700 | 
 701 | #ifdef USE_ATTRIB_LIGHT_ANGLE
 702 | 	// we add a fixed offset because we are using the sign later,
 703 | 	// and don't want floating point error around 0.0
 704 | 	float la = abs(light_angle) - 1.0;
 705 | 
 706 | 	// vector light angle
 707 | 	vec4 vla;
 708 | 	vla.xy = vec2(cos(la), sin(la));
 709 | 	vla.zw = vec2(-vla.y, vla.x);
 710 | 
 711 | 	// vertical flip encoded in the sign
 712 | 	vla.zw *= sign(light_angle);
 713 | 
 714 | 	// apply the transform matrix.
 715 | 	// The rotate will be encoded in the transform matrix for single rects,
 716 | 	// and just the flips in the light angle.
 717 | 	// For batching we will encode the rotation and the flips
 718 | 	// in the light angle, and can use the same shader.
 719 | 	local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.xy, 0.0, 0.0))).xy);
 720 | 	local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.zw, 0.0, 0.0))).xy);
 721 | #else
 722 | 	local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(1.0, 0.0, 0.0, 0.0))).xy);
 723 | 	local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(0.0, 1.0, 0.0, 0.0))).xy);
 724 | #ifdef USE_TEXTURE_RECT
 725 | 	local_rot.xy *= sign(src_rect.z);
 726 | 	local_rot.zw *= sign(src_rect.w);
 727 | #endif
 728 | #endif // not using light angle
 729 | 
 730 | #endif
 731 | }
 732 | 
 733 | /* clang-format off */
 734 | 
 drivers/gles2/shader_gles2.cpp:126 - CanvasShaderGLES2: Vertex shader compilation failed:
0(557) : error C1059: non constant expression in initialization

 drivers/gles2/shader_gles2.cpp:296 - Method failed. Returning: nullptr
 drivers/gles2/shader_gles2.cpp:87 - Condition "!version" is true. Returned: false
 drivers/gles2/shader_gles2.h:258 - Condition "!version" is true. Returned: -1
 drivers/gles2/shader_gles2.h:258 - Condition "!version" is true. Returned: -1
 drivers/gles2/shader_gles2.h:258 - Condition "!version" is true. Returned: -1
 drivers/gles2/shader_gles2.h:258 - Condition "!version" is true. Returned: -1
 drivers/gles2/shader_gles2.h:258 - Condition "!version" is true. Returned: -1
 drivers/gles2/shader_gles2.h:258 - Condition "!version" is true. Returned: -1

Steps to reproduce

The lines that trigger the bug are:

uniform bool invert_effect = false;
const float alpha_multiplier = float(invert_effect) * -1.0;

I tried to take away the const keyword but the editor marks it as an error.

In the repro example, open the scene "bug_demo.tscn", then inspect the sprite called "slash", then check the ShaderMaterial and then the shader inside it. Uncomment the line below the comment saying it's the following line.

Minimal reproduction project

shader_bug_demo.zip

@clayjohn
Copy link
Member

The issue here is that you are using a non-constant variable (invert_effect) in the definition of a constant (const float alpha_multiplier) Constant definitions must be constants i.e. 1.0 or constant expressions 1.0 - 2.0 they can not be variables i.e. invert_effect

The Godot shader compiler should provide an error with line highlighting in this case though. It should not fall through to the GLSL compiler.

@clayjohn clayjohn added this to the 3.x milestone Jan 31, 2023
@obfuscatedgenerated
Copy link
Author

I did think that but I thought it was weird for Godot to tell me off for it, I'll give it a try

@clayjohn clayjohn modified the milestones: 3.x, 4.x Jan 31, 2023
@clayjohn clayjohn added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jan 31, 2023
@clayjohn
Copy link
Member

clayjohn commented Jan 31, 2023

Marking as 4.x with cherrypick to 3.x as 4.x doesn't catch this error either, it falls through to the GLSL compiler as well.

CC @Chaosus

@obfuscatedgenerated
Copy link
Author

Thanks for your reply,

I've tried removing the const keyword but I think Godot is refusing to compile my shader now as the shader param options are gone. Is there a way I can force Godot to compile it or is it a fatal error?

Error log:

    1 | shader_type canvas_item;
    2 | 
    3 | uniform float effect_start = 1;
    4 | uniform float effect_width = 0.5;
    5 | uniform float smoothness = 0.1;
    6 | uniform bool invert_effect = false;
    7 | 
    8 | // UNCOMMENT THIS LINE BELOW TO DEMO THE BUG \/
E   9-> float alpha_multiplier = float(invert_effect) * -1.0;
   10 | 
   11 | void fragment(){
   12 | 	COLOR = texture(TEXTURE, UV);
   13 |     COLOR.a -= smoothstep(effect_start, effect_start + smoothness, UV.y);
   14 | 	COLOR.a += smoothstep(effect_start + effect_width, effect_start + effect_width + smoothness, UV.y); // todo: could make trasparent solid?
   15 | }
 :9 - Expected 'const' keyword before constant definition

@obfuscatedgenerated
Copy link
Author

Not sure how relevant it is now, but I'd also like to add that I've just updated my GPU drivers to the latest version (528.24) and the issue still persists

@clayjohn
Copy link
Member

That is no longer a valid shader. To be in the global namespace it needs to be a constant or a uniform. For that to work the definition needs to be inside of fragment(). The error is correct in that case

@clayjohn
Copy link
Member

Not sure how relevant it is now, but I'd also like to add that I've just updated my GPU drivers to the latest version (528.24) and the issue still persists

Updating GPU drivers won't help here. You are writing invalid code and the compiler is rightfully failing to compile. On our end we need to make the compiler error easier to understand so that it helps you write correct code.

@obfuscatedgenerated
Copy link
Author

That is no longer a valid shader. To be in the global namespace it needs to be a constant or a uniform. For that to work the definition needs to be inside of fragment(). The error is correct in that case

Thank you for your help, this fixed my problem. Should I leave this issue open if you're intending to improve the error raised?

@clayjohn
Copy link
Member

Thank you for your help, this fixed my problem. Should I leave this issue open if you're intending to improve the error raised?

Yes please

@Chaosus Chaosus self-assigned this Jan 31, 2023
@akien-mga akien-mga modified the milestones: 4.x, 4.0 Feb 2, 2023
@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 2, 2023
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.

4 participants