Compare commits

..

5 Commits

Author SHA1 Message Date
Kneelawk
f380256482
Remove clean matrices for now 2024-03-05 14:03:49 -08:00
Kneelawk
c84cd0a14a
Level uniforms gets context from context 2024-03-05 13:05:48 -08:00
Kneelawk
b53c6c60bd
Move constant ambient light uniform to level group 2024-03-05 13:03:19 -08:00
Kneelawk
206aa8d312
Provide all uniforms to cull shaders 2024-03-05 12:45:20 -08:00
Kneelawk
d11a6e3b48
Fix mixin method names 2024-03-05 12:35:46 -08:00
7 changed files with 20 additions and 74 deletions

View File

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

View File

@ -38,13 +38,6 @@ public class FrameUniforms implements UniformProvider {
private final Matrix4f viewProjectionInverse = 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 cameraLookPrev = new Vector3f();
private final Vector2f cameraRotPrev = new Vector2f();
@ -79,7 +72,6 @@ public class FrameUniforms implements UniformProvider {
projection.set(context.projection());
viewProjection.set(context.viewProjection());
viewProjection.translate(-camX, -camY, -camZ);
setupCleanMatrices(context.stack(), camera, context.partialTick());
if (!Uniforms.frustumPaused || Uniforms.frustumCapture) {
MatrixMath.writePackedFrustumPlanes(ptr, viewProjection);
@ -93,15 +85,11 @@ public class FrameUniforms implements UniformProvider {
viewPrev.set(view);
projectionPrev.set(projection);
viewProjectionPrev.set(viewProjectionPrev);
cleanProjectionPrev.set(cleanProjection);
cleanViewProjectionPrev.set(cleanViewProjection);
}
ptr = writeMatrices(ptr);
viewPrev.set(view);
projectionPrev.set(projection);
viewProjectionPrev.set(viewProjection);
cleanProjectionPrev.set(cleanProjection);
cleanViewProjectionPrev.set(cleanViewProjection);
// last values for camera
if (!lastInit) {
@ -128,9 +116,6 @@ public class FrameUniforms implements UniformProvider {
MemoryUtil.memPutFloat(ptr, Minecraft.getInstance().gameRenderer.getDepthFar());
ptr += 4;
MemoryUtil.memPutInt(ptr, getConstantAmbientLightFlag(context));
ptr += 4;
ptr = writeTime(ptr);
ptr = writeCameraIn(ptr);
@ -150,35 +135,9 @@ public class FrameUniforms implements UniformProvider {
MatrixMath.writeUnsafe(viewProjection, ptr + 64 * 6);
MatrixMath.writeUnsafe(viewProjection.invert(viewProjectionInverse), ptr + 64 * 7);
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;
}
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) {
Camera camera = context.camera();
Vector3f lookVector = camera.getLookVector();
@ -220,11 +179,4 @@ public class FrameUniforms implements UniformProvider {
Vec3 cameraPos = camera.getPosition();
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,16 +28,15 @@ public class LevelUniforms implements UniformProvider {
@Override
public void write(long ptr) {
Minecraft mc = Minecraft.getInstance();
ClientLevel level = mc.level;
if (level == null || context == null) {
if (context == null) {
MemoryUtil.memSet(ptr, 0, SIZE);
return;
}
ClientLevel level = context.level();
float ptick = context.partialTick();
Vec3 skyColor = level.getSkyColor(mc.gameRenderer.getMainCamera().getPosition(), ptick);
Vec3 skyColor = level.getSkyColor(context.camera().getPosition(), ptick);
ptr = Uniforms.writeVec4(ptr, (float) skyColor.x, (float) skyColor.y, (float) skyColor.z, 1f);
Vec3 cloudColor = level.getCloudColor(ptick);
@ -76,6 +75,9 @@ public class LevelUniforms implements UniformProvider {
MemoryUtil.memPutFloat(ptr, level.getSkyDarken(ptick));
ptr += 4;
MemoryUtil.memPutInt(ptr, getConstantAmbientLightFlag(context));
ptr += 4;
// TODO: use defines for custom dimension ids
int dimensionId;
ResourceKey<Level> dimension = level.dimension();
@ -90,4 +92,11 @@ public class LevelUniforms implements UniformProvider {
}
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)
public class OptionsMixin {
@Inject(method = "load()V", at = @At("RETURN"))
private void onLoad(CallbackInfo ci) {
private void flywheel$onLoad(CallbackInfo ci) {
Uniforms.onOptionsUpdate();
}
@Inject(method = "save", at = @At("HEAD"))
private void onSave(CallbackInfo ci) {
private void flywheel$onSave(CallbackInfo ci) {
Uniforms.onOptionsUpdate();
}
}

View File

@ -1,10 +1,7 @@
#include "flywheel:internal/indirect/buffers.glsl"
#include "flywheel:internal/indirect/model_descriptor.glsl"
#include "flywheel:internal/indirect/object.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:internal/uniforms/uniforms.glsl"
#include "flywheel:util/matrix.glsl"
layout(local_size_x = _FLW_SUBGROUP_SIZE) in;

View File

@ -1,9 +1,3 @@
#include "flywheel:internal/uniforms/frame.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"
// Cull shaders may not need all uniforms, but it is
// more consistent if we just provide all uniforms anyways.
#include "flywheel:internal/uniforms/uniforms.glsl"

View File

@ -22,13 +22,6 @@ layout(std140) uniform _FlwFrameUniforms {
mat4 flw_viewProjectionInverse;
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_cameraPosPrev;
vec4 _flw_cameraLook;