diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/IndirectPrograms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/IndirectPrograms.java index 524a1b583..ec94221ce 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/IndirectPrograms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/IndirectPrograms.java @@ -15,6 +15,7 @@ import dev.engine_room.flywheel.backend.compile.component.InstanceStructComponen import dev.engine_room.flywheel.backend.compile.component.SsboInstanceComponent; import dev.engine_room.flywheel.backend.compile.core.CompilationHarness; import dev.engine_room.flywheel.backend.compile.core.Compile; +import dev.engine_room.flywheel.backend.engine.uniform.FrameUniforms; import dev.engine_room.flywheel.backend.engine.uniform.Uniforms; import dev.engine_room.flywheel.backend.gl.GlCompat; import dev.engine_room.flywheel.backend.gl.shader.GlProgram; @@ -151,7 +152,7 @@ public class IndirectPrograms extends AtomicReferenceCounted { } public GlProgram getIndirectProgram(InstanceType instanceType, ContextShader contextShader, LightShader light, CutoutShader cutout, MaterialShaders shaders) { - return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, shaders)); + return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, shaders, FrameUniforms.debugOn())); } public GlProgram getCullingProgram(InstanceType instanceType) { diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/InstancingPrograms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/InstancingPrograms.java index ac9de915d..24724174d 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/InstancingPrograms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/InstancingPrograms.java @@ -11,6 +11,7 @@ import dev.engine_room.flywheel.api.material.CutoutShader; import dev.engine_room.flywheel.api.material.LightShader; import dev.engine_room.flywheel.api.material.MaterialShaders; import dev.engine_room.flywheel.backend.compile.core.CompilationHarness; +import dev.engine_room.flywheel.backend.engine.uniform.FrameUniforms; import dev.engine_room.flywheel.backend.gl.GlCompat; import dev.engine_room.flywheel.backend.gl.shader.GlProgram; import dev.engine_room.flywheel.backend.glsl.GlslVersion; @@ -74,7 +75,7 @@ public class InstancingPrograms extends AtomicReferenceCounted { } public GlProgram get(InstanceType instanceType, ContextShader contextShader, LightShader light, CutoutShader cutout, MaterialShaders materialShaders) { - return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, materialShaders)); + return pipeline.get(new PipelineProgramKey(instanceType, contextShader, light, cutout, materialShaders, FrameUniforms.debugOn())); } @Override diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineCompiler.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineCompiler.java index 10e443f16..486f7295c 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineCompiler.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineCompiler.java @@ -16,6 +16,7 @@ import dev.engine_room.flywheel.backend.gl.shader.GlProgram; import dev.engine_room.flywheel.backend.gl.shader.ShaderType; import dev.engine_room.flywheel.backend.glsl.ShaderSources; import dev.engine_room.flywheel.backend.glsl.SourceComponent; +import dev.engine_room.flywheel.lib.material.CutoutShaders; import dev.engine_room.flywheel.lib.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; @@ -39,12 +40,18 @@ public final class PipelineCompiler { .vertexSource()); var context = key.contextShader() .nameLowerCase(); - return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "/" + material + "_" + context; + var debug = key.debugEnabled() ? "_debug" : ""; + return "pipeline/" + pipeline.compilerMarker() + "/" + instance + "/" + material + "_" + context + debug; }) .requireExtensions(extensions) .onCompile((key, comp) -> key.contextShader() .onCompile(comp)) .onCompile((key, comp) -> lightSmoothness.onCompile(comp)) + .onCompile((key, comp) -> { + if (key.debugEnabled()) { + comp.define("_FLW_DEBUG"); + } + }) .withResource(API_IMPL_VERT) .withComponent(key -> new InstanceStructComponent(key.instanceType())) .withResource(key -> key.instanceType() @@ -69,13 +76,24 @@ public final class PipelineCompiler { var light = ResourceUtil.toDebugFileNameNoExtension(key.light() .source()); - return "pipeline/" + pipeline.compilerMarker() + "/frag/" + material + "/" + light + "_" + cutout + "_" + context; + var debug = key.debugEnabled() ? "_debug" : ""; + return "pipeline/" + pipeline.compilerMarker() + "/frag/" + material + "/" + light + "_" + cutout + "_" + context + debug; }) .requireExtensions(extensions) .enableExtension("GL_ARB_conservative_depth") .onCompile((key, comp) -> key.contextShader() .onCompile(comp)) .onCompile((key, comp) -> lightSmoothness.onCompile(comp)) + .onCompile((key, comp) -> { + if (key.debugEnabled()) { + comp.define("_FLW_DEBUG"); + } + }) + .onCompile((key, comp) -> { + if (key.cutout() != CutoutShaders.OFF) { + comp.define("_FLW_USE_DISCARD"); + } + }) .withResource(API_IMPL_FRAG) .withResource(key -> key.materialShaders() .fragmentSource()) diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineProgramKey.java b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineProgramKey.java index bd8d0a1a2..ac004c1c4 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineProgramKey.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/compile/PipelineProgramKey.java @@ -13,5 +13,5 @@ import dev.engine_room.flywheel.api.material.MaterialShaders; * @param light The light shader to use. */ public record PipelineProgramKey(InstanceType instanceType, ContextShader contextShader, LightShader light, - CutoutShader cutout, MaterialShaders materialShaders) { + CutoutShader cutout, MaterialShaders materialShaders, boolean debugEnabled) { } diff --git a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java index 3f7b8e871..82c0d97ed 100644 --- a/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java +++ b/common/src/backend/java/dev/engine_room/flywheel/backend/engine/uniform/FrameUniforms.java @@ -315,4 +315,8 @@ public final class FrameUniforms extends UniformWriter { MemoryUtil.memPutFloat(ptr + 88, nzW); MemoryUtil.memPutFloat(ptr + 92, pzW); } + + public static boolean debugOn() { + return debugMode != DebugMode.OFF.ordinal(); + } } diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag index aac8334b3..677e141ca 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.frag @@ -3,7 +3,7 @@ #include "flywheel:internal/colorizer.glsl" // optimize discard usage -#ifdef GL_ARB_conservative_depth +#if defined(GL_ARB_conservative_depth) && defined(_FLW_USE_DISCARD) layout (depth_greater) out float gl_FragDepth; #endif @@ -13,7 +13,9 @@ uniform sampler2D _flw_crumblingTex; in vec2 _flw_crumblingTexCoord; #endif +#ifdef _FLW_DEBUG flat in uint _flw_instanceID; +#endif out vec4 _flw_outputColor; @@ -49,9 +51,11 @@ void _flw_main() { vec4 color = flw_fragColor; + #ifdef _FLW_USE_DISCARD if (flw_discardPredicate(color)) { discard; } + #endif float diffuseFactor = _flw_diffuseFactor(); color.rgb *= diffuseFactor; @@ -67,6 +71,7 @@ void _flw_main() { color *= lightColor; } + #ifdef _FLW_DEBUG switch (_flw_debugMode) { case 1u: color = vec4(flw_vertexNormal * .5 + .5, 1.); @@ -87,6 +92,7 @@ void _flw_main() { color = vec4(vec3(diffuseFactor), 1.); break; } + #endif _flw_outputColor = flw_fogFilter(color); } diff --git a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert index 214ab12d2..8163c1118 100644 --- a/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert +++ b/common/src/backend/resources/assets/flywheel/flywheel/internal/common.vert @@ -71,7 +71,9 @@ mat4 _flw_modelMatrix; mat3 _flw_normalMatrix; #endif +#ifdef _FLW_DEBUG flat out uint _flw_instanceID; +#endif void _flw_main(in FlwInstance instance, in uint stableInstanceID) { _flw_layoutVertex(); @@ -93,5 +95,7 @@ void _flw_main(in FlwInstance instance, in uint stableInstanceID) { gl_Position = flw_viewProjection * flw_vertexPos; + #ifdef _FLW_DEBUG _flw_instanceID = stableInstanceID; + #endif }