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.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.level.Level;
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 final class FrameUniforms extends UniformWriter {
ptr += 96;
ptr = writeCullData(ptr);
ptr = writeMatrices(ptr);
ptr = writeRenderOrigin(ptr, renderOrigin);
@ -113,8 +116,6 @@ public final class FrameUniforms extends UniformWriter {
ptr = writeInt(ptr, debugMode);
ptr = writeCullData(ptr);
firstWrite = false;
BUFFER.markDirty();
}
@ -161,11 +162,15 @@ public final class FrameUniforms extends UniformWriter {
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;
}

View File

@ -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)

View File

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

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 GLINT = new SimpleMaterialShaders(Flywheel.rl("material/glint.vert"), Flywheel.rl("material/default.frag"));
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.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 final class ModelUtil {
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) {
int vertexCount = 0;
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.);
}