- model normals fix

This commit is contained in:
Rachael Alexanderson 2022-05-03 23:39:40 -04:00
parent c86d9f60d0
commit 679518f8e5

View file

@ -5,8 +5,8 @@ layout(location = 1) in vec4 vColor;
layout(location = 2) in vec4 pixelpos;
layout(location = 3) in vec3 glowdist;
layout(location = 4) in vec3 gradientdist;
layout(location = 5) in vec4 vWorldNormal;
layout(location = 6) in vec4 vEyeNormal;
layout(location = 5) in vec4 vWorldNormalOrig;
layout(location = 6) in vec4 vEyeNormalOrig;
layout(location = 9) in vec3 vLightmap;
#ifdef NO_CLIPDISTANCE_SUPPORT
@ -20,6 +20,9 @@ layout(location=1) out vec4 FragFog;
layout(location=2) out vec4 FragNormal;
#endif
vec4 vWorldNormal;
vec4 vEyeNormal;
struct Material
{
vec4 Base;
@ -720,6 +723,15 @@ void main()
if (ClipDistanceA.x < 0 || ClipDistanceA.y < 0 || ClipDistanceA.z < 0 || ClipDistanceA.w < 0 || ClipDistanceB.x < 0) discard;
#endif
// Flip normal if it is facing away from the camera
vWorldNormal = vWorldNormalOrig;
vEyeNormal = vEyeNormalOrig;
if (dot(uCameraPos.xyz - pixelpos.xyz, vWorldNormal.xyz) < 0)
{
vWorldNormal.xyz = -vWorldNormal.xyz;
vEyeNormal.xyz = -vEyeNormal.xyz;
}
#ifndef LEGACY_USER_SHADER
Material material;