Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 13, 2023
1 parent 0297ea2 commit d7bd891
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ public static void injectVertInit(
tree.parseAndInjectNodes(t, ASTInjectionPoint.BEFORE_FUNCTIONS,
"""
struct IrisQuad {
uvec3 position_hi; // offset: 0 size: 16
uvec3 position_lo; // offset: 16 size: 16
uvec3 position_hi; // offset: 0 size: 12
uint material; // offset: 12 size: 4
uvec3 position_lo; // offset: 16 size: 12
uint mesh_id; // offset: 28 size: 4
uvec4 color; // offset: 32 size: 16
Expand All @@ -150,13 +153,11 @@ public static void injectVertInit(
uvec2 light; // offset: 64 size: 8
uint material; // offset: 72 size: 4
uint mesh_id; // offset: 76 size: 4
uint midTexCoord; // offset: 80 size: 4
uint normal; // offset: 84 size: 4
uint tangent; // offset: 88 size: 4
uint blockInfo; // offset: 92 size: 4
uint midTexCoord; // offset: 72 size: 4
uint normal; // offset: 76 size: 4
uint tangent; // offset: 80 size: 4
uint blockInfo; // offset: 84 size: 4
// midBlock users mald for now
};
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public long write(long ptr, Material material, Vertex[] vertices, int sectionInd
MemoryUtil.memPutInt(ptr + 0, packU16x2_hi(encodePosition(vertices[3].x), encodePosition(vertices[2].x), encodePosition(vertices[1].x), encodePosition(vertices[0].x)));
MemoryUtil.memPutInt(ptr + 4, packU16x2_hi(encodePosition(vertices[3].y), encodePosition(vertices[2].y), encodePosition(vertices[1].y), encodePosition(vertices[0].y)));
MemoryUtil.memPutInt(ptr + 8, packU16x2_hi(encodePosition(vertices[3].z), encodePosition(vertices[2].z), encodePosition(vertices[1].z), encodePosition(vertices[0].z)));
MemoryUtil.memPutInt(ptr + 12, material.bits());

MemoryUtil.memPutInt(ptr + 16, packU16x2_lo(encodePosition(vertices[3].x), encodePosition(vertices[2].x), encodePosition(vertices[1].x), encodePosition(vertices[0].x)));
MemoryUtil.memPutInt(ptr + 20, packU16x2_lo(encodePosition(vertices[3].y), encodePosition(vertices[2].y), encodePosition(vertices[1].y), encodePosition(vertices[0].y)));
MemoryUtil.memPutInt(ptr + 24, packU16x2_lo(encodePosition(vertices[3].z), encodePosition(vertices[2].z), encodePosition(vertices[1].z), encodePosition(vertices[0].z)));
MemoryUtil.memPutInt(ptr + 28, sectionIndex);

MemoryUtil.memPutInt(ptr + 32, packU8x4(ColorABGR.unpackRed(vertices[0].color), ColorABGR.unpackRed(vertices[1].color), ColorABGR.unpackRed(vertices[2].color), ColorABGR.unpackRed(vertices[3].color)));
MemoryUtil.memPutInt(ptr + 36, packU8x4(ColorABGR.unpackGreen(vertices[0].color), ColorABGR.unpackGreen(vertices[1].color), ColorABGR.unpackGreen(vertices[2].color), ColorABGR.unpackGreen(vertices[3].color)));
Expand All @@ -46,25 +48,25 @@ public long write(long ptr, Material material, Vertex[] vertices, int sectionInd
MemoryUtil.memPutInt(ptr + 64, packU16x2(encodeLight(vertices[0].light), encodeLight(vertices[1].light)));
MemoryUtil.memPutInt(ptr + 68, packU16x2(encodeLight(vertices[2].light), encodeLight(vertices[3].light)));

MemoryUtil.memPutInt(ptr + 72, material.bits());
MemoryUtil.memPutInt(ptr + 76, sectionIndex);

float midU = (vertices[0].u + vertices[1].u + vertices[2].u + vertices[3].u) * 0.25f;
float midV = (vertices[0].v + vertices[1].v + vertices[2].v + vertices[3].v) * 0.25f;

MemoryUtil.memPutShort(ptr + 80, (short) encodeTexture(midU));
MemoryUtil.memPutShort(ptr + 82, (short) encodeTexture(midV));
MemoryUtil.memPutShort(ptr + 72, (short) encodeTexture(midU));
MemoryUtil.memPutShort(ptr + 74, (short) encodeTexture(midV));
int normal = flipUpcomingNormal ? NormalHelper.computeFaceNormalCompact(vertices[3].x, vertices[3].y, vertices[3].z, vertices[2].x, vertices[2].y, vertices[2].z, vertices[1].x, vertices[1].y, vertices[1].z, vertices[0].x, vertices[0].y, vertices[0].z)
: NormalHelper.computeFaceNormalCompact(vertices[0].x, vertices[0].y, vertices[0].z, vertices[1].x, vertices[1].y, vertices[1].z, vertices[2].x, vertices[2].y, vertices[2].z, vertices[3].x, vertices[3].y, vertices[3].z);
MemoryUtil.memPutInt(ptr + 84, normal);
MemoryUtil.memPutInt(ptr + 88, NormalHelper.computeTangent(NormI8.unpackX(normal), NormI8.unpackY(normal), NormI8.unpackZ(normal),
MemoryUtil.memPutInt(ptr + 76, normal);

flipUpcomingNormal = false;

MemoryUtil.memPutInt(ptr + 80, NormalHelper.computeTangent(NormI8.unpackX(normal), NormI8.unpackY(normal), NormI8.unpackZ(normal),
vertices[0].x, vertices[0].y, vertices[0].z, vertices[0].u, vertices[0].v,
vertices[1].x, vertices[1].y, vertices[1].z, vertices[1].u, vertices[1].v,
vertices[2].x, vertices[2].y, vertices[2].z, vertices[2].u, vertices[2].v
));

MemoryUtil.memPutInt(ptr + 92, packU16x2(contextHolder.blockId, contextHolder.renderType));
flipUpcomingNormal = false;
MemoryUtil.memPutInt(ptr + 84, packU16x2(contextHolder.blockId, contextHolder.renderType));
// TODO MemoryUtil.memPutInt(ptr + 36, contextHolder.ignoreMidBlock ? 0 : ExtendedDataHelper.computeMidBlock(vertex.x, vertex.y, vertex.z, contextHolder.localPosX, contextHolder.localPosY, contextHolder.localPosZ));
return ptr + XHFPModelVertexType.STRIDE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@ public abstract class MixinFluidRenderer {

@Unique
private boolean useSeparateAo;

//@Inject(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer;writeQuad(Lme/jellysquid/mods/sodium/client/render/chunk/compile/buffers/ChunkModelBuilder;Lme/jellysquid/mods/sodium/client/render/chunk/terrain/material/Material;Lnet/minecraft/core/BlockPos;Lme/jellysquid/mods/sodium/client/model/quad/ModelQuadView;Lme/jellysquid/mods/sodium/client/model/quad/properties/ModelQuadFacing;Z)V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD)
private void iris$flipNextQuad(WorldSlice world, FluidState fluidState, BlockPos blockPos, BlockPos offset, ChunkBuildBuffers buffers, CallbackInfo ci, Material material) {
((ContextAwareVertexWriter) buffers.get(material)).flipUpcomingQuadNormal();
}

//@Inject(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/chunk/compile/pipeline/FluidRenderer;writeQuad(Lme/jellysquid/mods/sodium/client/render/chunk/compile/buffers/ChunkModelBuilder;Lme/jellysquid/mods/sodium/client/render/chunk/terrain/material/Material;Lnet/minecraft/core/BlockPos;Lme/jellysquid/mods/sodium/client/model/quad/ModelQuadView;Lme/jellysquid/mods/sodium/client/model/quad/properties/ModelQuadFacing;Z)V", ordinal = 2), locals = LocalCapture.CAPTURE_FAILHARD)
private void iris$flipNextQuad2(WorldSlice world, FluidState fluidState, BlockPos blockPos, BlockPos offset, ChunkBuildBuffers buffers, CallbackInfo ci, Material material) {
((ContextAwareVertexWriter) buffers.get(material)).flipUpcomingQuadNormal();
}

@Inject(method = "writeQuad", at = @At("HEAD"))
private void a(ChunkModelBuilder builder, Material material, BlockPos offset, ModelQuadView quad, ModelQuadFacing facing, boolean flip, CallbackInfo ci) {
if (facing == ModelQuadFacing.NEG_Y) {
((ContextAwareVertexWriter) builder.getMeshBuffer(facing)).flipUpcomingQuadNormal();
}
}
}

0 comments on commit d7bd891

Please sign in to comment.