Normalize normal tangent and binormal before interpolating in the mobile renderer to avoid precision errors on heavily scaled meshes

This commit is contained in:
clayjohn 2024-11-12 22:02:58 -08:00
parent cb411fa960
commit 2c158c386b

View File

@ -434,12 +434,12 @@ void main() {
vertex_interp = vertex; vertex_interp = vertex;
#ifdef NORMAL_USED #ifdef NORMAL_USED
normal_interp = normal; normal_interp = normalize(normal);
#endif #endif
#if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED) #if defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED)
tangent_interp = tangent; tangent_interp = normalize(tangent);
binormal_interp = binormal; binormal_interp = normalize(binormal);
#endif #endif
// VERTEX LIGHTING // VERTEX LIGHTING
@ -456,13 +456,13 @@ void main() {
uvec2 omni_light_indices = instances.data[draw_call.instance_index].omni_lights; uvec2 omni_light_indices = instances.data[draw_call.instance_index].omni_lights;
for (uint i = 0; i < sc_omni_lights(); i++) { for (uint i = 0; i < sc_omni_lights(); i++) {
uint light_index = (i > 3) ? ((omni_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_light_indices.x >> (i * 8)) & 0xFF); uint light_index = (i > 3) ? ((omni_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_light_indices.x >> (i * 8)) & 0xFF);
light_process_omni_vertex(light_index, vertex, view, normal, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb); light_process_omni_vertex(light_index, vertex, view, normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
} }
uvec2 spot_light_indices = instances.data[draw_call.instance_index].spot_lights; uvec2 spot_light_indices = instances.data[draw_call.instance_index].spot_lights;
for (uint i = 0; i < sc_spot_lights(); i++) { for (uint i = 0; i < sc_spot_lights(); i++) {
uint light_index = (i > 3) ? ((spot_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_light_indices.x >> (i * 8)) & 0xFF); uint light_index = (i > 3) ? ((spot_light_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_light_indices.x >> (i * 8)) & 0xFF);
light_process_spot_vertex(light_index, vertex, view, normal, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb); light_process_spot_vertex(light_index, vertex, view, normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
} }
if (sc_directional_lights() > 0) { if (sc_directional_lights() > 0) {
@ -479,13 +479,13 @@ void main() {
continue; // Statically baked light and object uses lightmap, skip. continue; // Statically baked light and object uses lightmap, skip.
} }
if (i == 0) { if (i == 0) {
light_compute_vertex(normal, directional_lights.data[0].direction, view, light_compute_vertex(normal_interp, directional_lights.data[0].direction, view,
directional_lights.data[0].color * directional_lights.data[0].energy, directional_lights.data[0].color * directional_lights.data[0].energy,
true, roughness, true, roughness,
directional_diffuse, directional_diffuse,
directional_specular); directional_specular);
} else { } else {
light_compute_vertex(normal, directional_lights.data[i].direction, view, light_compute_vertex(normal_interp, directional_lights.data[i].direction, view,
directional_lights.data[i].color * directional_lights.data[i].energy, directional_lights.data[i].color * directional_lights.data[i].energy,
true, roughness, true, roughness,
diffuse_light_interp.rgb, diffuse_light_interp.rgb,