mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
The origin of all your problems
- Expose an ivec3 flw_renderOrigin in the shader api - Internally add flw_renderOrigin in flw_light(*) - flw_lightFetch expects an actual world position still
This commit is contained in:
parent
fe89e0024a
commit
8dce80ba61
6 changed files with 42 additions and 10 deletions
|
@ -17,7 +17,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 * 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);
|
static final UniformBuffer BUFFER = new UniformBuffer(Uniforms.FRAME_INDEX, SIZE);
|
||||||
|
|
||||||
private static final Matrix4f VIEW = new Matrix4f();
|
private static final Matrix4f VIEW = new Matrix4f();
|
||||||
|
@ -94,6 +94,8 @@ public final class FrameUniforms extends UniformWriter {
|
||||||
|
|
||||||
ptr = writeMatrices(ptr);
|
ptr = writeMatrices(ptr);
|
||||||
|
|
||||||
|
ptr = writeRenderOrigin(ptr, renderOrigin);
|
||||||
|
|
||||||
ptr = writeCamera(ptr);
|
ptr = writeCamera(ptr);
|
||||||
|
|
||||||
var window = Minecraft.getInstance()
|
var window = Minecraft.getInstance()
|
||||||
|
@ -114,6 +116,11 @@ public final class FrameUniforms extends UniformWriter {
|
||||||
BUFFER.markDirty();
|
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() {
|
private static void setPrev() {
|
||||||
VIEW_PREV.set(VIEW);
|
VIEW_PREV.set(VIEW);
|
||||||
PROJECTION_PREV.set(PROJECTION);
|
PROJECTION_PREV.set(PROJECTION);
|
||||||
|
|
|
@ -45,6 +45,28 @@ class UniformWriter {
|
||||||
return ptr + 16;
|
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) {
|
static long writeMat4(long ptr, Matrix4f mat) {
|
||||||
ExtraMemoryOps.putMatrix4f(ptr, mat);
|
ExtraMemoryOps.putMatrix4f(ptr, mat);
|
||||||
return ptr + 64;
|
return ptr + 64;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// TODO: Add config for light smoothness. Should work at a compile flag level
|
// 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.
|
/// This may be interpolated for smooth lighting.
|
||||||
bool flw_light(vec3 worldPos, vec3 normal, out vec2 light);
|
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.
|
/// This may be interpolated for smooth lighting.
|
||||||
bool flw_light(vec3 worldPos, out vec2 light);
|
bool flw_light(vec3 worldPos, out vec2 light);
|
||||||
|
|
||||||
|
|
|
@ -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.
|
// 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
|
// 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.
|
// 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;
|
uint lightSectionIndex;
|
||||||
if (_flw_chunkCoordToSectionIndex(blockPos >> 4, 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.
|
// 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
|
// 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.
|
// 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;
|
uint lightSectionIndex;
|
||||||
if (_flw_chunkCoordToSectionIndex(blockPos >> 4, lightSectionIndex)) {
|
if (_flw_chunkCoordToSectionIndex(blockPos >> 4, lightSectionIndex)) {
|
||||||
|
|
|
@ -22,6 +22,8 @@ layout(std140) uniform _FlwFrameUniforms {
|
||||||
mat4 flw_viewProjectionInverse;
|
mat4 flw_viewProjectionInverse;
|
||||||
mat4 flw_viewProjectionPrev;
|
mat4 flw_viewProjectionPrev;
|
||||||
|
|
||||||
|
ivec4 _flw_renderOrigin;
|
||||||
|
|
||||||
vec4 _flw_cameraPos;
|
vec4 _flw_cameraPos;
|
||||||
vec4 _flw_cameraPosPrev;
|
vec4 _flw_cameraPosPrev;
|
||||||
vec4 _flw_cameraLook;
|
vec4 _flw_cameraLook;
|
||||||
|
@ -47,10 +49,11 @@ layout(std140) uniform _FlwFrameUniforms {
|
||||||
uint _flw_debugMode;
|
uint _flw_debugMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define flw_cameraPos _flw_cameraPos.xyz
|
#define flw_renderOrigin (_flw_renderOrigin.xyz)
|
||||||
#define flw_cameraLook _flw_cameraLook.xyz
|
#define flw_cameraPos (_flw_cameraPos.xyz)
|
||||||
#define flw_cameraPosPrev _flw_cameraPosPrev.xyz
|
#define flw_cameraLook (_flw_cameraLook.xyz)
|
||||||
#define flw_cameraLookPrev _flw_cameraLookPrev.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_WATER 1
|
||||||
#define FLW_CAMERA_IN_FLUID_LAVA 2
|
#define FLW_CAMERA_IN_FLUID_LAVA 2
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
void flw_shaderLight() {
|
void flw_shaderLight() {
|
||||||
vec2 embeddedLight;
|
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);
|
flw_fragLight = max(flw_fragLight, embeddedLight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue