Skip to content

Commit

Permalink
Fix MutableQuadViewImpl#fromVanilla methods not setting correct norma…
Browse files Browse the repository at this point in the history
…l flags (#4350)

- The (int[], int) overload used to keep the normal flags as is
- The (BakedQuad, RenderMaterial, Direction) overload used to reset all normal flags
- The normal flag for a vertex is now set if and only if the normal is not zero, ignoring the W component
- Clarify that MutableQuadView#fromVanilla(BakedQuad, ...) resets the quad tag
  • Loading branch information
PepperCode1 authored Jan 7, 2025
1 parent 8a54955 commit 50f0feb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ default MutableQuadView normal(int vertexIndex, Vector3fc normal) {
* <p>The {@linkplain BakedQuad#getLightEmission() baked quad's light emission} will be applied to the lightmap
* values from the vertex data after copying.
*
* <p>Calling this method resets the {@link #tag()}.
*
* <p>Calling this method does not emit the quad.
*/
MutableQuadView fromVanilla(BakedQuad quad, RenderMaterial material, @Nullable Direction cullFace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,30 @@ public final MutableQuadViewImpl fromVanilla(int[] quadData, int startIndex) {
System.arraycopy(quadData, startIndex, data, baseIndex + HEADER_STRIDE, VANILLA_QUAD_STRIDE);
isGeometryInvalid = true;

int normalFlags = 0;
int colorIndex = baseIndex + VERTEX_COLOR;
int normalIndex = baseIndex + VERTEX_NORMAL;

for (int i = 0; i < 4; i++) {
data[colorIndex] = ColorHelper.fromVanillaColor(data[colorIndex]);

// Set normal flag if normal is not zero, ignoring W component
if ((data[normalIndex] & 0xFFFFFF) != 0) {
normalFlags |= 1 << i;
}

colorIndex += VERTEX_STRIDE;
normalIndex += VERTEX_STRIDE;
}

normalFlags(normalFlags);
return this;
}

@Override
public final MutableQuadViewImpl fromVanilla(BakedQuad quad, RenderMaterial material, @Nullable Direction cullFace) {
fromVanilla(quad.getVertexData(), 0);
data[baseIndex + HEADER_BITS] = EncodingFormat.cullFace(0, cullFace);
cullFace(cullFace);
nominalFace(quad.getFace());
tintIndex(quad.getTintIndex());

Expand Down

0 comments on commit 50f0feb

Please sign in to comment.