diff --git a/src/main/java/net/vulkanmod/config/Config.java b/src/main/java/net/vulkanmod/config/Config.java index 2ba064652..b34409628 100644 --- a/src/main/java/net/vulkanmod/config/Config.java +++ b/src/main/java/net/vulkanmod/config/Config.java @@ -21,6 +21,9 @@ public class Config { public boolean uniqueOpaqueLayer = true; public boolean entityCulling = true; public int device = -1; + public boolean animations = true; + public boolean renderSky = true; + private static Path path; @@ -29,6 +32,8 @@ public class Config { .excludeFieldsWithModifiers(Modifier.PRIVATE) .create(); + public boolean renderFog = true; + public static Config load(Path path) { Config config; Config.path = path; diff --git a/src/main/java/net/vulkanmod/config/Options.java b/src/main/java/net/vulkanmod/config/Options.java index cad259c4a..71a189c89 100644 --- a/src/main/java/net/vulkanmod/config/Options.java +++ b/src/main/java/net/vulkanmod/config/Options.java @@ -154,6 +154,18 @@ public static Option[] getGraphicsOpts() { new RangeOption("Entity Distance", 50, 500, 25, value -> minecraftOptions.entityDistanceScaling().set(value * 0.01), () -> minecraftOptions.entityDistanceScaling().get().intValue() * 100), + new SwitchOption("Animations", + value -> config.animations = value, + () -> config.animations), + new SwitchOption("Render Sky", + value -> config.renderSky = value, + () -> config.renderSky), + new SwitchOption("RenderFog", + value -> { + config.renderFog = value; + Renderer.recomp=true; + }, + () -> config.renderFog), new CyclingOption<>("Mipmap Levels", new Integer[]{0, 1, 2, 3, 4}, value -> Component.nullToEmpty(value.toString()), diff --git a/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java b/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java index dc5b140dd..3b445e946 100644 --- a/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java +++ b/src/main/java/net/vulkanmod/mixin/render/vertex/VertexBufferM.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.VertexBuffer; import net.minecraft.client.renderer.ShaderInstance; +import net.vulkanmod.Initializer; import net.vulkanmod.render.VBO; import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Mixin; @@ -57,7 +58,8 @@ public void upload(BufferBuilder.RenderedBuffer buffer) { */ @Overwrite public void drawWithShader(Matrix4f viewMatrix, Matrix4f projectionMatrix, ShaderInstance shader) { - vbo.drawWithShader(viewMatrix, projectionMatrix, shader); + if(Initializer.CONFIG.renderSky) + vbo.drawWithShader(viewMatrix, projectionMatrix, shader); } /** diff --git a/src/main/java/net/vulkanmod/mixin/texture/MTextureManager.java b/src/main/java/net/vulkanmod/mixin/texture/MTextureManager.java index 76c7efc27..752fb5a35 100644 --- a/src/main/java/net/vulkanmod/mixin/texture/MTextureManager.java +++ b/src/main/java/net/vulkanmod/mixin/texture/MTextureManager.java @@ -5,6 +5,7 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.Tickable; import net.minecraft.resources.ResourceLocation; +import net.vulkanmod.Initializer; import net.vulkanmod.render.texture.SpriteUtil; import net.vulkanmod.vulkan.DeviceManager; import net.vulkanmod.vulkan.Renderer; @@ -29,7 +30,7 @@ public abstract class MTextureManager { */ @Overwrite public void tick() { - if(Renderer.skipRendering) + if(Renderer.skipRendering|| !Initializer.CONFIG.animations) return; //Debug D diff --git a/src/main/java/net/vulkanmod/vulkan/Renderer.java b/src/main/java/net/vulkanmod/vulkan/Renderer.java index 03130c3e8..cd51f7520 100644 --- a/src/main/java/net/vulkanmod/vulkan/Renderer.java +++ b/src/main/java/net/vulkanmod/vulkan/Renderer.java @@ -44,6 +44,8 @@ public class Renderer { private static boolean swapChainUpdate = false; public static boolean skipRendering = false; + public static boolean recomp; + public static void initRenderer() { INSTANCE = new Renderer(); INSTANCE.init(); @@ -57,7 +59,7 @@ public static void initRenderer() { public static int getCurrentImage() { return imageIndex; } - private final Set usedPipelines = new ObjectOpenHashSet<>(); + private final Set usedPipelines = new ObjectOpenHashSet<>(); private Drawer drawer; @@ -172,6 +174,14 @@ public void beginFrame() { p.pop(); p.push("Frame_fence"); + if(recomp) + { + waitIdle(); + usedPipelines.forEach(graphicsPipeline -> graphicsPipeline.updateSpecConstant(SPIRVUtils.SpecConstant.USE_FOG)); + recomp=false; + } + + if(swapChainUpdate) { recreateSwapChain(); swapChainUpdate = false; @@ -363,7 +373,7 @@ public void resetBuffers() { Vulkan.getStagingBuffer().reset(); } - public void addUsedPipeline(Pipeline pipeline) { + public void addUsedPipeline(GraphicsPipeline pipeline) { usedPipelines.add(pipeline); } diff --git a/src/main/java/net/vulkanmod/vulkan/shader/GraphicsPipeline.java b/src/main/java/net/vulkanmod/vulkan/shader/GraphicsPipeline.java index 334005d6c..68f4b477e 100644 --- a/src/main/java/net/vulkanmod/vulkan/shader/GraphicsPipeline.java +++ b/src/main/java/net/vulkanmod/vulkan/shader/GraphicsPipeline.java @@ -12,6 +12,7 @@ import java.nio.ByteBuffer; import java.nio.LongBuffer; +import java.util.EnumSet; import java.util.HashMap; import java.util.Map; @@ -26,9 +27,11 @@ public class GraphicsPipeline extends Pipeline { private final Map graphicsPipelines = new HashMap<>(); private final VertexFormat vertexFormat; + private final EnumSet specConstants; private long vertShaderModule = 0; private long fragShaderModule = 0; + private PipelineState state; GraphicsPipeline(Builder builder) { super(builder.shaderPath); @@ -37,14 +40,17 @@ public class GraphicsPipeline extends Pipeline { this.imageDescriptors = builder.imageDescriptors; this.pushConstants = builder.pushConstants; this.vertexFormat = builder.vertexFormat; + this.specConstants = builder.specConstants; createDescriptorSetLayout(); createPipelineLayout(); createShaderModules(builder.vertShaderSPIRV, builder.fragShaderSPIRV); - if(builder.renderPass != null) - graphicsPipelines.computeIfAbsent(new PipelineState(DEFAULT_BLEND_STATE, DEFAULT_DEPTH_STATE, DEFAULT_LOGICOP_STATE, DEFAULT_COLORMASK, builder.renderPass), + if(builder.renderPass != null) { + this.state = new PipelineState(DEFAULT_BLEND_STATE, DEFAULT_DEPTH_STATE, DEFAULT_LOGICOP_STATE, DEFAULT_COLORMASK, builder.renderPass); + graphicsPipelines.computeIfAbsent(state, this::createGraphicsPipeline); + } createDescriptorSets(Renderer.getFramesNum()); @@ -56,19 +62,30 @@ public long getHandle(PipelineState state) { } private long createGraphicsPipeline(PipelineState state) { - + this.state=state; try(MemoryStack stack = stackPush()) { ByteBuffer entryPoint = stack.UTF8("main"); VkPipelineShaderStageCreateInfo.Buffer shaderStages = VkPipelineShaderStageCreateInfo.calloc(2, stack); + + VkSpecializationMapEntry.Buffer specEntrySet = VkSpecializationMapEntry.malloc(specConstants.size(), stack); + + + boolean equals = !this.specConstants.isEmpty(); + VkSpecializationInfo specInfo = equals ? VkSpecializationInfo.malloc(stack) + .pMapEntries(specEntrySet) + .pData(enumSpecConstants(stack, specEntrySet)) : null; + + VkPipelineShaderStageCreateInfo vertShaderStageInfo = shaderStages.get(0); vertShaderStageInfo.sType(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO); vertShaderStageInfo.stage(VK_SHADER_STAGE_VERTEX_BIT); vertShaderStageInfo.module(vertShaderModule); vertShaderStageInfo.pName(entryPoint); + vertShaderStageInfo.pSpecializationInfo(specInfo); VkPipelineShaderStageCreateInfo fragShaderStageInfo = shaderStages.get(1); @@ -76,6 +93,7 @@ private long createGraphicsPipeline(PipelineState state) { fragShaderStageInfo.stage(VK_SHADER_STAGE_FRAGMENT_BIT); fragShaderStageInfo.module(fragShaderModule); fragShaderStageInfo.pName(entryPoint); + fragShaderStageInfo.pSpecializationInfo(specInfo); // ===> VERTEX STAGE <=== @@ -204,6 +222,30 @@ private long createGraphicsPipeline(PipelineState state) { } } + + private ByteBuffer enumSpecConstants(MemoryStack stack, VkSpecializationMapEntry.Buffer specEntrySet) { + int i = 0; + int x = 0; + ByteBuffer byteBuffer = stack.malloc(specConstants.size()*Integer.BYTES); + + for(var specDef : specConstants) + { + specEntrySet.get(i) + .constantID(specDef.ordinal()) + .offset(x) + .size(4); + + byteBuffer.putInt(i, specDef.getValue()); + i++; x+=4; + } + return byteBuffer; + } + + //Vulkan spec mandates that VkBool32 must always be aligned to uint32_t, which is 4 Bytes + private static ByteBuffer alignedVkBool32(MemoryStack stack, int i) { + return stack.malloc(Integer.BYTES).putInt(0, i); //Malloc as Int is always Unaligned, so asIntBuffer doesn't help here afaik + } + private void createShaderModules(SPIRVUtils.SPIRV vertSpirv, SPIRVUtils.SPIRV fragSpirv) { this.vertShaderModule = createShaderModule(vertSpirv.bytecode()); this.fragShaderModule = createShaderModule(fragSpirv.bytecode()); @@ -338,6 +380,28 @@ else if (type == VertexFormatElement.Type.INT && elementCount == 1) { return attributeDescriptions.rewind(); } + // SpecConstants can be set to be unique per Pipeline + // but that would involve adding boilerplate to PipelineState + // So to simplify the code, SpecConstants are limited to "Static Global State" rn + public void updateSpecConstant(SPIRVUtils.SpecConstant specConstant) + { + + if(this.specConstants.contains(specConstant)) + { + if(graphicsPipelines.size()>1) + { + graphicsPipelines.values().forEach(pipeline -> vkDestroyPipeline(DeviceManager.device, pipeline, null)); + graphicsPipelines.clear(); + } + this.graphicsPipelines.put(this.state, this.createGraphicsPipeline(this.state)); + } +// PIPELINES.remove(this); +// Renderer.getInstance().removeUsedPipeline(this); +// this.graphicsPipelines.remove(this.state); +// PIPELINES.add(this); +// Renderer.getInstance().addUsedPipeline(this); + } + public void cleanUp() { vkDestroyShaderModule(DeviceManager.device, vertShaderModule, null); vkDestroyShaderModule(DeviceManager.device, fragShaderModule, null); diff --git a/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java b/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java index 7bca8b45e..4b3890ffd 100644 --- a/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java +++ b/src/main/java/net/vulkanmod/vulkan/shader/Pipeline.java @@ -442,6 +442,8 @@ private void cleanUp() { public static class Builder { + final EnumSet specConstants = EnumSet.noneOf(SpecConstant.class); + public static GraphicsPipeline createGraphicsPipeline(VertexFormat format, String path) { Pipeline.Builder pipelineBuilder = new Pipeline.Builder(format, path); pipelineBuilder.parseBindingsJSON(); @@ -516,6 +518,7 @@ public void parseBindingsJSON() { JsonArray jsonManualUbos = GsonHelper.getAsJsonArray(jsonObject, "ManualUBOs", null); JsonArray jsonSamplers = GsonHelper.getAsJsonArray(jsonObject, "samplers", null); JsonArray jsonPushConstants = GsonHelper.getAsJsonArray(jsonObject, "PushConstants", null); + JsonArray jsonSpecConstants = GsonHelper.getAsJsonArray(jsonObject, "SpecConstants", null); if (jsonUbos != null) { for (JsonElement jsonelement : jsonUbos) { @@ -536,6 +539,24 @@ public void parseBindingsJSON() { if(jsonPushConstants != null) { this.parsePushConstantNode(jsonPushConstants); } + if(jsonSpecConstants != null) { + this.parseSpecConstantNode(jsonSpecConstants); + } + } + + private void parseSpecConstantNode(JsonArray jsonSpecConstants) { +// AlignedStruct.Builder builder = new AlignedStruct.Builder(); + + for(JsonElement jsonelement : jsonSpecConstants) { + JsonObject jsonobject2 = GsonHelper.convertToJsonObject(jsonelement, "SC"); + + String name = GsonHelper.getAsString(jsonobject2, "name"); +// String type2 = GsonHelper.getAsString(jsonobject2, "type"); + + + this.specConstants.add(SpecConstant.getNamed(name)); + } + } private void parseUboNode(JsonElement jsonelement) { diff --git a/src/main/java/net/vulkanmod/vulkan/shader/SPIRVUtils.java b/src/main/java/net/vulkanmod/vulkan/shader/SPIRVUtils.java index f1d8001e6..20be710bf 100644 --- a/src/main/java/net/vulkanmod/vulkan/shader/SPIRVUtils.java +++ b/src/main/java/net/vulkanmod/vulkan/shader/SPIRVUtils.java @@ -1,6 +1,8 @@ package net.vulkanmod.vulkan.shader; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.vulkanmod.Initializer; +import net.vulkanmod.vulkan.VRenderSystem; import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.NativeResource; @@ -118,6 +120,37 @@ private static SPIRV readFromStream(InputStream inputStream) { throw new RuntimeException("unable to read inputStream"); } + + + public enum SpecConstant + { + USE_FOG(Boolean.class), + ALPHA_CUTOUT(Float.class); + + SpecConstant(Object floatClass) { + + } + + public static SpecConstant getNamed(String name) { + return switch (name) + { + case "USE_FOG" -> USE_FOG; + case "ALPHA_CUTOUT" -> ALPHA_CUTOUT; + default -> null; + }; + } + + //Vulkan spec mandates that VkBool32 must always be aligned to uint32_t, which is 4 Bytes + public int getValue() + { + return switch (this){ + case USE_FOG -> Initializer.CONFIG.renderFog ? 1 : 0; + case ALPHA_CUTOUT -> Float.floatToRawIntBits(VRenderSystem.alphaCutout); + }; + } + } + + public enum ShaderKind { VERTEX_SHADER(shaderc_glsl_vertex_shader), GEOMETRY_SHADER(shaderc_glsl_geometry_shader), diff --git a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.fsh b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.fsh index 81a508fd6..7942f4ddd 100644 --- a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.fsh +++ b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.fsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; #include "light.glsl" layout(binding = 2) uniform sampler2D Sampler0; @@ -24,5 +24,5 @@ void main() { if (color.a < AlphaCutout) { discard; } - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); + fragColor = USE_FOG ? linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor) : color; //Optimised out by Driver } diff --git a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.vsh b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.vsh index a08f80d2f..9175b3170 100644 --- a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.vsh +++ b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_direct/terrain_direct.vsh @@ -1,5 +1,5 @@ #version 460 - +layout (constant_id = 0) const bool USE_FOG = true; #include "light.glsl" layout(binding = 0) uniform UniformBufferObject { @@ -31,8 +31,7 @@ const float POSITION_INV = 1.0 / 1900.0; void main() { vec3 pos = (Position * POSITION_INV); gl_Position = MVP * vec4(pos + ChunkOffset, 1.0); - - vertexDistance = length((ModelViewMat * vec4(pos + ChunkOffset, 1.0)).xyz); + vertexDistance = USE_FOG ? length((ModelViewMat * vec4(pos + ChunkOffset, 1.0)).xyz) : 0.0f; //Optimised out by Driver vertexColor = Color * sample_lightmap(Sampler2, UV2); texCoord0 = UV0 * UV_INV; // normal = MVP * vec4(Normal, 0.0); diff --git a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.fsh b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.fsh index 6880c1e94..d3f592994 100644 --- a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.fsh +++ b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.fsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; #include "light.glsl" layout(binding = 3) uniform sampler2D Sampler0; @@ -24,5 +24,5 @@ void main() { if (color.a < AlphaCutout) { discard; } - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); + fragColor = USE_FOG ? linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor) : color; //Optimised out by Driver } \ No newline at end of file diff --git a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.json b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.json index 9590454c5..57452b07b 100644 --- a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.json +++ b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.json @@ -21,7 +21,6 @@ { "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, { "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, { "name": "ChunkOffset", "type": "float", "count": 3, "values": [ 0.0, 0.0, 0.0 ] }, - { "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }, { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] }, { "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] } @@ -41,5 +40,8 @@ ], "ManualUBOs" : [ { "type": "vertex", "binding": 2, "size": 2048 } + ], + "SpecConstants": [ + { "name": "USE_FOG", "type": "bool" } ] } diff --git a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.vsh b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.vsh index b6bfcd991..2542610f8 100644 --- a/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.vsh +++ b/src/main/resources/assets/vulkanmod/shaders/basic/terrain_indirect/terrain_indirect.vsh @@ -1,6 +1,6 @@ #version 460 - -#define MAX_OFFSET_COUNT 512 +layout (constant_id = 0) const bool USE_FOG = true; +layout (constant_id = 2) const uint MAX_OFFSET_COUNT = 512; #include "light.glsl" @@ -35,7 +35,7 @@ void main() { vec3 pos = (Position * POSITION_INV); gl_Position = MVP * vec4(pos + ChunkOffset[gl_DrawID], 1.0); - vertexDistance = length((ModelViewMat * vec4(pos + ChunkOffset[gl_DrawID], 1.0)).xyz); + vertexDistance = USE_FOG ? length((ModelViewMat * vec4(pos + ChunkOffset[gl_DrawID], 1.0)).xyz) : 0.0f; //Optimised out by Driver vertexColor = Color * sample_lightmap(Sampler2, UV2); texCoord0 = UV0 * UV_INV; // normal = MVP * vec4(Normal, 0.0); diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.fsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.fsh index 93c401efe..123604a88 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.fsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.fsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; vec4 linear_fog(vec4 inColor, float vertexDistance, float fogStart, float fogEnd, vec4 fogColor) { if (vertexDistance <= fogStart) { return inColor; @@ -32,7 +32,7 @@ void main() { vec4 color = texture(Sampler0, texCoord0); color *= vertexColor * ColorModulator; float fragmentDistance = -ProjMat[3].z / ((gl_FragCoord.z) * -2.0 + 1.0 - ProjMat[2].z); - fragColor = linear_fog(color, fragmentDistance, FogStart, FogEnd, FogColor); + fragColor = USE_FOG ? linear_fog(color, fragmentDistance, FogStart, FogEnd, FogColor) : color; } /* diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.json b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.json index b2e5516d3..dd6818793 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.json +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_beacon_beam/rendertype_beacon_beam.json @@ -33,5 +33,8 @@ { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] } ] } + ], + "SpecConstants": [ + { "name": "USE_FOG", "type": "bool" } ] } diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.fsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.fsh index b3581c386..656f1e41a 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.fsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.fsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; vec4 linear_fog(vec4 inColor, float vertexDistance, float fogStart, float fogEnd, vec4 fogColor) { if (vertexDistance <= fogStart) { return inColor; @@ -35,5 +35,5 @@ void main() { color *= vertexColor * ColorModulator; color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); color *= lightMapColor; - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); -} + fragColor = USE_FOG ? linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor) : color; +} \ No newline at end of file diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.json b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.json index e7c4f0575..c72355a16 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.json +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.json @@ -42,5 +42,8 @@ { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] } ] } + ], + "SpecConstants": [ + { "name": "USE_FOG", "type": "bool" } ] } diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.vsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.vsh index a850d58c7..9430fbd99 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.vsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_cutout_no_cull/rendertype_entity_cutout_no_cull.vsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; #include "light.glsl" layout(location = 0) in vec3 Position; @@ -29,7 +29,7 @@ layout(location = 5) out float vertexDistance; void main() { gl_Position = MVP * vec4(Position, 1.0); - vertexDistance = length((ModelViewMat * vec4(Position, 1.0)).xyz); + vertexDistance = USE_FOG ? length((ModelViewMat * vec4(Position, 1.0)).xyz) : 0.0f; vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, Normal, Color); lightMapColor = texelFetch(Sampler2, UV2 / 16, 0); overlayColor = texelFetch(Sampler1, UV1, 0); diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.fsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.fsh index 03165826e..7591cbc8a 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.fsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.fsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; vec4 linear_fog(vec4 inColor, float vertexDistance, float fogStart, float fogEnd, vec4 fogColor) { if (vertexDistance <= fogStart) { return inColor; @@ -31,7 +31,7 @@ void main() { vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator; color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); color *= lightMapColor; - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); + fragColor = USE_FOG ? linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor) : color; } /* diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.json b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.json index ec5ae95bf..467c0aa20 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.json +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.json @@ -42,5 +42,8 @@ { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] } ] } + ], + "SpecConstants": [ + { "name": "USE_FOG", "type": "bool" } ] } diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.vsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.vsh index 13c8a8756..814a1a6ce 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.vsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_solid/rendertype_entity_solid.vsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; #include "light.glsl" layout(location = 0) in vec3 Position; @@ -29,7 +29,7 @@ layout(location = 5) out float vertexDistance; void main() { gl_Position = MVP * vec4(Position, 1.0); - vertexDistance = length((ModelViewMat * vec4(Position, 1.0)).xyz); + vertexDistance = USE_FOG ? length((ModelViewMat * vec4(Position, 1.0)).xyz) : 0.0f; vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, Normal, Color); lightMapColor = texelFetch(Sampler2, UV2 / 16, 0); overlayColor = texelFetch(Sampler1, UV1, 0); diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.fsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.fsh index 35f9567ff..2696d3c6d 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.fsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.fsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; vec4 linear_fog(vec4 inColor, float vertexDistance, float fogStart, float fogEnd, vec4 fogColor) { if (vertexDistance <= fogStart) { return inColor; @@ -35,7 +35,7 @@ void main() { color *= vertexColor * ColorModulator; color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); color *= lightMapColor; - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); + fragColor = USE_FOG ? linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor) : color; } /* diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.json b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.json index f509083e9..4bed78f13 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.json +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.json @@ -42,5 +42,8 @@ { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] } ] } + ], + "SpecConstants": [ + { "name": "USE_FOG", "type": "bool" } ] } diff --git a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.vsh b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.vsh index 9c44100f6..ed19e4526 100644 --- a/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.vsh +++ b/src/main/resources/assets/vulkanmod/shaders/minecraft/core/rendertype_entity_translucent/rendertype_entity_translucent.vsh @@ -1,5 +1,5 @@ #version 450 - +layout (constant_id = 0) const bool USE_FOG = true; #include "light.glsl" layout(location = 0) in vec3 Position; @@ -29,7 +29,7 @@ layout(location = 5) out float vertexDistance; void main() { gl_Position = MVP * vec4(Position, 1.0); - vertexDistance = length((ModelViewMat * vec4(Position, 1.0)).xyz); + vertexDistance = USE_FOG ? length((ModelViewMat * vec4(Position, 1.0)).xyz) : 0.0f; vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, Normal, Color); lightMapColor = texelFetch(Sampler2, UV2 / 16, 0); overlayColor = texelFetch(Sampler1, UV1, 0);