forked from IrisShaders/Iris
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 15 additions & 44 deletions
59
src/main/java/net/coderbot/iris/mixin/compat/pixelmon/MixinNormalizedFace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,23 @@ | ||
package net.coderbot.iris.mixin.compat.pixelmon; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.pixelmonmod.pixelmon.client.models.smd.DeformVertex; | ||
import com.pixelmonmod.pixelmon.client.models.smd.NormalizedFace; | ||
import com.pixelmonmod.pixelmon.client.models.smd.TextureCoordinate; | ||
import com.pixelmonmod.pixelmon.client.models.smd.Vertex; | ||
import org.joml.Matrix3f; | ||
import org.joml.Matrix4f; | ||
import org.joml.Vector3f; | ||
import org.joml.Vector4f; | ||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Coerce; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(value = NormalizedFace.class, remap = false) | ||
@Pseudo | ||
@Mixin(targets = {"com/pixelmonmod/pixelmon/client/models/smd/NormalizedFace"}) | ||
public class MixinNormalizedFace { | ||
|
||
@Shadow | ||
public DeformVertex[] vertices; | ||
|
||
@Shadow | ||
public TextureCoordinate[] textureCoordinates; | ||
|
||
@Shadow | ||
public Vertex faceNormal; | ||
|
||
@Shadow | ||
public Vertex calculateFaceNormal() { | ||
return null; | ||
} | ||
|
||
/** | ||
* @author Asek3 | ||
* @reason We should deal with this... | ||
* @author embeddedt (original idea by NanoLive) | ||
* @reason Pixelmon manipulates the buffer of a {@link BufferBuilder} directly which causes problems. | ||
* We bypass that code path. | ||
*/ | ||
@Overwrite | ||
public void addFaceForRender(PoseStack matrixStack, VertexConsumer bufferBuilder, int packedLight, int packedOverlay, boolean smoothShading, float partialTick, float r, float g, float b, float a) { | ||
if (!smoothShading && this.faceNormal == null) | ||
this.faceNormal = calculateFaceNormal(); | ||
for (int i = 0; i < 3; i++) { | ||
Matrix4f pose = matrixStack.last().pose(); | ||
Matrix3f normal = matrixStack.last().normal(); | ||
DeformVertex vertex = this.vertices[i]; | ||
Vector4f transformedPosition = pose.transform(new Vector4f(vertex.getX(partialTick), vertex.getY(partialTick), vertex.getZ(partialTick), 1.0F)); | ||
Vector3f transformedNormal = normal.transform(new Vector3f(vertex.getXN(partialTick), vertex.getYN(partialTick), vertex.getZN(partialTick))); | ||
bufferBuilder.vertex(transformedPosition.x(), transformedPosition.y(), transformedPosition.z(), r, g, b, a, this.textureCoordinates[i].u, this.textureCoordinates[i].v, packedOverlay, packedLight, transformedNormal.x(), transformedNormal.y(), transformedNormal.z()); | ||
} | ||
@Redirect(method = "addFaceForRender", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lcom/pixelmonmod/pixelmon/client/models/smd/DeformVertex;id2:I")) | ||
public int hideBufferBuilderId(@Coerce Object instance) { | ||
return -1; // prevent using "optimized" code path | ||
} | ||
|
||
} | ||
} |