mirror of https://github.com/bjornbytes/lovr.git
Invert surface normal when backfacing;
This commit is contained in:
parent
f679d602bd
commit
507c02bfb1
|
@ -207,16 +207,22 @@ mat3 getTangentMatrix() {
|
||||||
void initSurface(out Surface surface) {
|
void initSurface(out Surface surface) {
|
||||||
surface.position = PositionWorld;
|
surface.position = PositionWorld;
|
||||||
|
|
||||||
|
vec3 normal = normalize(Normal);
|
||||||
|
|
||||||
|
if (!FrontFacing) {
|
||||||
|
normal = -normal;
|
||||||
|
}
|
||||||
|
|
||||||
if (enableNormalMap) {
|
if (enableNormalMap) {
|
||||||
vec3 normalScale = vec3(Material.normalScale, Material.normalScale, 1.);
|
vec3 normalScale = vec3(Material.normalScale, Material.normalScale, 1.);
|
||||||
surface.normal = TangentMatrix * (normalize(getPixel(NormalTexture, UV).rgb * 2. - 1.) * normalScale);
|
surface.normal = TangentMatrix * (normalize(getPixel(NormalTexture, UV).rgb * 2. - 1.) * normalScale);
|
||||||
} else {
|
} else {
|
||||||
surface.normal = normalize(Normal);
|
surface.normal = normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
surface.geometricNormal = normalize(Normal);
|
surface.geometricNormal = normal;
|
||||||
surface.view = normalize(CameraPositionWorld - PositionWorld);
|
surface.view = normalize(CameraPositionWorld - PositionWorld);
|
||||||
surface.reflection = reflect(-surface.view, surface.normal);
|
surface.reflection = reflect(-surface.view, normal);
|
||||||
|
|
||||||
vec4 color = Color;
|
vec4 color = Color;
|
||||||
if (useColorTexture) color *= getPixel(ColorTexture, UV);
|
if (useColorTexture) color *= getPixel(ColorTexture, UV);
|
||||||
|
|
Loading…
Reference in New Issue