Fix lighting issues ()

This commit is contained in:
modmuss50 2020-04-20 01:42:57 +01:00 committed by GitHub
parent 708a050cc0
commit 6cbc90d6ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 14 deletions
fabric-renderer-indigo/src/main/java/net/fabricmc/fabric/impl/client/indigo/renderer

View file

@ -114,7 +114,7 @@ public class AoCalculator {
}
public void compute(MutableQuadViewImpl quad, boolean isVanilla) {
final AoConfig config = AoConfig.VANILLA; // Indigo.AMBIENT_OCCLUSION_MODE; TODO:20w09a Fix me
final AoConfig config = Indigo.AMBIENT_OCCLUSION_MODE;
final boolean shouldCompare;
switch (config) {
@ -188,7 +188,7 @@ public class AoCalculator {
quad.toVanilla(0, vertexData, 0, false);
VanillaAoHelper.updateShape(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, vertexData, face, vanillaAoData, vanillaAoControlBits);
vanillaCalc.fabric_apply(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, quad.lightFace(), vanillaAoData, vanillaAoControlBits, true /* TODO:20w09a check me */);
vanillaCalc.fabric_apply(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, quad.lightFace(), vanillaAoData, vanillaAoControlBits, quad.hasShade());
System.arraycopy(vanillaCalc.fabric_colorMultiplier(), 0, aoDest, 0, 4);
System.arraycopy(vanillaCalc.fabric_brightness(), 0, lightDest, 0, 4);
@ -229,12 +229,12 @@ public class AoCalculator {
private void vanillaFullFace(QuadViewImpl quad, boolean isOnLightFace) {
final Direction lightFace = quad.lightFace();
computeFace(lightFace, isOnLightFace).toArray(ao, light, VERTEX_MAP[lightFace.getId()]);
computeFace(lightFace, isOnLightFace, quad.hasShade()).toArray(ao, light, VERTEX_MAP[lightFace.getId()]);
}
private void vanillaPartialFace(QuadViewImpl quad, boolean isOnLightFace) {
final Direction lightFace = quad.lightFace();
AoFaceData faceData = computeFace(lightFace, isOnLightFace);
AoFaceData faceData = computeFace(lightFace, isOnLightFace, quad.hasShade());
final WeightFunction wFunc = AoFace.get(lightFace).weightFunc;
final float[] w = this.w;
@ -252,7 +252,7 @@ public class AoCalculator {
private AoFaceData blendedInsetFace(QuadViewImpl quad, int vertexIndex, Direction lightFace) {
final float w1 = AoFace.get(lightFace).depthFunc.apply(quad, vertexIndex);
final float w0 = 1 - w1;
return AoFaceData.weightedMean(computeFace(lightFace, true), w0, computeFace(lightFace, false), w1, tmpFace);
return AoFaceData.weightedMean(computeFace(lightFace, true, quad.hasShade()), w0, computeFace(lightFace, false, quad.hasShade()), w1, tmpFace);
}
/**
@ -263,12 +263,12 @@ public class AoCalculator {
final float w1 = AoFace.get(lightFace).depthFunc.apply(quad, vertexIndex);
if (MathHelper.approximatelyEquals(w1, 0)) {
return computeFace(lightFace, true);
return computeFace(lightFace, true, quad.hasShade());
} else if (MathHelper.approximatelyEquals(w1, 1)) {
return computeFace(lightFace, false);
return computeFace(lightFace, false, quad.hasShade());
} else {
final float w0 = 1 - w1;
return AoFaceData.weightedMean(computeFace(lightFace, true), w0, computeFace(lightFace, false), w1, tmpFace);
return AoFaceData.weightedMean(computeFace(lightFace, true, quad.hasShade()), w0, computeFace(lightFace, false, quad.hasShade()), w1, tmpFace);
}
}
@ -366,7 +366,7 @@ public class AoCalculator {
* in vanilla logic for some blocks that aren't full opaque cubes.
* Except for parameterization, the logic itself is practically identical to vanilla.
*/
private AoFaceData computeFace(Direction lightFace, boolean isOnBlockFace) {
private AoFaceData computeFace(Direction lightFace, boolean isOnBlockFace, boolean shade) {
final int faceDataIndex = isOnBlockFace ? lightFace.getId() : lightFace.getId() + 6;
final int mask = 1 << faceDataIndex;
final AoFaceData result = faceData[faceDataIndex];
@ -465,11 +465,12 @@ public class AoCalculator {
}
float aoCenter = aoFunc.apply(isOnBlockFace ? lightPos : pos);
float worldBrightness = world.getBrightness(lightFace, shade);
result.a0 = (ao3 + ao0 + cAo1 + aoCenter) * 0.25F;
result.a1 = (ao2 + ao0 + cAo0 + aoCenter) * 0.25F;
result.a2 = (ao2 + ao1 + cAo2 + aoCenter) * 0.25F;
result.a3 = (ao3 + ao1 + cAo3 + aoCenter) * 0.25F;
result.a0 = ((ao3 + ao0 + cAo1 + aoCenter) * 0.25F) * worldBrightness;
result.a1 = ((ao2 + ao0 + cAo0 + aoCenter) * 0.25F) * worldBrightness;
result.a2 = ((ao2 + ao1 + cAo2 + aoCenter) * 0.25F) * worldBrightness;
result.a3 = ((ao3 + ao1 + cAo3 + aoCenter) * 0.25F) * worldBrightness;
result.l0(meanBrightness(light3, light0, cLight1, lightCenter));
result.l1(meanBrightness(light2, light0, cLight0, lightCenter));

View file

@ -51,6 +51,7 @@ public class QuadViewImpl implements QuadView {
protected boolean isGeometryInvalid = true;
protected final Vector3f faceNormal = new Vector3f();
protected boolean isFaceNormalInvalid = true;
private boolean shade = true;
/** Size and where it comes from will vary in subtypes. But in all cases quad is fully encoded to array. */
protected int[] data;
@ -285,4 +286,12 @@ public class QuadViewImpl implements QuadView {
public int vertexStart() {
return baseIndex + HEADER_STRIDE;
}
public boolean hasShade() {
return shade;
}
public void shade(boolean shade) {
this.shade = shade;
}
}

View file

@ -139,7 +139,7 @@ public abstract class AbstractQuadRenderer {
/** for non-emissive mesh quads and all fallback quads with flat lighting. */
protected void tesselateFlat(MutableQuadViewImpl quad, RenderLayer renderLayer, int blockColorIndex) {
colorizeQuad(quad, blockColorIndex);
final int brightness = flatBrightness(quad, blockInfo.blockState, blockInfo.blockPos);
final int brightness = ColorHelper.multiplyRGB(flatBrightness(quad, blockInfo.blockState, blockInfo.blockPos), blockInfo.blockView.getBrightness(quad.lightFace(), quad.hasShade()));
for (int i = 0; i < 4; i++) {
quad.lightmap(i, ColorHelper.maxBrightness(quad.lightmap(i), brightness));

View file

@ -255,6 +255,7 @@ public class ItemRenderContext extends AbstractRenderContext implements RenderCo
editorQuad.lightFace(lightFace);
editorQuad.nominalFace(lightFace);
editorQuad.colorIndex(q.getColorIndex());
editorQuad.shade(q.hasShade());
renderQuad();
}
}

View file

@ -126,6 +126,7 @@ public abstract class TerrainFallbackConsumer extends AbstractQuadRenderer imple
editorQuad.nominalFace(lightFace);
editorQuad.colorIndex(quad.getColorIndex());
editorQuad.material(defaultMaterial);
editorQuad.shade(quad.hasShade());
if (!transform.transform(editorQuad)) {
return;