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 e85b71356..33bb81901 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 @@ -17,7 +17,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 * 4 + 8 * 2 + 8 + 4 * 10; + private static final int SIZE = 96 + 64 * 9 + 16 * 5 + 8 * 2 + 8 + 4 * 10; static final UniformBuffer BUFFER = new UniformBuffer(Uniforms.FRAME_INDEX, SIZE); private static final Matrix4f VIEW = new Matrix4f(); @@ -94,6 +94,8 @@ public final class FrameUniforms extends UniformWriter { ptr = writeMatrices(ptr); + ptr = writeRenderOrigin(ptr, renderOrigin); + ptr = writeCamera(ptr); var window = Minecraft.getInstance() @@ -114,6 +116,11 @@ public final class FrameUniforms extends UniformWriter { BUFFER.markDirty(); } + private static long writeRenderOrigin(long ptr, Vec3i renderOrigin) { + ptr = writeIVec3(ptr, renderOrigin.getX(), renderOrigin.getY(), renderOrigin.getZ()); + return ptr; + } + private static void setPrev() { VIEW_PREV.set(VIEW); PROJECTION_PREV.set(PROJECTION); diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/UniformWriter.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/UniformWriter.java index 022cc8c8c..7c3bd709f 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/UniformWriter.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/UniformWriter.java @@ -45,6 +45,28 @@ class UniformWriter { return ptr + 16; } + static long writeIVec2(long ptr, int x, int y) { + MemoryUtil.memPutInt(ptr, x); + MemoryUtil.memPutInt(ptr + 4, y); + return ptr + 8; + } + + static long writeIVec3(long ptr, int x, int y, int z) { + MemoryUtil.memPutInt(ptr, x); + MemoryUtil.memPutInt(ptr + 4, y); + MemoryUtil.memPutInt(ptr + 8, z); + MemoryUtil.memPutInt(ptr + 12, 0); // empty component of vec4 because we don't trust std140 + return ptr + 16; + } + + static long writeIVec4(long ptr, int x, int y, int z, int w) { + MemoryUtil.memPutInt(ptr, x); + MemoryUtil.memPutInt(ptr + 4, y); + MemoryUtil.memPutInt(ptr + 8, z); + MemoryUtil.memPutInt(ptr + 12, w); + return ptr + 16; + } + static long writeMat4(long ptr, Matrix4f mat) { ExtraMemoryOps.putMatrix4f(ptr, mat); return ptr + 64; diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/api_impl.glsl b/common/src/backend/resources/assets/flywheel/flywheel/internal/api_impl.glsl index a839a81c2..875a01ffd 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/api_impl.glsl +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/api_impl.glsl @@ -1,10 +1,10 @@ // TODO: Add config for light smoothness. Should work at a compile flag level -/// Get the light at the given world position from the given normal. +/// Get the light at the given world position relative to flw_renderOrigin from the given normal. /// This may be interpolated for smooth lighting. bool flw_light(vec3 worldPos, vec3 normal, out vec2 light); -/// Get the light at the given world position. +/// Get the light at the given world position relative to flw_renderOrigin. /// This may be interpolated for smooth lighting. bool flw_light(vec3 worldPos, out vec2 light); diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl b/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl index 4d864928c..84aca1f3e 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/light_lut.glsl @@ -82,7 +82,7 @@ bool flw_light(vec3 worldPos, out vec2 lightCoord) { // Always use the section of the block we are contained in to ensure accuracy. // We don't want to interpolate between sections, but also we might not be able // to rely on the existence neighboring sections, so don't do any extra rounding here. - ivec3 blockPos = ivec3(floor(worldPos)); + ivec3 blockPos = ivec3(floor(worldPos)) + flw_renderOrigin; uint lightSectionIndex; if (_flw_chunkCoordToSectionIndex(blockPos >> 4, lightSectionIndex)) { @@ -182,7 +182,7 @@ bool flw_light(vec3 worldPos, vec3 normal, out vec2 lightCoord) { // Always use the section of the block we are contained in to ensure accuracy. // We don't want to interpolate between sections, but also we might not be able // to rely on the existence neighboring sections, so don't do any extra rounding here. - ivec3 blockPos = ivec3(floor(worldPos)); + ivec3 blockPos = ivec3(floor(worldPos)) + flw_renderOrigin; uint lightSectionIndex; if (_flw_chunkCoordToSectionIndex(blockPos >> 4, lightSectionIndex)) { 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 5131f8ab0..4b3cfe69f 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 @@ -22,6 +22,8 @@ layout(std140) uniform _FlwFrameUniforms { mat4 flw_viewProjectionInverse; mat4 flw_viewProjectionPrev; + ivec4 _flw_renderOrigin; + vec4 _flw_cameraPos; vec4 _flw_cameraPosPrev; vec4 _flw_cameraLook; @@ -47,10 +49,11 @@ layout(std140) uniform _FlwFrameUniforms { uint _flw_debugMode; }; -#define flw_cameraPos _flw_cameraPos.xyz -#define flw_cameraLook _flw_cameraLook.xyz -#define flw_cameraPosPrev _flw_cameraPosPrev.xyz -#define flw_cameraLookPrev _flw_cameraLookPrev.xyz +#define flw_renderOrigin (_flw_renderOrigin.xyz) +#define flw_cameraPos (_flw_cameraPos.xyz) +#define flw_cameraLook (_flw_cameraLook.xyz) +#define flw_cameraPosPrev (_flw_cameraPosPrev.xyz) +#define flw_cameraLookPrev (_flw_cameraLookPrev.xyz) #define FLW_CAMERA_IN_FLUID_WATER 1 #define FLW_CAMERA_IN_FLUID_LAVA 2 diff --git a/common/src/lib/resources/assets/flywheel/flywheel/light/flat.glsl b/common/src/lib/resources/assets/flywheel/flywheel/light/flat.glsl index 365924db7..017929019 100644 --- a/common/src/lib/resources/assets/flywheel/flywheel/light/flat.glsl +++ b/common/src/lib/resources/assets/flywheel/flywheel/light/flat.glsl @@ -1,6 +1,6 @@ void flw_shaderLight() { vec2 embeddedLight; - if (flw_lightFetch(ivec3(floor(flw_vertexPos.xyz)), embeddedLight)) { + if (flw_lightFetch(ivec3(floor(flw_vertexPos.xyz)) + flw_renderOrigin, embeddedLight)) { flw_fragLight = max(flw_fragLight, embeddedLight); } }