Skip to content

Commit 7f6b272

Browse files
committed
Merge pull request #99163 from clayjohn/Mobile-normal-interp
Normalize normal, tangent, and binormal before interpolating in the mobile renderer to avoid precision errors on heavily scaled meshes
2 parents 8726f84 + 2c158c3 commit 7f6b272

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ void main() {
434434

435435
vertex_interp = vertex;
436436
#ifdef NORMAL_USED
437-
normal_interp = normal;
437+
normal_interp = normalize(normal);
438438
#endif
439439

440440
#if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED)
441-
tangent_interp = tangent;
442-
binormal_interp = binormal;
441+
tangent_interp = normalize(tangent);
442+
binormal_interp = normalize(binormal);
443443
#endif
444444

445445
// VERTEX LIGHTING
@@ -456,13 +456,13 @@ void main() {
456456
uvec2 omni_light_indices = instances.data[draw_call.instance_index].omni_lights;
457457
for (uint i = 0; i < sc_omni_lights(); i++) {
458458
uint light_index = (i > 3) ? ((omni_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_light_indices.x >> (i * 8)) & 0xFF);
459-
light_process_omni_vertex(light_index, vertex, view, normal, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
459+
light_process_omni_vertex(light_index, vertex, view, normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
460460
}
461461

462462
uvec2 spot_light_indices = instances.data[draw_call.instance_index].spot_lights;
463463
for (uint i = 0; i < sc_spot_lights(); i++) {
464464
uint light_index = (i > 3) ? ((spot_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_light_indices.x >> (i * 8)) & 0xFF);
465-
light_process_spot_vertex(light_index, vertex, view, normal, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
465+
light_process_spot_vertex(light_index, vertex, view, normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
466466
}
467467

468468
if (sc_directional_lights() > 0) {
@@ -479,13 +479,13 @@ void main() {
479479
continue; // Statically baked light and object uses lightmap, skip.
480480
}
481481
if (i == 0) {
482-
light_compute_vertex(normal, directional_lights.data[0].direction, view,
482+
light_compute_vertex(normal_interp, directional_lights.data[0].direction, view,
483483
directional_lights.data[0].color * directional_lights.data[0].energy,
484484
true, roughness,
485485
directional_diffuse,
486486
directional_specular);
487487
} else {
488-
light_compute_vertex(normal, directional_lights.data[i].direction, view,
488+
light_compute_vertex(normal_interp, directional_lights.data[i].direction, view,
489489
directional_lights.data[i].color * directional_lights.data[i].energy,
490490
true, roughness,
491491
diffuse_light_interp.rgb,

0 commit comments

Comments
 (0)