Skip to content

Commit

Permalink
Summer squash git pasta
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozufozu committed Jul 14, 2024
1 parent b2483de commit f5a6e5a
Show file tree
Hide file tree
Showing 34 changed files with 1,592 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.engine_room.flywheel.api.visualization.VisualizationManager;
import dev.engine_room.flywheel.backend.mixin.LevelRendererAccessor;
import dev.engine_room.flywheel.lib.math.MatrixMath;
import net.minecraft.Util;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
Expand All @@ -16,7 +17,7 @@
import net.minecraft.world.phys.Vec3;

public final class FrameUniforms extends UniformWriter {
private static final int SIZE = 96 + 64 * 9 + 16 * 4 + 8 * 2 + 8 + 4 * 10;
private static final int SIZE = 96 + 64 * 9 + 16 * 4 + 8 * 2 + 8 + 4 * 12;
static final UniformBuffer BUFFER = new UniformBuffer(Uniforms.FRAME_INDEX, SIZE);

private static final Matrix4f VIEW = new Matrix4f();
Expand Down Expand Up @@ -150,11 +151,15 @@ private static long writeTime(long ptr, RenderContext context) {
float partialTick = context.partialTick();
float renderTicks = ticks + partialTick;
float renderSeconds = renderTicks / 20f;
float systemSeconds = Util.getMillis() / 1000f;
int systemMillis = (int) (Util.getMillis() % Integer.MAX_VALUE);

ptr = writeInt(ptr, ticks);
ptr = writeFloat(ptr, partialTick);
ptr = writeFloat(ptr, renderTicks);
ptr = writeFloat(ptr, renderSeconds);
ptr = writeFloat(ptr, systemSeconds);
ptr = writeInt(ptr, systemMillis);
return ptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ layout(std140) uniform _FlwFrameUniforms {
float flw_partialTick;
float flw_renderTicks;
float flw_renderSeconds;
float flw_systemSeconds;
uint flw_systemMillis;

/** 0 means no fluid. Use FLW_CAMERA_IN_FLUID_* defines to detect fluid type. */
uint flw_cameraInFluid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package dev.engine_room.flywheel.lib.internal;

import java.util.Map;

import org.slf4j.Logger;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;

import dev.engine_room.flywheel.api.internal.DependencyInjection;
import dev.engine_room.flywheel.lib.transform.PoseTransformStack;
import net.minecraft.client.model.geom.ModelPart;

public interface FlwLibLink {
FlwLibLink INSTANCE = DependencyInjection.load(FlwLibLink.class, "dev.engine_room.flywheel.impl.FlwLibLinkImpl");

Logger getLogger();

PoseTransformStack getPoseTransformStackOf(PoseStack stack);

Map<String, ModelPart> getModelPartChildren(ModelPart part);

void compileModelPart(ModelPart part, PoseStack.Pose pose, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import dev.engine_room.flywheel.api.internal.DependencyInjection;
import dev.engine_room.flywheel.lib.model.baked.BakedModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.BlockModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.ItemModelBuilder;
import dev.engine_room.flywheel.lib.model.baked.MultiBlockModelBuilder;
import dev.engine_room.flywheel.lib.util.ShadersModHandler;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;

Expand All @@ -26,4 +28,6 @@ public interface FlwLibXplat {

@Nullable
ShadersModHandler.InternalHandler createIrisHandler();

ItemModelBuilder createItemModelBuilder(ItemStack stack, BakedModel model);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.engine_room.flywheel.lib.material;

import dev.engine_room.flywheel.api.material.DepthTest;
import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.api.material.Transparency;
import dev.engine_room.flywheel.api.material.WriteMask;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.resources.ResourceLocation;

public final class Materials {
Expand Down Expand Up @@ -69,6 +72,21 @@ public final class Materials {
.mipmap(false)
.build();

public static final Material GLINT = SimpleMaterial.builder()
.texture(ItemRenderer.ENCHANTED_GLINT_ITEM)
.shaders(StandardMaterialShaders.GLINT)
.transparency(Transparency.GLINT)
.writeMask(WriteMask.COLOR)
.depthTest(DepthTest.EQUAL)
.backfaceCulling(false)
.blur(true)
.mipmap(false)
.build();

public static final Material GLINT_ENTITY = SimpleMaterial.builderOf(GLINT)
.texture(ItemRenderer.ENCHANTED_GLINT_ENTITY)
.build();

private Materials() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,38 @@ public boolean diffuse() {
return diffuse;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

SimpleMaterial that = (SimpleMaterial) o;
return blur == that.blur && mipmap == that.mipmap && backfaceCulling == that.backfaceCulling && polygonOffset == that.polygonOffset && useOverlay == that.useOverlay && useLight == that.useLight && diffuse == that.diffuse && shaders.equals(that.shaders) && fog.equals(that.fog) && cutout.equals(that.cutout) && texture.equals(that.texture) && depthTest == that.depthTest && transparency == that.transparency && writeMask == that.writeMask;
}

@Override
public int hashCode() {
int result = shaders.hashCode();
result = 31 * result + fog.hashCode();
result = 31 * result + cutout.hashCode();
result = 31 * result + texture.hashCode();
result = 31 * result + Boolean.hashCode(blur);
result = 31 * result + Boolean.hashCode(mipmap);
result = 31 * result + Boolean.hashCode(backfaceCulling);
result = 31 * result + Boolean.hashCode(polygonOffset);
result = 31 * result + depthTest.hashCode();
result = 31 * result + transparency.hashCode();
result = 31 * result + writeMask.hashCode();
result = 31 * result + Boolean.hashCode(useOverlay);
result = 31 * result + Boolean.hashCode(useLight);
result = 31 * result + Boolean.hashCode(diffuse);
return result;
}

public static class Builder implements Material {
protected MaterialShaders shaders;
protected FogShader fog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public final class StandardMaterialShaders {

public static final MaterialShaders LINE = MaterialShaders.REGISTRY.registerAndGet(new SimpleMaterialShaders(Flywheel.rl("material/lines.vert"), Flywheel.rl("material/lines.frag")));

public static final MaterialShaders GLINT = MaterialShaders.REGISTRY.registerAndGet(new SimpleMaterialShaders(Flywheel.rl("material/glint.vert"), Flywheel.rl("material/default.frag")));

private StandardMaterialShaders() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dev.engine_room.flywheel.lib.memory.MemoryBlock;
import dev.engine_room.flywheel.lib.vertex.PosVertexView;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;

public final class ModelUtil {
Expand Down Expand Up @@ -48,6 +49,35 @@ public static Material getMaterial(RenderType chunkRenderType, boolean shaded) {
return null;
}

@Nullable
public static Material getItemMaterial(RenderType renderType, boolean shaded) {
if (renderType == RenderType.solid()) {
return shaded ? Materials.CHUNK_SOLID_SHADED : Materials.CHUNK_SOLID_UNSHADED;
}
if (renderType == RenderType.cutoutMipped()) {
return shaded ? Materials.CHUNK_CUTOUT_MIPPED_SHADED : Materials.CHUNK_CUTOUT_MIPPED_UNSHADED;
}
if (renderType == RenderType.cutout() || renderType == Sheets.cutoutBlockSheet()) {
return shaded ? Materials.CHUNK_CUTOUT_SHADED : Materials.CHUNK_CUTOUT_UNSHADED;
}
if (renderType == RenderType.translucent()) {
return shaded ? Materials.CHUNK_TRANSLUCENT_SHADED : Materials.CHUNK_TRANSLUCENT_UNSHADED;
}
if (renderType == RenderType.tripwire()) {
return shaded ? Materials.CHUNK_TRIPWIRE_SHADED : Materials.CHUNK_TRIPWIRE_UNSHADED;
}
if (renderType == Sheets.translucentCullBlockSheet() || renderType == Sheets.translucentItemSheet()) {
return shaded ? Materials.CHUNK_CUTOUT_SHADED : Materials.CHUNK_CUTOUT_UNSHADED;
}
if (renderType == RenderType.glint() || renderType == RenderType.glintDirect()) {
return Materials.GLINT;
}
if (renderType == RenderType.entityGlint() || renderType == RenderType.entityGlintDirect()) {
return Materials.GLINT_ENTITY;
}
return null;
}

public static int computeTotalVertexCount(Iterable<Mesh> meshes) {
int vertexCount = 0;
for (Mesh mesh : meshes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dev.engine_room.flywheel.lib.model;

import org.joml.Vector4fc;

import dev.engine_room.flywheel.api.model.IndexSequence;
import dev.engine_room.flywheel.api.model.Mesh;
import dev.engine_room.flywheel.api.vertex.MutableVertexList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;

public record RetexturedMesh(Mesh mesh, TextureAtlasSprite sprite) implements Mesh {
@Override
public int vertexCount() {
return mesh.vertexCount();
}

@Override
public void write(MutableVertexList vertexList) {
mesh.write(new RetexturingVertexList(vertexList, sprite));
}

@Override
public IndexSequence indexSequence() {
return mesh.indexSequence();
}

@Override
public int indexCount() {
return mesh.indexCount();
}

@Override
public Vector4fc boundingSphere() {
return mesh.boundingSphere();
}

@Override
public void delete() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.engine_room.flywheel.lib.model;

import dev.engine_room.flywheel.api.vertex.MutableVertexList;
import dev.engine_room.flywheel.lib.vertex.WrappedVertexList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;

/**
* A wrapper so that differently textured models from the same mesh tree can share the same backing memory
*/
public class RetexturingVertexList extends WrappedVertexList {
private final TextureAtlasSprite sprite;

public RetexturingVertexList(MutableVertexList delegate, TextureAtlasSprite sprite) {
super(delegate);

this.sprite = sprite;
}

@Override
public void u(int index, float u) {
super.u(index, sprite.getU(u * 16));
}

@Override
public void v(int index, float v) {
super.v(index, sprite.getV(v * 16));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dev.engine_room.flywheel.lib.model.baked;

import java.util.function.BiFunction;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import com.mojang.blaze3d.vertex.PoseStack;

import dev.engine_room.flywheel.api.material.Material;
import dev.engine_room.flywheel.lib.internal.FlwLibXplat;
import dev.engine_room.flywheel.lib.model.SimpleModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;

@ApiStatus.NonExtendable
public abstract class ItemModelBuilder {
final ItemStack itemStack;
final BakedModel model;
@Nullable
PoseStack poseStack;
@Nullable
ItemDisplayContext displayContext;
boolean leftHand;
@Nullable
BiFunction<RenderType, Boolean, Material> materialFunc;

ItemModelBuilder(ItemStack itemStack, BakedModel model) {
this.itemStack = itemStack;
this.model = model;
}

public static ItemModelBuilder create(ItemStack stack, BakedModel model) {
return FlwLibXplat.INSTANCE.createItemModelBuilder(stack, model);
}

public ItemModelBuilder poseStack(PoseStack poseStack) {
this.poseStack = poseStack;
return this;
}

public ItemModelBuilder displayContext(ItemDisplayContext displayContext) {
this.displayContext = displayContext;
return this;
}

public ItemModelBuilder leftHand(boolean leftHand) {
this.leftHand = leftHand;
return this;
}

public ItemModelBuilder materialFunc(BiFunction<RenderType, Boolean, Material> materialFunc) {
this.materialFunc = materialFunc;
return this;
}

public abstract SimpleModel build();
}
Loading

0 comments on commit f5a6e5a

Please sign in to comment.