From 5b1ca516e1879469bf5886b4ac0922824d35c37d Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 23 Apr 2024 11:30:31 +0200 Subject: [PATCH 1/4] shader: correctly apply defaults This (should) fix shader building on intel gpus with mesa drivers. `foutColor` was optimized out because the initial values appear to be always 0. Thus it was not building, because the uTintColor uniform was not found (and maybe it otherwise would have appeared black) --- .../assets/minosoft/rendering/shader/sky/planet/planet.fsh | 3 ++- .../minosoft/rendering/shader/sky/skybox/texture/texture.fsh | 3 ++- .../assets/minosoft/rendering/shader/world/border/border.fsh | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.fsh b/src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.fsh index b241b2c5e..34786ac5a 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.fsh @@ -23,7 +23,8 @@ uniform vec4 uTintColor; void main() { - applyTexel(); + applyDefaults(); foutColor *= uTintColor; discard_alpha(); + applyTexel(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/texture/texture.fsh b/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/texture/texture.fsh index 6b4be7f54..8d9e8b54c 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/texture/texture.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/texture/texture.fsh @@ -23,6 +23,7 @@ uniform vec4 uTintColor; #include "minosoft:animation" void main() { + applyDefaults(); + foutColor.rgb *= uTintColor.rgb; applyTexel(); - foutColor *= uTintColor; } diff --git a/src/main/resources/assets/minosoft/rendering/shader/world/border/border.fsh b/src/main/resources/assets/minosoft/rendering/shader/world/border/border.fsh index a889423eb..7be92adaa 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/world/border/border.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/world/border/border.fsh @@ -24,6 +24,7 @@ uniform vec4 uTintColor; #include "minosoft:animation" void main() { - applyTexel(); + applyDefaults(); foutColor *= uTintColor; + applyTexel(); } From e7b57e4da3ebc2e94418eb2490badd8ab4b3bb1b Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 23 Apr 2024 11:35:16 +0200 Subject: [PATCH 2/4] rendering: allow ignoring uniform errors This allows easier debugging on such errors for non developers. --- .../profile/profiles/rendering/advanced/AdvancedC.kt | 8 +++++++- .../gui/rendering/system/opengl/OpenGLNativeShader.kt | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/advanced/AdvancedC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/advanced/AdvancedC.kt index d14686dd0..bf1e1bd33 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/advanced/AdvancedC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/rendering/advanced/AdvancedC.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -37,4 +37,10 @@ class AdvancedC(profile: RenderingProfile) { * Requires rendering restart to apply */ var preferQuads by BooleanDelegate(profile, false) + + /** + * This option makes shader uniform errors just warnings and does not crash it. This only helps if there is a driver bug or the included shader does not follow + * the specs strictly. Not recommended to enable. + */ + var allowUniformErrors by BooleanDelegate(profile, false) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt index 61fa58987..5ac40c442 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt @@ -28,6 +28,9 @@ import de.bixilon.minosoft.gui.rendering.exceptions.ShaderLoadingException import de.bixilon.minosoft.gui.rendering.system.base.buffer.uniform.UniformBuffer import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader import de.bixilon.minosoft.gui.rendering.system.base.shader.code.glsl.GLSLShaderCode +import de.bixilon.minosoft.util.logging.Log +import de.bixilon.minosoft.util.logging.LogLevels +import de.bixilon.minosoft.util.logging.LogMessageType import it.unimi.dsi.fastutil.ints.IntArrayList import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap import org.lwjgl.opengl.GL11.GL_FALSE @@ -129,7 +132,11 @@ class OpenGLNativeShader( val location = uniformLocations.getOrPut(uniformName) { val location = glGetUniformLocation(handler, uniformName) if (location < 0) { - throw IllegalArgumentException("No uniform named $uniformName in $this, maybe you use something that has been optimized out? Check your shader code!") + val error = "No uniform named $uniformName in $this, maybe you use something that has been optimized out? Check your shader code!" + if (!context.profile.advanced.allowUniformErrors) { + throw IllegalArgumentException(error) + } + Log.log(LogMessageType.RENDERING, LogLevels.WARN, error) } return@getOrPut location } From ff92b1f0db5a500464db686f38d99249734a7ebf Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 23 Apr 2024 17:37:48 +0200 Subject: [PATCH 3/4] fog: fix null pointer if dimension has no fog Minosoft would instantly crash when you go into the end, because the end has no fog but it sill tries to get the fog options. --- .../de/bixilon/minosoft/gui/rendering/camera/fog/FogManager.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/fog/FogManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/fog/FogManager.kt index 1c2d89de6..534fc3321 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/fog/FogManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/fog/FogManager.kt @@ -68,7 +68,8 @@ class FogManager( if (state.enabled != enabled) { state.revision++ } - if (!state.enabled) return + state.enabled = enabled + if (!enabled) return val options = getOptions(effects!!) if (this.options == options) { From a433215260b3e07a2f6c47219cb1fa5f16a16c43 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Tue, 23 Apr 2024 17:46:30 +0200 Subject: [PATCH 4/4] fix particle fog `finFragmentPosition` was not set. This caused the fog to not appear. Some gpu drivers (e.g. intel) also heavily optimized the fog code and completely removed the uniform `uCameraPosition`, thus minosoft crashed when setting the value on those gpus. --- .../minosoft/gui/rendering/shader/uniform/ShaderUniform.kt | 3 +-- .../assets/minosoft/rendering/shader/particle/particle.gsh | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/shader/uniform/ShaderUniform.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/shader/uniform/ShaderUniform.kt index c9e288b8d..eb5ceb55f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/shader/uniform/ShaderUniform.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/shader/uniform/ShaderUniform.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2024 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -54,5 +54,4 @@ class ShaderUniform( upload() } } - } diff --git a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.gsh b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.gsh index f9dd5cfe8..f584e536b 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.gsh +++ b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.gsh @@ -21,6 +21,7 @@ uniform vec3 uCameraRight; uniform vec3 uCameraUp; out vec4 finTintColor; +out vec3 finFragmentPosition; in Vertex { @@ -41,8 +42,9 @@ in Vertex void emit(vec3 offset, vec2 uv) { vec3 pointPosition = gl_in[0].gl_Position.xyz; + finFragmentPosition = pointPosition + (offset * ginVertex[0].scale); - gl_Position = uViewProjectionMatrix * vec4(pointPosition + offset * ginVertex[0].scale, 1.0); + gl_Position = uViewProjectionMatrix * vec4(finFragmentPosition, 1.0f); finAnimationUV = uv; EmitVertex();