Handle floating point error in QuadEmitter.square() depth argument ()

This commit is contained in:
grondag 2019-07-07 23:13:52 +02:00 committed by asie
parent 896c7fbb2d
commit 6519cfb41e

View file

@ -21,6 +21,7 @@ import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
/**
* Specialized {@link MutableQuadView} obtained via {@link MeshBuilder#getEmitter()}
@ -99,17 +100,31 @@ public interface QuadEmitter extends MutableQuadView {
@Override
QuadEmitter spriteBake(int spriteIndex, Sprite sprite, int bakeFlags);
/**
* Tolerance for determining if the depth parameter to {@link #square(Direction, float, float, float, float, float)}
* is effectively zero - meaning the face is a cull face.
*/
final float CULL_FACE_EPSILON = 0.00001f;
/**
* Helper method to assign vertex coordinates for a square aligned with the given face.
* Ensures that vertex order is consistent with vanilla convention. (Incorrect order can
* lead to bad AO lighting.)<p>
* lead to bad AO lighting unless enhanced lighting logic is available/enabled.)<p>
*
* Square will be parallel to the given face and coplanar with the face if depth == 0.
* All coordinates are normalized (0-1).
* Square will be parallel to the given face and coplanar with the face (and culled if the
* face is occluded) if the depth parameter is approximately zero. See {@link #CULL_FACE_EPSILON}.<p>
*
* All coordinates should be normalized (0-1).
*/
default QuadEmitter square(Direction nominalFace, float left, float bottom, float right, float top, float depth) {
cullFace(depth == 0 ? nominalFace : null);
if(Math.abs(depth) < CULL_FACE_EPSILON) {
cullFace(nominalFace);
depth = 0; // avoid any inconsistency for face quads
} else {
cullFace(null);
}
nominalFace(nominalFace);
switch(nominalFace)
{