Skip to content

Commit

Permalink
Honor per-quad normals in BakedModelEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Jul 1, 2023
1 parent 4f6bfbc commit 95fcc2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@
/**
* The render context used for item rendering.
*/
// TODO: should we remove VertexConsumer in favor of VertexBufferWriter everywhere?
public class ItemRenderContext extends AbstractRenderContext {
/** Value vanilla uses for item rendering. The only sensible choice, of course. */
private static final long ITEM_RANDOM_SEED = 42L;

/* Random handling */
// TODO: shouldn't this be a local random? this is also the case in Indigo, does it deviate fom vanilla?
private final Random random = Random.create();
private final Supplier<Random> randomSupplier = this::prepareRandom;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.jellysquid.mods.sodium.client.render.immediate.model;

import me.jellysquid.mods.sodium.client.frapi.helper.ColorHelper;
import me.jellysquid.mods.sodium.client.frapi.mesh.MutableQuadViewImpl;
import me.jellysquid.mods.sodium.client.frapi.mesh.QuadViewImpl;
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
import net.caffeinemc.mods.sodium.api.math.MatrixHelper;
Expand Down Expand Up @@ -46,16 +47,15 @@ public static void writeQuadVertices(VertexBufferWriter writer, MatrixStack.Entr
}
}

public static void writeQuadVertices(VertexBufferWriter writer, MatrixStack.Entry matrices, QuadViewImpl quad, int overlay) {
public static void writeQuadVertices(VertexBufferWriter writer, MatrixStack.Entry matrices, MutableQuadViewImpl quad, int overlay) {
Matrix3f matNormal = matrices.getNormalMatrix();
Matrix4f matPosition = matrices.getPositionMatrix();

try (MemoryStack stack = RenderImmediate.VERTEX_DATA.push()) {
long buffer = stack.nmalloc(4 * ModelVertex.STRIDE);
long ptr = buffer;

// The packed transformed normal vector
var normal = MatrixHelper.transformNormal(matNormal, quad.packedFaceNormal());
quad.populateMissingNormals();

for (int i = 0; i < 4; i++) {
// The position vector
Expand All @@ -68,7 +68,13 @@ public static void writeQuadVertices(VertexBufferWriter writer, MatrixStack.Entr
float yt = MatrixHelper.transformPositionY(matPosition, x, y, z);
float zt = MatrixHelper.transformPositionZ(matPosition, x, y, z);

ModelVertex.write(ptr, xt, yt, zt, ColorARGB.toABGRKeepAlpha(quad.color(i)), quad.u(i), quad.v(i), overlay, quad.lightmap(i), normal);
// The transformed normal vector
float nx = quad.normalX(i);
float ny = quad.normalY(i);
float nz = quad.normalZ(i);
int transformedNormal = MatrixHelper.transformNormal(matNormal, nx, ny, nz);

ModelVertex.write(ptr, xt, yt, zt, ColorARGB.toABGRKeepAlpha(quad.color(i)), quad.u(i), quad.v(i), overlay, quad.lightmap(i), transformedNormal);
ptr += ModelVertex.STRIDE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Entrypoint of the FRAPI pipeline for non-terrain block rendering, for the baked models that require it.
*/
@Mixin(BlockModelRenderer.class)
public abstract class MixinBlockModelRenderer implements BlockModelRendererExtended {
@Unique
Expand Down

0 comments on commit 95fcc2b

Please sign in to comment.