Skip to content

Commit

Permalink
Glimpse of glint
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Jozufozu committed Sep 29, 2024
1 parent bd0aadf commit 0a01b82
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -93,6 +94,8 @@ public static void update(RenderContext context) {

ptr += 96;

ptr = writeCullData(ptr);

ptr = writeMatrices(ptr);

ptr = writeRenderOrigin(ptr, renderOrigin);
Expand All @@ -113,8 +116,6 @@ public static void update(RenderContext context) {

ptr = writeInt(ptr, debugMode);

ptr = writeCullData(ptr);

firstWrite = false;
BUFFER.markDirty();
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,15 +53,15 @@ 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;
/** 0 means no block. Use FLW_CAMERA_IN_BLOCK_* defines to detect block type. */
uint flw_cameraInBlock;

uint _flw_debugMode;

_FlwCullData _flw_cullData;
};

#define flw_renderOrigin (_flw_renderOrigin.xyz)
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}
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,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<Mesh> meshes) {
int vertexCount = 0;
for (Mesh mesh : meshes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.);
}

0 comments on commit 0a01b82

Please sign in to comment.