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

GLES3 3D Scene shader compile error with combination of Vertex Lighting + Oren-Nayar #56799

Closed
jnlopar opened this issue Jan 14, 2022 · 2 comments

Comments

@jnlopar
Copy link

jnlopar commented Jan 14, 2022

Godot version

3.5-beta1

System information

MacOS 12.1, AMD Radeon Pro 5300M 4GB, GLES3

Issue description

When using the combination of the Oren-Nayar diffuse model and the Vertex Lighting flag, SpatialMaterial shaders fail to compile. This appears to be a simple case of a missing identifier, as the shader attempts to access diffuse_color which does not exist in its current scope (but diffuse does). I believe this bug may have been around for some time (years even?) but the combination of options is likely rare enough to not be used in that combination very often. scene.glsl:215 in 3.x

I have a s/diffuse_color/diffuse PR one-liner ready if you'd like, but I'll wait for the go-ahead from maintainers as the guideliness prefer PRs for the main dev branch and this appears to be a 3.x-specific issue.

I did try to get things up and running in 4.x dev, as the GLES3 scene shader there has the same code, but it appears that Oren-Nayar is no longer a diffuse mode option in 4.x since #45023 and thus that codepath is likely never hit by the preprocessor in 4.x. #49418 was the only similar reference I found, but I believe that was around forward-porting it into the new shaders for 4.x.

Screenshot w/bug, 3.5-beta1:
shader_bug_3 5-beta1

Screenshot w/shader patched 3.5-beta1:
shader_patched_3 5-beta1

Compilation log:

Godot Engine v3.5.beta1.official (c) 2007-2021 Juan Linietsky, Ariel Manzur & Godot Contributors.
--- GDScript language server started ---
Switch Scene Tab
   1 | #version 330
   2 | #define GLES_OVER_GL
   3 | #define MAX_LIGHT_DATA_STRUCTS 409
   4 | 
   5 | #define MAX_FORWARD_LIGHTS 32
   6 | 
   7 | #define MAX_REFLECTION_DATA_STRUCTS 455
   8 | 
   9 | #define MAX_SKELETON_BONES 1365
  10 | 
  11 | #define ENABLE_OCTAHEDRAL_COMPRESSION
  12 | #define USE_VERTEX_LIGHTING
  13 | #define USE_FORWARD_LIGHTING
  14 | #define USE_RADIANCE_MAP
  15 | #define USE_RADIANCE_MAP_ARRAY
  16 | #define SHADOW_MODE_PCF_5
  17 | #define USE_SHADOW
  18 | #define USE_LIGHTMAP_FILTER_BICUBIC
  19 | #define DIFFUSE_OREN_NAYAR
  20 | #define SPECULAR_SCHLICK_GGX
  21 | #define USE_MATERIAL
  22 | #define ENABLE_UV_INTERP
  23 | precision highp float;
  24 | precision highp int;
  25 | 
  26 | #if defined(IS_UBERSHADER)
  27 | uniform highp int ubershader_flags;
  28 | #endif
  29 | 
  30 | #define M_PI 3.14159265359
  31 | 
  32 | #define SHADER_IS_SRGB false
  33 | 
  34 | /*
  35 | from VisualServer:
  36 | 
  37 | ARRAY_VERTEX=0,
  38 | ARRAY_NORMAL=1,
  39 | ARRAY_TANGENT=2,
  40 | ARRAY_COLOR=3,
  41 | ARRAY_TEX_UV=4,
  42 | ARRAY_TEX_UV2=5,
  43 | ARRAY_BONES=6,
  44 | ARRAY_WEIGHTS=7,
  45 | ARRAY_INDEX=8,
  46 | */
  47 | 
  48 | // hack to use uv if no uv present so it works with lightmap
  49 | 
  50 | /* INPUT ATTRIBS */
  51 | 
  52 | layout(location = 0) in highp vec4 vertex_attrib;
  53 | /* clang-format on */
  54 | #ifdef ENABLE_OCTAHEDRAL_COMPRESSION //ubershader-skip
  55 | layout(location = 2) in vec4 normal_tangent_attrib;
  56 | #else //ubershader-skip
  57 | layout(location = 1) in vec3 normal_attrib;
  58 | #endif //ubershader-skip
  59 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
  60 | #ifdef ENABLE_OCTAHEDRAL_COMPRESSION //ubershader-skip
  61 | // packed into normal_attrib zw component
  62 | #else //ubershader-skip
  63 | layout(location = 2) in vec4 normal_tangent_attrib; //ubershader-skip
  64 | #endif //ubershader-skip
  65 | #endif
  66 | 
  67 | #if defined(ENABLE_COLOR_INTERP)
  68 | layout(location = 3) in vec4 color_attrib;
  69 | #endif
  70 | 
  71 | #if defined(ENABLE_UV_INTERP)
  72 | layout(location = 4) in vec2 uv_attrib;
  73 | #endif
  74 | 
  75 | #if defined(ENABLE_UV2_INTERP)
  76 | layout(location = 5) in vec2 uv2_attrib;
  77 | #else
  78 | #ifdef USE_LIGHTMAP //ubershader-skip
  79 | layout(location = 5) in vec2 uv2_attrib;
  80 | #endif //ubershader-skip
  81 | #endif
  82 | 
  83 | #ifdef USE_SKELETON //ubershader-skip
  84 | layout(location = 6) in uvec4 bone_indices; // attrib:6
  85 | layout(location = 7) in highp vec4 bone_weights; // attrib:7
  86 | #endif //ubershader-skip
  87 | 
  88 | #ifdef USE_INSTANCING //ubershader-skip
  89 | 
  90 | layout(location = 8) in highp vec4 instance_xform0;
  91 | layout(location = 9) in highp vec4 instance_xform1;
  92 | layout(location = 10) in highp vec4 instance_xform2;
  93 | layout(location = 11) in lowp vec4 instance_color;
  94 | 
  95 | #if defined(ENABLE_INSTANCE_CUSTOM)
  96 | layout(location = 12) in highp vec4 instance_custom_data;
  97 | #endif
  98 | 
  99 | #endif //ubershader-skip
 100 | 
 101 | layout(std140) uniform SceneData { // ubo:0
 102 | 
 103 | 	highp mat4 projection_matrix;
 104 | 	highp mat4 inv_projection_matrix;
 105 | 	highp mat4 camera_inverse_matrix;
 106 | 	highp mat4 camera_matrix;
 107 | 
 108 | 	mediump vec4 ambient_light_color;
 109 | 	mediump vec4 bg_color;
 110 | 
 111 | 	mediump vec4 fog_color_enabled;
 112 | 	mediump vec4 fog_sun_color_amount;
 113 | 
 114 | 	mediump float ambient_energy;
 115 | 	mediump float bg_energy;
 116 | 
 117 | 	mediump float z_offset;
 118 | 	mediump float z_slope_scale;
 119 | 	highp float shadow_dual_paraboloid_render_zfar;
 120 | 	highp float shadow_dual_paraboloid_render_side;
 121 | 
 122 | 	highp vec2 viewport_size;
 123 | 	highp vec2 screen_pixel_size;
 124 | 	highp vec2 shadow_atlas_pixel_size;
 125 | 	highp vec2 directional_shadow_pixel_size;
 126 | 
 127 | 	highp float time;
 128 | 	highp float z_far;
 129 | 	mediump float reflection_multiplier;
 130 | 	mediump float subsurface_scatter_width;
 131 | 	mediump float ambient_occlusion_affect_light;
 132 | 	mediump float ambient_occlusion_affect_ao_channel;
 133 | 	mediump float opaque_prepass_threshold;
 134 | 
 135 | 	bool fog_depth_enabled;
 136 | 	highp float fog_depth_begin;
 137 | 	highp float fog_depth_end;
 138 | 	mediump float fog_density;
 139 | 	highp float fog_depth_curve;
 140 | 	bool fog_transmit_enabled;
 141 | 	highp float fog_transmit_curve;
 142 | 	bool fog_height_enabled;
 143 | 	highp float fog_height_min;
 144 | 	highp float fog_height_max;
 145 | 	highp float fog_height_curve;
 146 | 
 147 | 	int view_index;
 148 | };
 149 | 
 150 | uniform highp mat4 world_transform;
 151 | 
 152 | #ifdef USE_LIGHTMAP //ubershader-skip
 153 | uniform highp vec4 lightmap_uv_rect;
 154 | #endif //ubershader-skip
 155 | 
 156 | #ifdef USE_LIGHT_DIRECTIONAL //ubershader-skip
 157 | 
 158 | layout(std140) uniform DirectionalLightData { //ubo:3
 159 | 
 160 | 	highp vec4 light_pos_inv_radius;
 161 | 	mediump vec4 light_direction_attenuation;
 162 | 	mediump vec4 light_color_energy;
 163 | 	mediump vec4 light_params; // cone attenuation, angle, specular, shadow enabled,
 164 | 	mediump vec4 light_clamp;
 165 | 	mediump vec4 shadow_color_contact;
 166 | 	highp mat4 shadow_matrix1;
 167 | 	highp mat4 shadow_matrix2;
 168 | 	highp mat4 shadow_matrix3;
 169 | 	highp mat4 shadow_matrix4;
 170 | 	mediump vec4 shadow_split_offsets;
 171 | };
 172 | 
 173 | #endif //ubershader-skip
 174 | 
 175 | #ifdef USE_VERTEX_LIGHTING //ubershader-skip
 176 | //omni and spot
 177 | 
 178 | struct LightData {
 179 | 	highp vec4 light_pos_inv_radius;
 180 | 	mediump vec4 light_direction_attenuation;
 181 | 	mediump vec4 light_color_energy;
 182 | 	mediump vec4 light_params; // cone attenuation, angle, specular, shadow enabled,
 183 | 	mediump vec4 light_clamp;
 184 | 	mediump vec4 shadow_color_contact;
 185 | 	highp mat4 shadow_matrix;
 186 | };
 187 | 
 188 | layout(std140) uniform OmniLightData { //ubo:4
 189 | 
 190 | 	LightData omni_lights[MAX_LIGHT_DATA_STRUCTS];
 191 | };
 192 | 
 193 | layout(std140) uniform SpotLightData { //ubo:5
 194 | 
 195 | 	LightData spot_lights[MAX_LIGHT_DATA_STRUCTS];
 196 | };
 197 | 
 198 | #ifdef USE_FORWARD_LIGHTING //ubershader-skip
 199 | 
 200 | uniform int omni_light_indices[MAX_FORWARD_LIGHTS];
 201 | uniform int omni_light_count;
 202 | 
 203 | uniform int spot_light_indices[MAX_FORWARD_LIGHTS];
 204 | uniform int spot_light_count;
 205 | 
 206 | #endif //ubershader-skip
 207 | 
 208 | out vec4 diffuse_light_interp;
 209 | out vec4 specular_light_interp;
 210 | 
 211 | void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float roughness, inout vec3 diffuse, inout vec3 specular) {
 212 | 	float NdotL = dot(N, L);
 213 | 	float cNdotL = max(NdotL, 0.0); // clamped NdotL
 214 | 	float NdotV = dot(N, V);
 215 | 	float cNdotV = max(NdotV, 0.0);
 216 | 
 217 | #if defined(DIFFUSE_OREN_NAYAR)
 218 | 	vec3 diffuse_brdf_NL;
 219 | #else
 220 | 	float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance
 221 | #endif
 222 | 
 223 | #if defined(DIFFUSE_LAMBERT_WRAP)
 224 | 	// energy conserving lambert wrap shader
 225 | 	diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
 226 | 
 227 | #elif defined(DIFFUSE_OREN_NAYAR)
 228 | 
 229 | 	{
 230 | 		// see http://mimosa-pudica.net/improved-oren-nayar.html
 231 | 		float LdotV = dot(L, V);
 232 | 
 233 | 		float s = LdotV - NdotL * NdotV;
 234 | 		float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
 235 | 
 236 | 		float sigma2 = roughness * roughness; // TODO: this needs checking
 237 | 		vec3 A = 1.0 + sigma2 * (-0.5 / (sigma2 + 0.33) + 0.17 * diffuse_color / (sigma2 + 0.13));
 238 | 		float B = 0.45 * sigma2 / (sigma2 + 0.09);
 239 | 
 240 | 		diffuse_brdf_NL = cNdotL * (A + vec3(B) * s / t) * (1.0 / M_PI);
 241 | 	}
 242 | #else
 243 | 	// lambert by default for everything else
 244 | 	diffuse_brdf_NL = cNdotL * (1.0 / M_PI);
 245 | #endif
 246 | 
 247 | 	diffuse += light_color * diffuse_brdf_NL;
 248 | 
 249 | 	if (roughness > 0.0) {
 250 | 		// D
 251 | 		float specular_brdf_NL = 0.0;
 252 | 
 253 | #if !defined(SPECULAR_DISABLED)
 254 | 		//normalized blinn always unless disabled
 255 | 		vec3 H = normalize(V + L);
 256 | 		float cNdotH = max(dot(N, H), 0.0);
 257 | 		float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
 258 | 		float blinn = pow(cNdotH, shininess);
 259 | 		blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));
 260 | 		specular_brdf_NL = blinn;
 261 | #endif
 262 | 
 263 | 		specular += specular_brdf_NL * light_color;
 264 | 	}
 265 | }
 266 | 
 267 | #ifdef USE_PHYSICAL_LIGHT_ATTENUATION
 268 | float get_omni_attenuation(float distance, float inv_range, float decay) {
 269 | 	float nd = distance * inv_range;
 270 | 	nd *= nd;
 271 | 	nd *= nd; // nd^4
 272 | 	nd = max(1.0 - nd, 0.0);
 273 | 	nd *= nd; // nd^2
 274 | 	return nd * pow(max(distance, 0.0001), -decay);
 275 | }
 276 | #endif
 277 | 
 278 | void light_process_omni(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) {
 279 | 	vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz - vertex;
 280 | 	float light_length = length(light_rel_vec);
 281 | 
 282 | #ifdef USE_PHYSICAL_LIGHT_ATTENUATION
 283 | 	vec3 light_attenuation = vec3(get_omni_attenuation(light_length, omni_lights[idx].light_pos_inv_radius.w, omni_lights[idx].light_direction_attenuation.w));
 284 | #else
 285 | 	float normalized_distance = light_length * omni_lights[idx].light_pos_inv_radius.w;
 286 | 	vec3 light_attenuation = vec3(pow(max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w));
 287 | #endif
 288 | 
 289 | 	light_compute(normal, normalize(light_rel_vec), eye_vec, omni_lights[idx].light_color_energy.rgb * light_attenuation, roughness, diffuse, specular);
 290 | }
 291 | 
 292 | void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) {
 293 | 	vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz - vertex;
 294 | 	float light_length = length(light_rel_vec);
 295 | 
 296 | #ifdef USE_PHYSICAL_LIGHT_ATTENUATION
 297 | 	vec3 light_attenuation = vec3(get_omni_attenuation(light_length, spot_lights[idx].light_pos_inv_radius.w, spot_lights[idx].light_direction_attenuation.w));
 298 | #else
 299 | 	float normalized_distance = light_length * spot_lights[idx].light_pos_inv_radius.w;
 300 | 	vec3 light_attenuation = vec3(pow(max(1.0 - normalized_distance, 0.001), spot_lights[idx].light_direction_attenuation.w));
 301 | #endif
 302 | 
 303 | 	vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz;
 304 | 	float spot_cutoff = spot_lights[idx].light_params.y;
 305 | 	float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
 306 | 	float spot_rim = (1.0 - scos) / (1.0 - spot_cutoff);
 307 | 	light_attenuation *= 1.0 - pow(max(spot_rim, 0.001), spot_lights[idx].light_params.x);
 308 | 
 309 | 	light_compute(normal, normalize(light_rel_vec), eye_vec, spot_lights[idx].light_color_energy.rgb * light_attenuation, roughness, diffuse, specular);
 310 | }
 311 | 
 312 | #endif //ubershader-skip
 313 | 
 314 | #ifdef ENABLE_OCTAHEDRAL_COMPRESSION //ubershader-skip
 315 | vec3 oct_to_vec3(vec2 e) {
 316 | 	vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
 317 | 	float t = max(-v.z, 0.0);
 318 | 	v.xy += t * -sign(v.xy);
 319 | 	return normalize(v);
 320 | }
 321 | #endif //ubershader-skip
 322 | 
 323 | /* Varyings */
 324 | 
 325 | out highp vec3 vertex_interp;
 326 | out vec3 normal_interp;
 327 | 
 328 | #if defined(ENABLE_COLOR_INTERP)
 329 | out vec4 color_interp;
 330 | #endif
 331 | 
 332 | #if defined(ENABLE_UV_INTERP)
 333 | out vec2 uv_interp;
 334 | #endif
 335 | 
 336 | #if defined(ENABLE_UV2_INTERP)
 337 | out vec2 uv2_interp;
 338 | #else
 339 | #ifdef USE_LIGHTMAP //ubershader-skip
 340 | out vec2 uv2_interp;
 341 | #endif //ubershader-skip
 342 | #endif
 343 | 
 344 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 345 | out vec3 tangent_interp;
 346 | out vec3 binormal_interp;
 347 | #endif
 348 | 
 349 | #if defined(USE_MATERIAL)
 350 | 
 351 | /* clang-format off */
 352 | layout(std140) uniform UniformData { // ubo:1
 353 | vec4 m_albedo;
 354 | float m_specular;
 355 | float m_metallic;
 356 | float m_roughness;
 357 | float m_point_size;
 358 | vec3 m_uv1_scale;
 359 | vec3 m_uv1_offset;
 360 | vec3 m_uv2_scale;
 361 | vec3 m_uv2_offset;
 362 | 
 363 | 
 364 | };
 365 | /* clang-format on */
 366 | 
 367 | #endif
 368 | 
 369 | /* clang-format off */
 370 | uniform sampler2D m_texture_albedo;
 371 | 
 372 | 
 373 | /* clang-format on */
 374 | 
 375 | #ifdef RENDER_DEPTH_DUAL_PARABOLOID //ubershader-skip
 376 | 
 377 | out highp float dp_clip;
 378 | 
 379 | #endif //ubershader-skip
 380 | 
 381 | #define SKELETON_TEXTURE_WIDTH 256
 382 | 
 383 | #ifdef USE_SKELETON //ubershader-skip
 384 | uniform highp sampler2D skeleton_texture; // texunit:-1
 385 | #endif //ubershader-skip
 386 | 
 387 | out highp vec4 position_interp;
 388 | 
 389 | // FIXME: This triggers a Mesa bug that breaks rendering, so disabled for now.
 390 | // See GH-13450 and https://bugs.freedesktop.org/show_bug.cgi?id=100316
 391 | //invariant gl_Position;
 392 | 
 393 | void main() {
 394 | 	highp vec4 vertex = vertex_attrib; // vec4(vertex_attrib.xyz * data_attrib.x,1.0);
 395 | 
 396 | 	highp mat4 world_matrix = world_transform;
 397 | 
 398 | #ifdef USE_INSTANCING //ubershader-runtime
 399 | 
 400 | 	{
 401 | 		highp mat4 m = mat4(instance_xform0, instance_xform1, instance_xform2, vec4(0.0, 0.0, 0.0, 1.0));
 402 | 		world_matrix = world_matrix * transpose(m);
 403 | 	}
 404 | #endif //ubershader-runtime
 405 | 
 406 | 	vec3 normal;
 407 | #ifdef ENABLE_OCTAHEDRAL_COMPRESSION //ubershader-runtime
 408 | 	normal = oct_to_vec3(normal_tangent_attrib.xy);
 409 | #else //ubershader-runtime
 410 | 	normal = normal_attrib;
 411 | #endif //ubershader-runtime
 412 | 
 413 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 414 | 	vec3 tangent;
 415 | 	float binormalf;
 416 | #ifdef ENABLE_OCTAHEDRAL_COMPRESSION //ubershader-runtime
 417 | 	tangent = oct_to_vec3(vec2(normal_tangent_attrib.z, abs(normal_tangent_attrib.w) * 2.0 - 1.0));
 418 | 	binormalf = sign(normal_tangent_attrib.w);
 419 | #else //ubershader-runtime
 420 | 	tangent = normal_tangent_attrib.xyz;
 421 | 	binormalf = normal_tangent_attrib.a;
 422 | #endif //ubershader-runtime
 423 | #endif
 424 | 
 425 | #if defined(ENABLE_COLOR_INTERP)
 426 | 	color_interp = color_attrib;
 427 | #ifdef USE_INSTANCING //ubershader-runtime
 428 | 	color_interp *= instance_color;
 429 | #endif //ubershader-runtime
 430 | 
 431 | #endif
 432 | 
 433 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 434 | 	vec3 binormal = normalize(cross(normal, tangent) * binormalf);
 435 | #endif
 436 | 
 437 | #if defined(ENABLE_UV_INTERP)
 438 | 	uv_interp = uv_attrib;
 439 | #endif
 440 | 
 441 | #ifdef USE_LIGHTMAP //ubershader-runtime
 442 | 	uv2_interp = lightmap_uv_rect.zw * uv2_attrib + lightmap_uv_rect.xy;
 443 | #else //ubershader-runtime
 444 | #if defined(ENABLE_UV2_INTERP)
 445 | 	uv2_interp = uv2_attrib;
 446 | #endif
 447 | #endif //ubershader-runtime
 448 | 
 449 | #if defined(OVERRIDE_POSITION)
 450 | 	highp vec4 position;
 451 | #endif
 452 | 
 453 | 	vec4 instance_custom;
 454 | #ifdef USE_INSTANCING //ubershader-runtime
 455 | #if defined(ENABLE_INSTANCE_CUSTOM)
 456 | 	instance_custom = instance_custom_data;
 457 | #else
 458 | 	instance_custom = vec4(0.0);
 459 | #endif
 460 | #else //ubershader-runtime
 461 | 	instance_custom = vec4(0.0);
 462 | #endif //ubershader-runtime
 463 | 
 464 | 	highp mat4 local_projection = projection_matrix;
 465 | 
 466 | //using world coordinates
 467 | #if !defined(SKIP_TRANSFORM_USED) && defined(VERTEX_WORLD_COORDS_USED)
 468 | 
 469 | 	vertex = world_matrix * vertex;
 470 | 
 471 | #if defined(ENSURE_CORRECT_NORMALS)
 472 | 	mat3 normal_matrix = mat3(transpose(inverse(world_matrix)));
 473 | 	normal = normal_matrix * normal;
 474 | #else
 475 | 	normal = normalize((world_matrix * vec4(normal, 0.0)).xyz);
 476 | #endif
 477 | 
 478 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 479 | 
 480 | 	tangent = normalize((world_matrix * vec4(tangent, 0.0)).xyz);
 481 | 	binormal = normalize((world_matrix * vec4(binormal, 0.0)).xyz);
 482 | #endif
 483 | #endif
 484 | 
 485 | 	float roughness = 1.0;
 486 | 
 487 | //defines that make writing custom shaders easier
 488 | #define projection_matrix local_projection
 489 | #define world_transform world_matrix
 490 | 
 491 | #ifdef USE_SKELETON //ubershader-runtime
 492 | 	{
 493 | 		//skeleton transform
 494 | 		ivec4 bone_indicesi = ivec4(bone_indices); // cast to signed int
 495 | 
 496 | 		ivec2 tex_ofs = ivec2(bone_indicesi.x % 256, (bone_indicesi.x / 256) * 3);
 497 | 		highp mat4 m;
 498 | 		m = mat4(
 499 | 					texelFetch(skeleton_texture, tex_ofs, 0),
 500 | 					texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
 501 | 					texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0),
 502 | 					vec4(0.0, 0.0, 0.0, 1.0)) *
 503 | 				bone_weights.x;
 504 | 
 505 | 		tex_ofs = ivec2(bone_indicesi.y % 256, (bone_indicesi.y / 256) * 3);
 506 | 
 507 | 		m += mat4(
 508 | 					 texelFetch(skeleton_texture, tex_ofs, 0),
 509 | 					 texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
 510 | 					 texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0),
 511 | 					 vec4(0.0, 0.0, 0.0, 1.0)) *
 512 | 				bone_weights.y;
 513 | 
 514 | 		tex_ofs = ivec2(bone_indicesi.z % 256, (bone_indicesi.z / 256) * 3);
 515 | 
 516 | 		m += mat4(
 517 | 					 texelFetch(skeleton_texture, tex_ofs, 0),
 518 | 					 texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
 519 | 					 texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0),
 520 | 					 vec4(0.0, 0.0, 0.0, 1.0)) *
 521 | 				bone_weights.z;
 522 | 
 523 | 		tex_ofs = ivec2(bone_indicesi.w % 256, (bone_indicesi.w / 256) * 3);
 524 | 
 525 | 		m += mat4(
 526 | 					 texelFetch(skeleton_texture, tex_ofs, 0),
 527 | 					 texelFetch(skeleton_texture, tex_ofs + ivec2(0, 1), 0),
 528 | 					 texelFetch(skeleton_texture, tex_ofs + ivec2(0, 2), 0),
 529 | 					 vec4(0.0, 0.0, 0.0, 1.0)) *
 530 | 				bone_weights.w;
 531 | 
 532 | 		world_matrix = world_matrix * transpose(m);
 533 | 	}
 534 | #endif //ubershader-runtime
 535 | 
 536 | 	float point_size = 1.0;
 537 | 
 538 | 	highp mat4 modelview = camera_inverse_matrix * world_matrix;
 539 | 	{
 540 | 		/* clang-format off */
 541 | 	{
 542 | 		roughness=m_roughness;
 543 | 		uv_interp=((uv_interp*m_uv1_scale.xy)+m_uv1_offset.xy);
 544 | 	}
 545 | 
 546 | 
 547 | 		/* clang-format on */
 548 | 	}
 549 | 
 550 | 	gl_PointSize = point_size;
 551 | 
 552 | // using local coordinates (default)
 553 | #if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED)
 554 | 
 555 | 	vertex = modelview * vertex;
 556 | 
 557 | #if defined(ENSURE_CORRECT_NORMALS)
 558 | 	mat3 normal_matrix = mat3(transpose(inverse(modelview)));
 559 | 	normal = normal_matrix * normal;
 560 | #else
 561 | 	normal = normalize((modelview * vec4(normal, 0.0)).xyz);
 562 | #endif
 563 | 
 564 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 565 | 
 566 | 	tangent = normalize((modelview * vec4(tangent, 0.0)).xyz);
 567 | 	binormal = normalize((modelview * vec4(binormal, 0.0)).xyz);
 568 | #endif
 569 | #endif
 570 | 
 571 | //using world coordinates
 572 | #if !defined(SKIP_TRANSFORM_USED) && defined(VERTEX_WORLD_COORDS_USED)
 573 | 
 574 | 	vertex = camera_inverse_matrix * vertex;
 575 | 	normal = normalize((camera_inverse_matrix * vec4(normal, 0.0)).xyz);
 576 | 
 577 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 578 | 
 579 | 	tangent = normalize((camera_inverse_matrix * vec4(tangent, 0.0)).xyz);
 580 | 	binormal = normalize((camera_inverse_matrix * vec4(binormal, 0.0)).xyz);
 581 | #endif
 582 | #endif
 583 | 
 584 | 	vertex_interp = vertex.xyz;
 585 | 	normal_interp = normal;
 586 | 
 587 | #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
 588 | 	tangent_interp = tangent;
 589 | 	binormal_interp = binormal;
 590 | #endif
 591 | 
 592 | #ifdef RENDER_DEPTH //ubershader-runtime
 593 | 
 594 | #ifdef RENDER_DEPTH_DUAL_PARABOLOID //ubershader-runtime
 595 | 
 596 | 	vertex_interp.z *= shadow_dual_paraboloid_render_side;
 597 | 	normal_interp.z *= shadow_dual_paraboloid_render_side;
 598 | 
 599 | 	dp_clip = vertex_interp.z; //this attempts to avoid noise caused by objects sent to the other parabolloid side due to bias
 600 | 
 601 | 	//for dual paraboloid shadow mapping, this is the fastest but least correct way, as it curves straight edges
 602 | 
 603 | 	highp vec3 vtx = vertex_interp + normalize(vertex_interp) * z_offset;
 604 | 	highp float distance = length(vtx);
 605 | 	vtx = normalize(vtx);
 606 | 	vtx.xy /= 1.0 - vtx.z;
 607 | 	vtx.z = (distance / shadow_dual_paraboloid_render_zfar);
 608 | 	vtx.z = vtx.z * 2.0 - 1.0;
 609 | 
 610 | 	vertex_interp = vtx;
 611 | 
 612 | #else //ubershader-runtime
 613 | 
 614 | 	float z_ofs = z_offset;
 615 | 	z_ofs += (1.0 - abs(normal_interp.z)) * z_slope_scale;
 616 | 	vertex_interp.z -= z_ofs;
 617 | 
 618 | #endif //RENDER_DEPTH_DUAL_PARABOLOID //ubershader-runtime
 619 | 
 620 | #endif //RENDER_DEPTH //ubershader-runtime
 621 | 
 622 | #if defined(OVERRIDE_POSITION)
 623 | 	gl_Position = position;
 624 | #else
 625 | 	gl_Position = projection_matrix * vec4(vertex_interp, 1.0);
 626 | #endif
 627 | 
 628 | 	position_interp = gl_Position;
 629 | 
 630 | #ifdef USE_VERTEX_LIGHTING //ubershader-runtime
 631 | 
 632 | 	diffuse_light_interp = vec4(0.0);
 633 | 	specular_light_interp = vec4(0.0);
 634 | 
 635 | #ifdef USE_FORWARD_LIGHTING //ubershader-runtime
 636 | 
 637 | 	for (int i = 0; i < omni_light_count; i++) {
 638 | 		light_process_omni(omni_light_indices[i], vertex_interp, -normalize(vertex_interp), normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
 639 | 	}
 640 | 
 641 | 	for (int i = 0; i < spot_light_count; i++) {
 642 | 		light_process_spot(spot_light_indices[i], vertex_interp, -normalize(vertex_interp), normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
 643 | 	}
 644 | #endif //ubershader-runtime
 645 | 
 646 | #ifdef USE_LIGHT_DIRECTIONAL //ubershader-runtime
 647 | 
 648 | 	vec3 directional_diffuse = vec3(0.0);
 649 | 	vec3 directional_specular = vec3(0.0);
 650 | 	light_compute(normal_interp, -light_direction_attenuation.xyz, -normalize(vertex_interp), light_color_energy.rgb, roughness, directional_diffuse, directional_specular);
 651 | 
 652 | 	float diff_avg = dot(diffuse_light_interp.rgb, vec3(0.33333));
 653 | 	float diff_dir_avg = dot(directional_diffuse, vec3(0.33333));
 654 | 	if (diff_avg > 0.0) {
 655 | 		diffuse_light_interp.a = diff_dir_avg / (diff_avg + diff_dir_avg);
 656 | 	} else {
 657 | 		diffuse_light_interp.a = 1.0;
 658 | 	}
 659 | 
 660 | 	diffuse_light_interp.rgb += directional_diffuse;
 661 | 
 662 | 	float spec_avg = dot(specular_light_interp.rgb, vec3(0.33333));
 663 | 	float spec_dir_avg = dot(directional_specular, vec3(0.33333));
 664 | 	if (spec_avg > 0.0) {
 665 | 		specular_light_interp.a = spec_dir_avg / (spec_avg + spec_dir_avg);
 666 | 	} else {
 667 | 		specular_light_interp.a = 1.0;
 668 | 	}
 669 | 
 670 | 	specular_light_interp.rgb += directional_specular;
 671 | 
 672 | #endif //USE_LIGHT_DIRECTIONAL //ubershader-runtime
 673 | 
 674 | #endif // USE_VERTEX_LIGHTING //ubershader-runtime
 675 | }
 676 | 
 677 | /* clang-format off */
 678 | 
 drivers/gles3/shader_gles3.cpp:432 - SceneShaderGLES3: Vertex Program Compilation Failed:
ERROR: 0:237: Use of undeclared identifier 'diffuse_color'
ERROR: 0:240: Use of undeclared identifier 'A'

 drivers/gles3/shader_gles3.cpp:869 - SceneShaderGLES3: Vertex Program Compilation Failed:
ERROR: 0:237: Use of undeclared identifier 'diffuse_color'
ERROR: 0:240: Use of undeclared identifier 'A'

It then proceeds to spam the following line into eternity:

 drivers/gles3/shader_gles3.h:432 - Condition "!version" is true. Returned: -1

Steps to reproduce

  1. Create an OpenGL ES 3.0 project.
  2. Create a 3D Scene.
  3. Add a MeshInstance with any primitive type.
  4. Add a SpatialMaterial to the Mesh or MeshInstance, and set the following properties on the material:
  • Parameters/Diffuse Mode: Oren Nayar
  • Flags/Vertex Lighting: On

At that point the mesh no longer renders and has a pure black unshaded surface. The Output should show the relevant shader compilation errors.

Any other combination of the 4 Diffuse Modes and the Vertex Lighting flag appear to be fine. I don't believe that any other flags or parameters are involved in this but in my reading of the preprocessor directives I certainly could have missed something.

Minimal reproduction project

3.x repro with all Diffuse Mode x Vertex Lighting combinations, as in the screenshots in the description (sorry about the typo in the project name, should be s/Nayer/Nayar 😢 )

@Calinou
Copy link
Member

Calinou commented Jan 14, 2022

Feel free to open a pull request for this against the 3.x branch 🙂

The PR can then be cherry-picked to the 3.4 branch, so you don't need to open a PR against 3.4 specifically.

@akien-mga
Copy link
Member

Fixed by #56802.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants