From 507c02bfb12af360fa4db6b7229ac91c2978344f Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 12 Aug 2022 23:30:39 -0700 Subject: [PATCH] Invert surface normal when backfacing; --- etc/shaders/lovr.glsl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/etc/shaders/lovr.glsl b/etc/shaders/lovr.glsl index 6307ad8a..a14aa4cf 100644 --- a/etc/shaders/lovr.glsl +++ b/etc/shaders/lovr.glsl @@ -207,16 +207,22 @@ mat3 getTangentMatrix() { void initSurface(out Surface surface) { surface.position = PositionWorld; + vec3 normal = normalize(Normal); + + if (!FrontFacing) { + normal = -normal; + } + if (enableNormalMap) { vec3 normalScale = vec3(Material.normalScale, Material.normalScale, 1.); surface.normal = TangentMatrix * (normalize(getPixel(NormalTexture, UV).rgb * 2. - 1.) * normalScale); } else { - surface.normal = normalize(Normal); + surface.normal = normal; } - surface.geometricNormal = normalize(Normal); + surface.geometricNormal = normal; surface.view = normalize(CameraPositionWorld - PositionWorld); - surface.reflection = reflect(-surface.view, surface.normal); + surface.reflection = reflect(-surface.view, normal); vec4 color = Color; if (useColorTexture) color *= getPixel(ColorTexture, UV);