Skip to content

Commit

Permalink
clean up block renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Decencies committed Dec 28, 2024
1 parent 581cf67 commit 9239f51
Showing 1 changed file with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.caffeinemc.mods.sodium.client.model.color.ColorProviderRegistry;
import net.caffeinemc.mods.sodium.client.model.light.LightMode;
import net.caffeinemc.mods.sodium.client.model.light.LightPipelineProvider;
import net.caffeinemc.mods.sodium.client.model.light.data.QuadLightData;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadFacing;
import net.caffeinemc.mods.sodium.client.model.quad.properties.ModelQuadOrientation;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
Expand Down Expand Up @@ -74,25 +75,25 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP

this.posOffset.set(origin.getX(), origin.getY(), origin.getZ());

//Block.OffsetType offsetType = state.getBlock().getOffsetType();
//
//if (offsetType != Block.OffsetType.NONE) {
// int x = origin.getX();
// int z = origin.getZ();
// // Taken from MathHelper.hashCode()
// long i = (x * 3129871L) ^ z * 116129781L;
// i = i * i * 42317861L + i * 11L;
//
// double fx = (((i >> 16 & 15L) / 15.0F) - 0.5f) * 0.5f;
// double fz = (((i >> 24 & 15L) / 15.0F) - 0.5f) * 0.5f;
// double fy = 0;
//
// if (offsetType == Block.OffsetType.XYZ) {
// fy += (((i >> 20 & 15L) / 15.0F) - 1.0f) * 0.2f;
// }
//
// posOffset.add((float) fx, (float) fy, (float) fz);
//}
var offsetType = state.getBlock().getOffsetType();

if (offsetType != Block.OffsetType.NONE) {
int x = origin.getX();
int z = origin.getZ();
// Taken from MathHelper.hashCode()
long i = (x * 3129871L) ^ z * 116129781L;
i = i * i * 42317861L + i * 11L;

double fx = (((i >> 16 & 15L) / 15.0F) - 0.5f) * 0.5f;
double fz = (((i >> 24 & 15L) / 15.0F) - 0.5f) * 0.5f;
double fy = 0;

if (offsetType == Block.OffsetType.XYZ) {
fy += (((i >> 20 & 15L) / 15.0F) - 1.0f) * 0.2f;
}

posOffset.add((float) fx, (float) fy, (float) fz);
}

this.colorProvider = this.colorProviderRegistry.getColorProvider(state.getBlock());

Expand All @@ -101,10 +102,7 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP
this.prepareCulling(true);
this.prepareAoInfo(model.useAmbientOcclusion());

this.type = state.getBlock().getRenderLayerType();
VanillaModelEncoder.emitBlockQuads(getEmitter(), model, state, this::isFaceCulled);

type = null;
}

/**
Expand Down Expand Up @@ -134,7 +132,7 @@ protected void processQuad(MutableQuadViewImpl quad) {

this.tintQuad(quad);
this.shadeQuad(quad, lightMode, emissive, shadeMode);
this.bufferQuad(quad, this.quadLightData.br, material);
this.bufferQuad(quad, this.quadLightData, material);
}

private void tintQuad(MutableQuadViewImpl quad) {
Expand All @@ -154,7 +152,7 @@ private void tintQuad(MutableQuadViewImpl quad) {
}
}

private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material material) {
private void bufferQuad(MutableQuadViewImpl quad, QuadLightData light, Material material) {
// TODO: Find a way to reimplement quad reorientation
ModelQuadOrientation orientation = ModelQuadOrientation.NORMAL;
ChunkVertexEncoder.Vertex[] vertices = this.vertices;
Expand All @@ -168,16 +166,15 @@ private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material
out.y = quad.y(srcIndex) + offset.y;
out.z = quad.z(srcIndex) + offset.z;

out.color = quad.color(srcIndex);//ColorARGB.fromABGR();
out.ao = brightnesses[srcIndex];
out.color = quad.color(srcIndex);
out.ao = light.br[srcIndex];

out.u = quad.u(srcIndex);
out.v = quad.v(srcIndex);

out.light = this.quadLightData.lm[srcIndex];
out.light = light.lm[srcIndex];
}

//var atlasSprite = quad.sprite(SpriteFinderCache.forBlockAtlas());
var materialBits = material.bits();
ModelQuadFacing normalFace = quad.normalFace();

Expand All @@ -192,7 +189,5 @@ private void bufferQuad(MutableQuadViewImpl quad, float[] brightnesses, Material
ChunkModelBuilder builder = this.buffers.get(pass);
ChunkMeshBufferBuilder vertexBuffer = builder.getVertexBuffer(normalFace);
vertexBuffer.push(vertices, materialBits);

//builder.addSprite(atlasSprite);
}
}

0 comments on commit 9239f51

Please sign in to comment.