Add options uniform

This commit is contained in:
Kneelawk 2024-03-03 01:25:45 -08:00
parent ef2f2268cc
commit 56d03601cd
Failed to generate hash of commit
6 changed files with 113 additions and 6 deletions

View file

@ -0,0 +1,61 @@
package com.jozufozu.flywheel.backend.engine.uniform;
import org.lwjgl.system.MemoryUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.Options;
public class OptionsUniforms implements UniformProvider {
public static final int SIZE = 4 * 14;
@Override
public int byteSize() {
return SIZE;
}
@Override
public void write(long ptr) {
Options options = Minecraft.getInstance().options;
MemoryUtil.memPutFloat(ptr, options.gamma().get().floatValue());
ptr += 4;
MemoryUtil.memPutInt(ptr, options.fov().get());
ptr += 4;
MemoryUtil.memPutFloat(ptr, options.screenEffectScale().get().floatValue());
ptr += 4;
MemoryUtil.memPutFloat(ptr, options.glintSpeed().get().floatValue());
ptr += 4;
MemoryUtil.memPutFloat(ptr, options.glintStrength().get().floatValue());
ptr += 4;
MemoryUtil.memPutInt(ptr, options.biomeBlendRadius().get());
ptr += 4;
MemoryUtil.memPutInt(ptr, options.ambientOcclusion().get() ? 1 : 0);
ptr += 4;
MemoryUtil.memPutInt(ptr, options.bobView().get() ? 1 : 0);
ptr += 4;
MemoryUtil.memPutInt(ptr, options.highContrast().get() ? 1 : 0);
ptr += 4;
MemoryUtil.memPutFloat(ptr, options.textBackgroundOpacity().get().floatValue());
ptr += 4;
MemoryUtil.memPutInt(ptr, options.backgroundForChatOnly().get() ? 1 : 0);
ptr += 4;
MemoryUtil.memPutFloat(ptr, options.darknessEffectScale().get().floatValue());
ptr += 4;
MemoryUtil.memPutFloat(ptr, options.damageTiltStrength().get().floatValue());
ptr += 4;
MemoryUtil.memPutInt(ptr, options.hideLightningFlash().get() ? 1 : 0);
}
}

View file

@ -5,11 +5,14 @@ import com.jozufozu.flywheel.api.event.RenderContext;
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
import com.jozufozu.flywheel.config.DebugMode;
import org.jetbrains.annotations.Nullable;
public class Uniforms {
public static boolean frustumPaused = false;
public static boolean frustumCapture = false;
private static UniformBuffer<FrameUniforms> frame;
private static UniformBuffer<FogUniforms> fog;
private static @Nullable UniformBuffer<FrameUniforms> frame;
private static @Nullable UniformBuffer<FogUniforms> fog;
private static @Nullable UniformBuffer<OptionsUniforms> options;
public static UniformBuffer<FrameUniforms> frame() {
if (frame == null) {
@ -25,9 +28,17 @@ public class Uniforms {
return fog;
}
public static UniformBuffer<OptionsUniforms> options() {
if (options == null) {
options = new UniformBuffer<>(2, new OptionsUniforms());
}
return options;
}
public static void bindForDraw() {
bindFrame();
bindFog();
bindOptions();
}
public static void bindFrame() {
@ -42,6 +53,12 @@ public class Uniforms {
}
}
public static void bindOptions() {
if (options != null) {
options.bind();
}
}
public static void onFogUpdate() {
try (var restoreState = GlStateTracker.getRestoreState()) {
fog().update();
@ -52,6 +69,8 @@ public class Uniforms {
var ubo = frame();
ubo.provider.setContext(ctx);
ubo.update();
options();
}
public static void setDebugMode(DebugMode mode) {
@ -68,5 +87,10 @@ public class Uniforms {
fog.delete();
fog = null;
}
if (options != null) {
options.delete();
options = null;
}
}
}

View file

@ -1,6 +1,5 @@
#include "flywheel:internal/material.glsl"
#include "flywheel:internal/uniforms/frame.glsl"
#include "flywheel:internal/uniforms/fog.glsl"
#include "flywheel:internal/uniforms/uniforms.glsl"
in vec4 flw_vertexPos;
in vec4 flw_vertexColor;

View file

@ -1,6 +1,5 @@
#include "flywheel:internal/material.glsl"
#include "flywheel:internal/uniforms/frame.glsl"
#include "flywheel:internal/uniforms/fog.glsl"
#include "flywheel:internal/uniforms/uniforms.glsl"
// TODO: can we combine some of these internally to use fewer in/out slots?
out vec4 flw_vertexPos;

View file

@ -0,0 +1,19 @@
// options.glsl - Houses uniforms for many of the game's settings, focusing on video and accessibility settings.
layout(std140) uniform _FlwOptionsUniforms {
float flw_brightnessOption;
uint flw_fovOption;
float flw_distortionOption;
float flw_glintSpeedOption;
float flw_glintStrengthOption;
uint flw_biomeBlendOption;
uint flw_smoothLightingOption;
uint flw_viewBobbingOption;
uint flw_highContrastOption;
float flw_textBackgroundOpacityOption;
uint flw_textBackgroundForChatOnlyOption;
float flw_darknessPulsingOption;
float flw_damageTiltOption;
uint hideLightningFlashesOption;
};

View file

@ -0,0 +1,5 @@
// uniforms.glsl - Includes common uniforms.
#include "flywheel:internal/uniforms/frame.glsl"
#include "flywheel:internal/uniforms/fog.glsl"
#include "flywheel:internal/uniforms/options.glsl"