VulkanShader_1.21.10-0.0.4-alpha.jar
Download file
package net.vulkanmod.render.chunk.build.light.smooth;
import net.minecraft.class_2338;
import net.minecraft.class_2350;
import net.minecraft.class_3532;
import net.vulkanmod.render.chunk.build.light.LightPipeline;
import net.vulkanmod.render.chunk.build.light.data.LightDataAccess;
import net.vulkanmod.render.chunk.build.light.data.QuadLightData;
import net.vulkanmod.render.chunk.util.SimpleDirection;
import net.vulkanmod.render.model.quad.ModelQuadView;
public class NewSmoothLightPipeline implements LightPipeline {
private final LightDataAccess lightCache;
private final SubBlockAoFace[] cachedFaceData = new SubBlockAoFace[12];
private final SubBlockAoFace self = new SubBlockAoFace();
private long cachedPos = Long.MIN_VALUE;
private final float[] weights = new float[4];
public NewSmoothLightPipeline(LightDataAccess cache) {
this.lightCache = cache;
for(int i = 0; i < this.cachedFaceData.length; ++i) {
this.cachedFaceData[i] = new SubBlockAoFace();
}
}
public void calculate(ModelQuadView quad, class_2338 pos, QuadLightData out, class_2350 cullFace, class_2350 lightFaceO, boolean shade) {
this.updateCachedData(pos.method_10063());
int flags = quad.getFlags();
SimpleDirection lightFace = SimpleDirection.of(lightFaceO);
AoNeighborInfo neighborInfo = AoNeighborInfo.get(lightFace);
if ((flags & 4) != 0 || (flags & 2) != 0 && LightDataAccess.unpackFC(this.lightCache.get(pos))) {
if ((flags & 1) == 0) {
this.applyAlignedFullFace(neighborInfo, pos, lightFace, out);
} else {
this.applyAlignedPartialFace(neighborInfo, quad, pos, lightFace, out);
}
} else if ((flags & 2) != 0) {
this.applyParallelFace(neighborInfo, quad, pos, lightFace, out);
} else {
this.applyNonParallelFace(neighborInfo, quad, pos, lightFace, out);
}
this.applySidedBrightness(out, lightFaceO, shade);
}
private void applyAlignedFullFace(AoNeighborInfo neighborInfo, class_2338 pos, SimpleDirection dir, QuadLightData out) {
SubBlockAoFace faceData = this.getCachedFaceData(pos, dir, true);
neighborInfo.copyLightValues(faceData.lm, faceData.ao, out.lm, out.br);
}
private void applyAlignedPartialFace(AoNeighborInfo neighborInfo, ModelQuadView quad, class_2338 pos, SimpleDirection dir, QuadLightData out) {
for(int i = 0; i < 4; ++i) {
float cx = clamp(quad.getX(i));
float cy = clamp(quad.getY(i));
float cz = clamp(quad.getZ(i));
float[] weights = this.weights;
neighborInfo.calculateCornerWeights(cx, cy, cz, weights);
this.applyAlignedPartialFaceVertex(pos, dir, weights, i, out, true);
}
}
private void applyParallelFace(AoNeighborInfo neighborInfo, ModelQuadView quad, class_2338 pos, SimpleDirection dir, QuadLightData out) {
this.self.calculateSelfOcclusion(this.lightCache, pos, dir);
for(int i = 0; i < 4; ++i) {
float cx = clamp(quad.getX(i));
float cy = clamp(quad.getY(i));
float cz = clamp(quad.getZ(i));
float[] weights = this.weights;
neighborInfo.calculateCornerWeights(cx, cy, cz, weights);
float depth = neighborInfo.getDepth(cx, cy, cz);
if (class_3532.method_15347(depth, 1.0F)) {
this.applyAlignedPartialFaceVertex(pos, dir, weights, i, out, false);
} else {
this.applyInsetPartialFaceVertexSO(pos, dir, depth, 1.0F - depth, weights, i, out);
}
}
}
private void applyNonParallelFace(AoNeighborInfo neighborInfo, ModelQuadView quad, class_2338 pos, SimpleDirection dir, QuadLightData out) {
for(int i = 0; i < 4; ++i) {
float cx = clamp(quad.getX(i));
float cy = clamp(quad.getY(i));
float cz = clamp(quad.getZ(i));
float[] weights = this.weights;
neighborInfo.calculateCornerWeights(cx, cy, cz, weights);
float depth = neighborInfo.getDepth(cx, cy, cz);
if (class_3532.method_15347(depth, 0.0F)) {
this.applyAlignedPartialFaceVertex(pos, dir, weights, i, out, true);
} else if (class_3532.method_15347(depth, 1.0F)) {
this.applyAlignedPartialFaceVertex(pos, dir, weights, i, out, false);
} else {
this.applyInsetPartialFaceVertex(pos, dir, depth, 1.0F - depth, weights, i, out);
}
}
}
private void applyAlignedPartialFaceVertex(class_2338 pos, SimpleDirection dir, float[] w, int i, QuadLightData out, boolean offset) {
SubBlockAoFace faceData = this.getCachedFaceData(pos, dir, offset);
if (!faceData.hasUnpackedLightData()) {
faceData.unpackLightData();
}
float sl = faceData.getBlendedSkyLight(w);
float bl = faceData.getBlendedBlockLight(w);
float ao = faceData.getBlendedShade(w);
out.br[i] = ao;
out.lm[i] = packLightMap(sl, bl);
}
private void applyInsetPartialFaceVertex(class_2338 pos, SimpleDirection dir, float n1d, float n2d, float[] w, int i, QuadLightData out) {
SubBlockAoFace n1 = this.getCachedFaceData(pos, dir, false);
if (!n1.hasUnpackedLightData()) {
n1.unpackLightData();
}
SubBlockAoFace n2 = this.getCachedFaceData(pos, dir, true);
if (!n2.hasUnpackedLightData()) {
n2.unpackLightData();
}
float ao = n1.getBlendedShade(w) * n1d + n2.getBlendedShade(w) * n2d;
float sl = n1.getBlendedSkyLight(w) * n1d + n2.getBlendedSkyLight(w) * n2d;
float bl = n1.getBlendedBlockLight(w) * n1d + n2.getBlendedBlockLight(w) * n2d;
out.br[i] = ao;
out.lm[i] = packLightMap(sl, bl);
}
private void applyInsetPartialFaceVertexSO(class_2338 pos, SimpleDirection dir, float n1d, float n2d, float[] w, int i, QuadLightData out) {
SubBlockAoFace n1 = this.getCachedFaceData(pos, dir, false);
if (!n1.hasUnpackedLightData()) {
n1.unpackLightData();
}
SubBlockAoFace n2 = this.getCachedFaceData(pos, dir, true);
if (!n2.hasUnpackedLightData()) {
n2.unpackLightData();
}
float ao = n1.getBlendedShade(w) * n1d + n2.getBlendedShade(w) * n2d;
float sl = n1.getBlendedSkyLight(w) * n1d + n2.getBlendedSkyLight(w) * n2d;
float bl = n1.getBlendedBlockLight(w) * n1d + n2.getBlendedBlockLight(w) * n2d;
ao = Math.min(ao, this.self.getBlendedShade(w));
out.br[i] = ao;
out.lm[i] = packLightMap(sl, bl);
}
private void applySidedBrightness(QuadLightData out, class_2350 face, boolean shade) {
float brightness = this.lightCache.getRegion().method_24852(face, shade);
float[] br = out.br;
for(int i = 0; i < br.length; ++i) {
br[i] *= brightness;
}
}
private SubBlockAoFace getCachedFaceData(class_2338 pos, SimpleDirection face, boolean offset) {
SubBlockAoFace data = this.cachedFaceData[offset ? face.ordinal() : face.ordinal() + 6];
if (!data.hasLightData()) {
data.initLightData(this.lightCache, pos, face, offset);
}
return data;
}
private void updateCachedData(long key) {
if (this.cachedPos != key) {
for(SubBlockAoFace data : this.cachedFaceData) {
data.reset();
}
this.cachedPos = key;
}
}
private static float clamp(float v) {
if (v < 0.0F) {
return 0.0F;
} else {
return v > 1.0F ? 1.0F : v;
}
}
private static int packLightMap(float sl, float bl) {
return ((int)sl & 255) << 16 | (int)bl & 255;
}
}
Download file