Cool and normal

- Reimplement normal debug mode
- Add debug mode for instance ID and light coordinates
- Pass an id into _flw_main
- Allow specifying how the debug color is applied, not sure if I want
  to keep it though
- Do not store the debug mode in config
This commit is contained in:
Jozufozu 2024-02-20 15:19:51 -06:00
parent 83119040d2
commit 0e00c7019d
10 changed files with 109 additions and 20 deletions

View file

@ -15,8 +15,10 @@ import net.minecraft.world.phys.Vec3;
public class FrameUniforms implements UniformProvider {
public static final int SIZE = 304;
public int debugMode;
public int debugOverlay;
@Nullable
@Nullable
private RenderContext context;
private final Matrix4f viewProjection = new Matrix4f();
@ -70,7 +72,10 @@ public class FrameUniforms implements UniformProvider {
MemoryUtil.memPutInt(ptr, getConstantAmbientLightFlag(context));
ptr += 4;
writeTime(ptr);
ptr = writeTime(ptr);
MemoryUtil.memPutInt(ptr, debugMode);
MemoryUtil.memPutInt(ptr + 4, debugOverlay);
}
private long writeMatrices(long ptr) {

View file

@ -3,6 +3,8 @@ package com.jozufozu.flywheel.backend.engine.uniform;
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
import com.jozufozu.flywheel.api.event.RenderContext;
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
import com.jozufozu.flywheel.config.DebugMode;
import com.jozufozu.flywheel.config.DebugOverlay;
public class Uniforms {
public static boolean frustumPaused = false;
@ -53,6 +55,11 @@ public class Uniforms {
ubo.update();
}
public static void setDebugMode(DebugMode mode, DebugOverlay visual) {
frame().provider.debugMode = mode.ordinal();
frame().provider.debugOverlay = visual.ordinal();
}
public static void onReloadLevelRenderer(ReloadLevelRendererEvent event) {
if (frame != null) {
frame.delete();

View file

@ -0,0 +1,8 @@
package com.jozufozu.flywheel.config;
public enum DebugMode {
NONE,
NORMALS,
INSTANCE_ID,
LIGHT,
}

View file

@ -0,0 +1,7 @@
package com.jozufozu.flywheel.config;
public enum DebugOverlay {
NONE,
MUL,
OVERRIDE,
}

View file

@ -23,6 +23,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
import net.minecraftforge.server.command.EnumArgument;
public class FlwCommands {
public static void registerClientCommands(RegisterClientCommandsEvent event) {
@ -101,18 +102,32 @@ public class FlwCommands {
}
));
// TODO
command.then(Commands.literal("debugNormals"))
.executes(context -> {
LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return 0;
command.then(Commands.literal("debug")
.then(Commands.argument("mode", EnumArgument.enumArgument(DebugMode.class))
.executes(context -> {
LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return 0;
player.displayClientMessage(Component.literal("This command is not yet implemented."), false);
DebugMode mode = context.getArgument("mode", DebugMode.class);
return Command.SINGLE_SUCCESS;
});
Uniforms.setDebugMode(mode, DebugOverlay.OVERRIDE);
command.then(Commands.literal("debugCrumbling")
return Command.SINGLE_SUCCESS;
})
.then(Commands.argument("overlay", EnumArgument.enumArgument(DebugOverlay.class))
.executes(context -> {
LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return 0;
DebugMode mode = context.getArgument("mode", DebugMode.class);
DebugOverlay visual = context.getArgument("overlay", DebugOverlay.class);
Uniforms.setDebugMode(mode, visual);
return Command.SINGLE_SUCCESS;
}))));
command.then(Commands.literal("crumbling")
.then(Commands.argument("pos", BlockPosArgument.blockPos())
.then(Commands.argument("stage", IntegerArgumentType.integer(0, 9))
.executes(context -> {
@ -132,12 +147,7 @@ public class FlwCommands {
return Command.SINGLE_SUCCESS;
}))));
command.then(Commands.literal("debugFrustum")
.then(Commands.literal("pause")
.executes(context -> {
Uniforms.frustumPaused = true;
return 1;
}))
command.then(Commands.literal("frustum")
.then(Commands.literal("unpause")
.executes(context -> {
Uniforms.frustumPaused = false;

View file

@ -12,6 +12,8 @@ uniform sampler2D _flw_lightTex;
out vec4 _flw_outputColor;
in vec4 _flw_debugColor;
void _flw_main() {
flw_sampleColor = texture(_flw_diffuseTex, flw_vertexTexCoord);
flw_fragColor = flw_vertexColor * flw_sampleColor;
@ -48,5 +50,14 @@ void _flw_main() {
discard;
}
switch (_flw_debugOverlay) {
case 1u:
color *= _flw_debugColor;
break;
case 2u:
color = _flw_debugColor;
break;
}
_flw_outputColor = flw_fogFilter(color);
}

View file

@ -1,6 +1,29 @@
#include "flywheel:internal/fog_distance.glsl"
void _flw_main(in FlwInstance instance) {
// https://stackoverflow.com/a/17479300
uint _flw_hash(in uint x) {
x += (x << 10u);
x ^= (x >> 6u);
x += (x << 3u);
x ^= (x >> 11u);
x += (x << 15u);
return x;
}
vec4 _flw_id2Color(in uint id) {
uint x = _flw_hash(id);
return vec4(
float(x & 0xFFu) / 255.0,
float((x >> 8u) & 0xFFu) / 255.0,
float((x >> 16u) & 0xFFu) / 255.0,
1.
);
}
out vec4 _flw_debugColor;
void _flw_main(in FlwInstance instance, in uint stableInstanceID) {
_flw_layoutVertex();
flw_beginVertex();
flw_instanceVertex(instance);
@ -12,4 +35,19 @@ void _flw_main(in FlwInstance instance) {
flw_distance = fogDistance(flw_vertexPos.xyz, flw_cameraPos, flw_fogShape);
gl_Position = flw_viewProjection * flw_vertexPos;
switch (_flw_debugMode) {
case 0u:
_flw_debugColor = vec4(1.);
break;
case 1u:
_flw_debugColor = vec4(flw_vertexNormal * .5 + .5, 1.);
break;
case 2u:
_flw_debugColor = _flw_id2Color(stableInstanceID);
break;
case 3u:
_flw_debugColor = vec4(vec2((flw_vertexLight * 15.0 + 0.5) / 16.), 0., 1.);
break;
}
}

View file

@ -32,5 +32,5 @@ void main() {
uint objectIndex = objectIndices[gl_BaseInstance + gl_InstanceID];
FlwInstance instance = _flw_unpackInstance(objects[objectIndex].instance);
_flw_main(instance);
_flw_main(instance, objectIndex);
}

View file

@ -9,5 +9,5 @@ void main() {
FlwInstance instance = _flw_unpackInstance();
_flw_main(instance);
_flw_main(instance, uint(gl_InstanceID));
}

View file

@ -29,6 +29,9 @@ layout(std140) uniform _FlwFrameUniforms {
float flw_renderTicks;
float flw_renderSeconds;
uint _flw_debugMode;
uint _flw_debugOverlay;
};
#define flw_cameraPos _flw_cameraPos.xyz