Glimpse of glint

- Add pick glint material and system time uniform
- Move _FlwCullData to beginning of uniform block to ensure alignment
- Add helper to convert item rendertype into flywheel material
This commit is contained in:
Jozufozu 2024-09-28 23:27:28 -07:00
parent bd0aadf9d9
commit 0a01b82647
6 changed files with 61 additions and 5 deletions

View file

@ -10,6 +10,7 @@ import dev.engine_room.flywheel.api.RenderContext;
import dev.engine_room.flywheel.api.visualization.VisualizationManager; import dev.engine_room.flywheel.api.visualization.VisualizationManager;
import dev.engine_room.flywheel.backend.engine.indirect.DepthPyramid; import dev.engine_room.flywheel.backend.engine.indirect.DepthPyramid;
import dev.engine_room.flywheel.backend.mixin.LevelRendererAccessor; import dev.engine_room.flywheel.backend.mixin.LevelRendererAccessor;
import net.minecraft.Util;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -18,7 +19,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
public final class FrameUniforms extends UniformWriter { 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); static final UniformBuffer BUFFER = new UniformBuffer(Uniforms.FRAME_INDEX, SIZE);
private static final Matrix4f VIEW = new Matrix4f(); private static final Matrix4f VIEW = new Matrix4f();
@ -93,6 +94,8 @@ public final class FrameUniforms extends UniformWriter {
ptr += 96; ptr += 96;
ptr = writeCullData(ptr);
ptr = writeMatrices(ptr); ptr = writeMatrices(ptr);
ptr = writeRenderOrigin(ptr, renderOrigin); ptr = writeRenderOrigin(ptr, renderOrigin);
@ -113,8 +116,6 @@ public final class FrameUniforms extends UniformWriter {
ptr = writeInt(ptr, debugMode); ptr = writeInt(ptr, debugMode);
ptr = writeCullData(ptr);
firstWrite = false; firstWrite = false;
BUFFER.markDirty(); BUFFER.markDirty();
} }
@ -161,11 +162,15 @@ public final class FrameUniforms extends UniformWriter {
float partialTick = context.partialTick(); float partialTick = context.partialTick();
float renderTicks = ticks + partialTick; float renderTicks = ticks + partialTick;
float renderSeconds = renderTicks / 20f; float renderSeconds = renderTicks / 20f;
float systemSeconds = Util.getMillis() / 1000f;
int systemMillis = (int) (Util.getMillis() % Integer.MAX_VALUE);
ptr = writeInt(ptr, ticks); ptr = writeInt(ptr, ticks);
ptr = writeFloat(ptr, partialTick); ptr = writeFloat(ptr, partialTick);
ptr = writeFloat(ptr, renderTicks); ptr = writeFloat(ptr, renderTicks);
ptr = writeFloat(ptr, renderSeconds); ptr = writeFloat(ptr, renderSeconds);
ptr = writeFloat(ptr, systemSeconds);
ptr = writeInt(ptr, systemMillis);
return ptr; return ptr;
} }

View file

@ -23,6 +23,8 @@ struct _FlwCullData {
layout(std140) uniform _FlwFrameUniforms { layout(std140) uniform _FlwFrameUniforms {
FrustumPlanes flw_frustumPlanes; FrustumPlanes flw_frustumPlanes;
_FlwCullData _flw_cullData;
mat4 flw_view; mat4 flw_view;
mat4 flw_viewInverse; mat4 flw_viewInverse;
mat4 flw_viewPrev; mat4 flw_viewPrev;
@ -51,6 +53,8 @@ layout(std140) uniform _FlwFrameUniforms {
float flw_partialTick; float flw_partialTick;
float flw_renderTicks; float flw_renderTicks;
float flw_renderSeconds; float flw_renderSeconds;
float flw_systemSeconds;
uint flw_systemMillis;
/** 0 means no fluid. Use FLW_CAMERA_IN_FLUID_* defines to detect fluid type. */ /** 0 means no fluid. Use FLW_CAMERA_IN_FLUID_* defines to detect fluid type. */
uint flw_cameraInFluid; uint flw_cameraInFluid;
@ -58,8 +62,6 @@ layout(std140) uniform _FlwFrameUniforms {
uint flw_cameraInBlock; uint flw_cameraInBlock;
uint _flw_debugMode; uint _flw_debugMode;
_FlwCullData _flw_cullData;
}; };
#define flw_renderOrigin (_flw_renderOrigin.xyz) #define flw_renderOrigin (_flw_renderOrigin.xyz)

View file

@ -1,7 +1,10 @@
package dev.engine_room.flywheel.lib.material; 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.Material;
import dev.engine_room.flywheel.api.material.Transparency; 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 final class Materials {
public static final Material SOLID_BLOCK = SimpleMaterial.builder() public static final Material SOLID_BLOCK = SimpleMaterial.builder()
@ -46,6 +49,21 @@ public final class Materials {
.diffuse(false) .diffuse(false)
.build(); .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() { private Materials() {
} }
} }

View file

@ -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 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() { private StandardMaterialShaders() {
} }
} }

View file

@ -15,6 +15,7 @@ import dev.engine_room.flywheel.lib.material.Materials;
import dev.engine_room.flywheel.lib.memory.MemoryBlock; import dev.engine_room.flywheel.lib.memory.MemoryBlock;
import dev.engine_room.flywheel.lib.vertex.PosVertexView; import dev.engine_room.flywheel.lib.vertex.PosVertexView;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.renderer.block.BlockRenderDispatcher;
public final class ModelUtil { public final class ModelUtil {
@ -48,6 +49,26 @@ public final class ModelUtil {
return null; 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<Mesh> meshes) { public static int computeTotalVertexCount(Iterable<Mesh> meshes) {
int vertexCount = 0; int vertexCount = 0;
for (Mesh mesh : meshes) { for (Mesh mesh : meshes) {

View file

@ -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.);
}