From 0275a7756e31321f4c0f2628174a1745d9b1e25a Mon Sep 17 00:00:00 2001 From: grondag Date: Thu, 30 May 2019 19:24:28 -0700 Subject: [PATCH] Fix exterior vertex lighting --- .../main/java/net/fabricmc/indigo/Indigo.java | 2 + .../indigo/renderer/aocalc/AoFace.java | 38 +++++++++---------- .../aocalc/AoVertexClampFunction.java | 29 ++++++++++++++ 3 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoVertexClampFunction.java diff --git a/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/Indigo.java b/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/Indigo.java index fab4f76dc..1494f18c9 100644 --- a/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/Indigo.java +++ b/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/Indigo.java @@ -38,6 +38,7 @@ public class Indigo implements ClientModInitializer { /** Set true in dev env to confirm results match vanilla when they should */ public static final boolean DEBUG_COMPARE_LIGHTING; public static final boolean FIX_SMOOTH_LIGHTING_OFFSET; + public static final boolean FIX_EXTERIOR_VERTEX_LIGHTING; private static final Logger LOGGER = LogManager.getLogger(); @@ -105,6 +106,7 @@ public class Indigo implements ClientModInitializer { AMBIENT_OCCLUSION_MODE = asEnum((String) properties.computeIfAbsent("ambient-occlusion-mode", (a) -> "enhanced"), AoConfig.ENHANCED); DEBUG_COMPARE_LIGHTING = asBoolean((String) properties.computeIfAbsent("debug-compare-lighting", (a) -> "auto"), false); FIX_SMOOTH_LIGHTING_OFFSET = asBoolean((String) properties.computeIfAbsent("fix-smooth-lighting-offset", (a) -> "auto"), true); + FIX_EXTERIOR_VERTEX_LIGHTING = asBoolean((String) properties.computeIfAbsent("fix-exterior-vertex-lighting", (a) -> "auto"), true); try (FileOutputStream stream = new FileOutputStream(configFile)) { properties.store(stream, "Indigo properties file"); diff --git a/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoFace.java b/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoFace.java index a8a42a2ea..9227eb06c 100644 --- a/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoFace.java +++ b/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoFace.java @@ -17,7 +17,7 @@ package net.fabricmc.indigo.renderer.aocalc; import static net.minecraft.util.math.Direction.*; - +import static net.fabricmc.indigo.renderer.aocalc.AoVertexClampFunction.CLAMP_FUNC; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.util.SystemUtil; @@ -30,55 +30,55 @@ import net.fabricmc.indigo.renderer.mesh.QuadViewImpl; */ @Environment(EnvType.CLIENT) enum AoFace { - AOF_DOWN(new Direction[]{WEST, EAST, NORTH, SOUTH}, (q, i) -> q.y(i), + AOF_DOWN(new Direction[]{WEST, EAST, NORTH, SOUTH}, (q, i) -> CLAMP_FUNC.clamp(q.y(i)), (q, i, w) -> { - final float u = q.x(i); - final float v = q.z(i); + final float u = CLAMP_FUNC.clamp(q.x(i)); + final float v = CLAMP_FUNC.clamp(q.z(i)); w[0] = (1-u) * v; w[1] = (1-u) * (1-v); w[2] = u * (1-v); w[3] = u * v; }), - AOF_UP(new Direction[]{EAST, WEST, NORTH, SOUTH}, (q, i) -> 1 - q.y(i), + AOF_UP(new Direction[]{EAST, WEST, NORTH, SOUTH}, (q, i) -> 1 - CLAMP_FUNC.clamp(q.y(i)), (q, i, w) -> { - final float u = q.x(i); - final float v = q.z(i); + final float u = CLAMP_FUNC.clamp(q.x(i)); + final float v = CLAMP_FUNC.clamp(q.z(i)); w[0] = u * v; w[1] = u * (1-v); w[2] = (1-u) * (1-v); w[3] = (1-u) * v; }), - AOF_NORTH(new Direction[]{UP, DOWN, EAST, WEST}, (q, i) -> q.z(i), + AOF_NORTH(new Direction[]{UP, DOWN, EAST, WEST}, (q, i) -> CLAMP_FUNC.clamp(q.z(i)), (q, i, w) -> { - final float u = q.y(i); - final float v = q.x(i); + final float u = CLAMP_FUNC.clamp(q.y(i)); + final float v = CLAMP_FUNC.clamp(q.x(i)); w[0] = u * (1-v); w[1] = u * v; w[2] = (1-u) * v; w[3] = (1-u) * (1-v); }), - AOF_SOUTH(new Direction[]{WEST, EAST, DOWN, UP}, (q, i) -> 1 - q.z(i), + AOF_SOUTH(new Direction[]{WEST, EAST, DOWN, UP}, (q, i) -> 1 - CLAMP_FUNC.clamp(q.z(i)), (q, i, w) -> { - final float u = q.y(i); - final float v = q.x(i); + final float u = CLAMP_FUNC.clamp(q.y(i)); + final float v = CLAMP_FUNC.clamp(q.x(i)); w[0] = u * (1-v); w[1] = (1-u) * (1-v); w[2] = (1-u) * v; w[3] = u * v; }), - AOF_WEST(new Direction[]{UP, DOWN, NORTH, SOUTH}, (q, i) -> q.x(i), + AOF_WEST(new Direction[]{UP, DOWN, NORTH, SOUTH}, (q, i) -> CLAMP_FUNC.clamp(q.x(i)), (q, i, w) -> { - final float u = q.y(i); - final float v = q.z(i); + final float u = CLAMP_FUNC.clamp(q.y(i)); + final float v = CLAMP_FUNC.clamp(q.z(i)); w[0] = u * v; w[1] = u * (1-v); w[2] = (1-u) * (1-v); w[3] = (1-u) * v; }), - AOF_EAST(new Direction[]{DOWN, UP, NORTH, SOUTH}, (q, i) -> 1 - q.x(i), + AOF_EAST(new Direction[]{DOWN, UP, NORTH, SOUTH}, (q, i) -> 1 - CLAMP_FUNC.clamp(q.x(i)), (q, i, w) -> { - final float u = q.y(i); - final float v = q.z(i); + final float u = CLAMP_FUNC.clamp(q.y(i)); + final float v = CLAMP_FUNC.clamp(q.z(i)); w[0] = (1-u) * v; w[1] = (1-u) * (1-v); w[2] = u * (1-v); diff --git a/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoVertexClampFunction.java b/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoVertexClampFunction.java new file mode 100644 index 000000000..4d38532fa --- /dev/null +++ b/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/aocalc/AoVertexClampFunction.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.indigo.renderer.aocalc; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.indigo.Indigo; + +@Environment(EnvType.CLIENT) +@FunctionalInterface +interface AoVertexClampFunction { + float clamp(float x); + + static final AoVertexClampFunction CLAMP_FUNC = Indigo.FIX_EXTERIOR_VERTEX_LIGHTING ? x -> x < 0f ? 0f : (x > 1f ? 1f : x) : x -> x; +} \ No newline at end of file