Compare commits

..

No commits in common. "f380256482429b093810e32fb589b1b277f1a576" and "5399b0fc50cd72ed6d2b5207d90ebcddee8ff257" have entirely different histories.

7 changed files with 74 additions and 20 deletions

View File

@ -84,7 +84,6 @@ public class IndirectPrograms extends AtomicReferenceCounted {
.withResource(CULL_SHADER_MAIN)) .withResource(CULL_SHADER_MAIN))
.postLink((key, program) -> { .postLink((key, program) -> {
program.setUniformBlockBinding("_FlwFrameUniforms", Uniforms.FRAME_INDEX); program.setUniformBlockBinding("_FlwFrameUniforms", Uniforms.FRAME_INDEX);
program.setUniformBlockBinding("_FlwFogUniforms", Uniforms.FOG_INDEX);
program.setUniformBlockBinding("_FlwOptionsUniforms", Uniforms.OPTIONS_INDEX); program.setUniformBlockBinding("_FlwOptionsUniforms", Uniforms.OPTIONS_INDEX);
program.setUniformBlockBinding("_FlwPlayerUniforms", Uniforms.PLAYER_INDEX); program.setUniformBlockBinding("_FlwPlayerUniforms", Uniforms.PLAYER_INDEX);
program.setUniformBlockBinding("_FlwLevelUniforms", Uniforms.LEVEL_INDEX); program.setUniformBlockBinding("_FlwLevelUniforms", Uniforms.LEVEL_INDEX);

View File

@ -38,6 +38,13 @@ public class FrameUniforms implements UniformProvider {
private final Matrix4f viewProjectionInverse = new Matrix4f(); private final Matrix4f viewProjectionInverse = new Matrix4f();
private final Matrix4f viewProjectionPrev = new Matrix4f(); private final Matrix4f viewProjectionPrev = new Matrix4f();
private final Matrix4f cleanProjection = new Matrix4f();
private final Matrix4f cleanProjectionInverse = new Matrix4f();
private final Matrix4f cleanProjectionPrev = new Matrix4f();
private final Matrix4f cleanViewProjection = new Matrix4f();
private final Matrix4f cleanViewProjectionInverse = new Matrix4f();
private final Matrix4f cleanViewProjectionPrev = new Matrix4f();
private final Vector3f cameraPositionPrev = new Vector3f(); private final Vector3f cameraPositionPrev = new Vector3f();
private final Vector3f cameraLookPrev = new Vector3f(); private final Vector3f cameraLookPrev = new Vector3f();
private final Vector2f cameraRotPrev = new Vector2f(); private final Vector2f cameraRotPrev = new Vector2f();
@ -72,6 +79,7 @@ public class FrameUniforms implements UniformProvider {
projection.set(context.projection()); projection.set(context.projection());
viewProjection.set(context.viewProjection()); viewProjection.set(context.viewProjection());
viewProjection.translate(-camX, -camY, -camZ); viewProjection.translate(-camX, -camY, -camZ);
setupCleanMatrices(context.stack(), camera, context.partialTick());
if (!Uniforms.frustumPaused || Uniforms.frustumCapture) { if (!Uniforms.frustumPaused || Uniforms.frustumCapture) {
MatrixMath.writePackedFrustumPlanes(ptr, viewProjection); MatrixMath.writePackedFrustumPlanes(ptr, viewProjection);
@ -85,11 +93,15 @@ public class FrameUniforms implements UniformProvider {
viewPrev.set(view); viewPrev.set(view);
projectionPrev.set(projection); projectionPrev.set(projection);
viewProjectionPrev.set(viewProjectionPrev); viewProjectionPrev.set(viewProjectionPrev);
cleanProjectionPrev.set(cleanProjection);
cleanViewProjectionPrev.set(cleanViewProjection);
} }
ptr = writeMatrices(ptr); ptr = writeMatrices(ptr);
viewPrev.set(view); viewPrev.set(view);
projectionPrev.set(projection); projectionPrev.set(projection);
viewProjectionPrev.set(viewProjection); viewProjectionPrev.set(viewProjection);
cleanProjectionPrev.set(cleanProjection);
cleanViewProjectionPrev.set(cleanViewProjection);
// last values for camera // last values for camera
if (!lastInit) { if (!lastInit) {
@ -116,6 +128,9 @@ public class FrameUniforms implements UniformProvider {
MemoryUtil.memPutFloat(ptr, Minecraft.getInstance().gameRenderer.getDepthFar()); MemoryUtil.memPutFloat(ptr, Minecraft.getInstance().gameRenderer.getDepthFar());
ptr += 4; ptr += 4;
MemoryUtil.memPutInt(ptr, getConstantAmbientLightFlag(context));
ptr += 4;
ptr = writeTime(ptr); ptr = writeTime(ptr);
ptr = writeCameraIn(ptr); ptr = writeCameraIn(ptr);
@ -135,9 +150,35 @@ public class FrameUniforms implements UniformProvider {
MatrixMath.writeUnsafe(viewProjection, ptr + 64 * 6); MatrixMath.writeUnsafe(viewProjection, ptr + 64 * 6);
MatrixMath.writeUnsafe(viewProjection.invert(viewProjectionInverse), ptr + 64 * 7); MatrixMath.writeUnsafe(viewProjection.invert(viewProjectionInverse), ptr + 64 * 7);
MatrixMath.writeUnsafe(viewProjectionPrev, ptr + 64 * 8); MatrixMath.writeUnsafe(viewProjectionPrev, ptr + 64 * 8);
MatrixMath.writeUnsafe(cleanProjection, ptr + 64 * 9);
MatrixMath.writeUnsafe(cleanProjection.invert(cleanProjectionInverse), ptr + 64 * 10);
MatrixMath.writeUnsafe(cleanProjectionPrev, ptr + 64 * 11);
MatrixMath.writeUnsafe(cleanViewProjection, ptr + 64 * 12);
MatrixMath.writeUnsafe(cleanViewProjection.invert(cleanViewProjectionInverse), ptr + 64 * 13);
MatrixMath.writeUnsafe(cleanViewProjectionPrev, ptr + 64 * 14);
return ptr + 64 * 15; return ptr + 64 * 15;
} }
private void setupCleanMatrices(PoseStack stack, Camera camera, float partialTicks) {
Minecraft mc = Minecraft.getInstance();
GameRenderer gr = mc.gameRenderer;
GameRendererAccessor gra = (GameRendererAccessor) gr;
float fov = (float) gra.flywheel$getFov(camera, partialTicks, true);
cleanProjection.identity();
if (gra.flywheel$getZoom() != 1.0F) {
cleanProjection.translate(gra.flywheel$getZoomX(), -gra.flywheel$getZoomY(), 0.0F);
cleanProjection.scale(gra.flywheel$getZoom(), gra.flywheel$getZoom(), 1.0F);
}
cleanProjection.mul(new Matrix4f().setPerspective(fov * ((float) Math.PI / 180F),
(float) mc.getWindow().getWidth() / (float) mc.getWindow().getHeight(), 0.05F, gr.getDepthFar()));
cleanViewProjection.set(cleanProjection).mul(stack.last().pose());
}
private long writeCamera(long ptr, float camX, float camY, float camZ) { private long writeCamera(long ptr, float camX, float camY, float camZ) {
Camera camera = context.camera(); Camera camera = context.camera();
Vector3f lookVector = camera.getLookVector(); Vector3f lookVector = camera.getLookVector();
@ -179,4 +220,11 @@ public class FrameUniforms implements UniformProvider {
Vec3 cameraPos = camera.getPosition(); Vec3 cameraPos = camera.getPosition();
return Uniforms.writeInFluidAndBlock(ptr, level, blockPos, cameraPos); return Uniforms.writeInFluidAndBlock(ptr, level, blockPos, cameraPos);
} }
private static int getConstantAmbientLightFlag(RenderContext context) {
var constantAmbientLight = context.level()
.effects()
.constantAmbientLight();
return constantAmbientLight ? 1 : 0;
}
} }

View File

@ -28,15 +28,16 @@ public class LevelUniforms implements UniformProvider {
@Override @Override
public void write(long ptr) { public void write(long ptr) {
if (context == null) { Minecraft mc = Minecraft.getInstance();
ClientLevel level = mc.level;
if (level == null || context == null) {
MemoryUtil.memSet(ptr, 0, SIZE); MemoryUtil.memSet(ptr, 0, SIZE);
return; return;
} }
ClientLevel level = context.level();
float ptick = context.partialTick(); float ptick = context.partialTick();
Vec3 skyColor = level.getSkyColor(context.camera().getPosition(), ptick); Vec3 skyColor = level.getSkyColor(mc.gameRenderer.getMainCamera().getPosition(), ptick);
ptr = Uniforms.writeVec4(ptr, (float) skyColor.x, (float) skyColor.y, (float) skyColor.z, 1f); ptr = Uniforms.writeVec4(ptr, (float) skyColor.x, (float) skyColor.y, (float) skyColor.z, 1f);
Vec3 cloudColor = level.getCloudColor(ptick); Vec3 cloudColor = level.getCloudColor(ptick);
@ -75,9 +76,6 @@ public class LevelUniforms implements UniformProvider {
MemoryUtil.memPutFloat(ptr, level.getSkyDarken(ptick)); MemoryUtil.memPutFloat(ptr, level.getSkyDarken(ptick));
ptr += 4; ptr += 4;
MemoryUtil.memPutInt(ptr, getConstantAmbientLightFlag(context));
ptr += 4;
// TODO: use defines for custom dimension ids // TODO: use defines for custom dimension ids
int dimensionId; int dimensionId;
ResourceKey<Level> dimension = level.dimension(); ResourceKey<Level> dimension = level.dimension();
@ -92,11 +90,4 @@ public class LevelUniforms implements UniformProvider {
} }
MemoryUtil.memPutInt(ptr, dimensionId); MemoryUtil.memPutInt(ptr, dimensionId);
} }
private static int getConstantAmbientLightFlag(RenderContext context) {
var constantAmbientLight = context.level()
.effects()
.constantAmbientLight();
return constantAmbientLight ? 1 : 0;
}
} }

View File

@ -12,12 +12,12 @@ import net.minecraft.client.Options;
@Mixin(Options.class) @Mixin(Options.class)
public class OptionsMixin { public class OptionsMixin {
@Inject(method = "load()V", at = @At("RETURN")) @Inject(method = "load()V", at = @At("RETURN"))
private void flywheel$onLoad(CallbackInfo ci) { private void onLoad(CallbackInfo ci) {
Uniforms.onOptionsUpdate(); Uniforms.onOptionsUpdate();
} }
@Inject(method = "save", at = @At("HEAD")) @Inject(method = "save", at = @At("HEAD"))
private void flywheel$onSave(CallbackInfo ci) { private void onSave(CallbackInfo ci) {
Uniforms.onOptionsUpdate(); Uniforms.onOptionsUpdate();
} }
} }

View File

@ -1,7 +1,10 @@
#include "flywheel:internal/indirect/buffers.glsl" #include "flywheel:internal/indirect/buffers.glsl"
#include "flywheel:internal/indirect/model_descriptor.glsl" #include "flywheel:internal/indirect/model_descriptor.glsl"
#include "flywheel:internal/indirect/object.glsl" #include "flywheel:internal/indirect/object.glsl"
#include "flywheel:internal/uniforms/uniforms.glsl" #include "flywheel:internal/uniforms/frame.glsl"
#include "flywheel:internal/uniforms/options.glsl"
#include "flywheel:internal/uniforms/player.glsl"
#include "flywheel:internal/uniforms/level.glsl"
#include "flywheel:util/matrix.glsl" #include "flywheel:util/matrix.glsl"
layout(local_size_x = _FLW_SUBGROUP_SIZE) in; layout(local_size_x = _FLW_SUBGROUP_SIZE) in;

View File

@ -1,3 +1,9 @@
// Cull shaders may not need all uniforms, but it is #include "flywheel:internal/uniforms/frame.glsl"
// more consistent if we just provide all uniforms anyways.
#include "flywheel:internal/uniforms/uniforms.glsl" // Fog doesn't seem like a valid thing to query during the cull pass. Other uniforms added in the
// future may also be excluded, and we'll have to document each one.
// #include "flywheel:internal/uniforms/fog.glsl"
#include "flywheel:internal/uniforms/options.glsl"
#include "flywheel:internal/uniforms/player.glsl"
#include "flywheel:internal/uniforms/level.glsl"

View File

@ -22,6 +22,13 @@ layout(std140) uniform _FlwFrameUniforms {
mat4 flw_viewProjectionInverse; mat4 flw_viewProjectionInverse;
mat4 flw_viewProjectionPrev; mat4 flw_viewProjectionPrev;
mat4 flw_cleanProjection;
mat4 flw_cleanProjectionInverse;
mat4 flw_cleanProjectionPrev;
mat4 flw_cleanViewProjection;
mat4 flw_cleanViewProjectionInverse;
mat4 flw_cleanViewProjectionPrev;
vec4 _flw_cameraPos; vec4 _flw_cameraPos;
vec4 _flw_cameraPosPrev; vec4 _flw_cameraPosPrev;
vec4 _flw_cameraLook; vec4 _flw_cameraLook;