Fix exterior vertex lighting

This commit is contained in:
grondag 2019-05-30 19:24:28 -07:00
parent 702c210a7a
commit 0275a7756e
3 changed files with 50 additions and 19 deletions

View file

@ -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");

View file

@ -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);

View file

@ -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;
}