diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java index 82c0d97ed..07e8a9e5c 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java @@ -10,6 +10,7 @@ import dev.engine_room.flywheel.api.visualization.VisualizationManager; import dev.engine_room.flywheel.backend.engine.indirect.DepthPyramid; import dev.engine_room.flywheel.backend.mixin.LevelRendererAccessor; +import net.minecraft.Util; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; @@ -18,7 +19,7 @@ import net.minecraft.world.phys.Vec3; public final class FrameUniforms extends UniformWriter { - private static final int SIZE = 96 + 64 * 9 + 16 * 5 + 8 * 2 + 8 + 4 * 17; + private static final int SIZE = 96 + 64 * 9 + 16 * 5 + 8 * 2 + 8 + 4 * 19; static final UniformBuffer BUFFER = new UniformBuffer(Uniforms.FRAME_INDEX, SIZE); private static final Matrix4f VIEW = new Matrix4f(); @@ -93,6 +94,8 @@ public static void update(RenderContext context) { ptr += 96; + ptr = writeCullData(ptr); + ptr = writeMatrices(ptr); ptr = writeRenderOrigin(ptr, renderOrigin); @@ -113,8 +116,6 @@ public static void update(RenderContext context) { ptr = writeInt(ptr, debugMode); - ptr = writeCullData(ptr); - firstWrite = false; BUFFER.markDirty(); } @@ -161,11 +162,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; } diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl b/common/src/backend/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl index 05b3110dc..f96f502fc 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/uniforms/frame.glsl @@ -23,6 +23,8 @@ struct _FlwCullData { layout(std140) uniform _FlwFrameUniforms { FrustumPlanes flw_frustumPlanes; + _FlwCullData _flw_cullData; + mat4 flw_view; mat4 flw_viewInverse; mat4 flw_viewPrev; @@ -51,6 +53,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; @@ -58,8 +62,6 @@ layout(std140) uniform _FlwFrameUniforms { uint flw_cameraInBlock; uint _flw_debugMode; - - _FlwCullData _flw_cullData; }; #define flw_renderOrigin (_flw_renderOrigin.xyz) diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/material/Materials.java b/common/src/lib/java/dev/engine_room/flywheel/lib/material/Materials.java index 38bbd4ff6..3d72653cd 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/material/Materials.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/material/Materials.java @@ -1,7 +1,10 @@ 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.entity.ItemRenderer; public final class Materials { public static final Material SOLID_BLOCK = SimpleMaterial.builder() @@ -46,6 +49,21 @@ public final class Materials { .diffuse(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() { } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/material/StandardMaterialShaders.java b/common/src/lib/java/dev/engine_room/flywheel/lib/material/StandardMaterialShaders.java index e2f26911b..5aef506bf 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/material/StandardMaterialShaders.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/material/StandardMaterialShaders.java @@ -11,6 +11,8 @@ public final class StandardMaterialShaders { public static final MaterialShaders LINE = new SimpleMaterialShaders(Flywheel.rl("material/lines.vert"), Flywheel.rl("material/lines.frag")); + public static final MaterialShaders GLINT = new SimpleMaterialShaders(Flywheel.rl("material/glint.vert"), Flywheel.rl("material/default.frag")); + private StandardMaterialShaders() { } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java index 4b3bf1d74..17a93e383 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/ModelUtil.java @@ -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 { @@ -48,6 +49,26 @@ public static Material getMaterial(RenderType chunkRenderType, boolean shaded) { return null; } + @Nullable + public static Material getItemMaterial(RenderType renderType, boolean shaded) { + var chunkMaterial = getMaterial(renderType, shaded); + + if (chunkMaterial != null) { + return chunkMaterial; + } + + if (renderType == Sheets.translucentCullBlockSheet() || renderType == Sheets.translucentItemSheet()) { + return shaded ? Materials.CUTOUT_BLOCK : Materials.CUTOUT_UNSHADED_BLOCK; + } + 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 meshes) { int vertexCount = 0; for (Mesh mesh : meshes) { diff --git a/common/src/lib/resources/assets/flywheel/flywheel/material/glint.vert b/common/src/lib/resources/assets/flywheel/flywheel/material/glint.vert new file mode 100644 index 000000000..eca6ddef7 --- /dev/null +++ b/common/src/lib/resources/assets/flywheel/flywheel/material/glint.vert @@ -0,0 +1,8 @@ +void flw_materialVertex() { + float p = flw_glintSpeedOption * flw_systemSeconds * 8.; + + flw_vertexTexCoord *= 8.; + // Rotate by 0.17453292 radians + flw_vertexTexCoord *= mat2(0.98480775, 0.17364817, -0.17364817, 0.98480775); + flw_vertexTexCoord += vec2(-p / 110., p / 30.); +}