Skip to content

Commit

Permalink
shading works more like CE6 again, and uses less VRAM.
Browse files Browse the repository at this point in the history
  • Loading branch information
EternalBlueFlame committed Dec 15, 2023
1 parent 6f2940d commit a60d025
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/fexcraft/tmt/slim/Tessellator.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public static void bindTexture(ResourceLocation uri){
public void drawTexturedVertsWithNormal(TexturedPolygon polygon, float scale){
GL11.glBegin(polygon.vertices.size()==4?GL11.GL_QUADS:polygon.vertices.size()==3?GL11.GL_TRIANGLES:GL11.GL_POLYGON);

setNormal(polygon.vertices.get(0).vector3F, polygon.vertices.get(1).vector3F, polygon.vertices.get(2).vector3F);
if(polygon.vertices.get(3).vector3F==polygon.vertices.get(1).vector3F
|| polygon.vertices.get(1).vector3F ==polygon.vertices.get(2).vector3F
|| polygon.vertices.get(3).vector3F ==polygon.vertices.get(2).vector3F){
setNormal(polygon.vertices.get(2).vector3F, polygon.vertices.get(0).vector3F, polygon.vertices.get(1).vector3F);
} else {
setNormal(polygon.vertices.get(3).vector3F, polygon.vertices.get(1).vector3F, polygon.vertices.get(2).vector3F);
}

for (TexturedVertex vert : polygon.vertices) {
GL11.glTexCoord2f(vert.textureX, vert.textureY);
Expand All @@ -83,10 +89,10 @@ public void drawTexturedVertsWithNormal(TexturedPolygon polygon, float scale){

public static void setNormal(Vec3f vec0, Vec3f vec1, Vec3f vec2) {
Vec3f vec = new Vec3f(vec1.subtract(vec2)).crossProduct(vec1.subtract(vec0)).normalize();
GL11.glNormal3f(
(byte)((vec.xCoord+90) * 127.0F),
(byte)(vec.yCoord * 127.0F),
(byte)(vec.zCoord * 127.0F));
GL11.glNormal3b(
((byte)((int)(vec.xCoord * 100F))),
((byte)((int)(vec.yCoord * 100F))),
((byte)((int)(vec.zCoord * 100F))));
}

}

0 comments on commit a60d025

Please sign in to comment.