Skip to content

Commit 5ecca7c

Browse files
committed
shaders: apply tint before texel, particle fog
Applying the tint before the texel, fixes a lot of fog issues that are caused by lighting
1 parent a3f0907 commit 5ecca7c

File tree

17 files changed

+39
-19
lines changed

17 files changed

+39
-19
lines changed

src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/text/BillboardTextShader.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ class BillboardTextShader(
3333
override var cameraPosition: Vec3 by cameraPosition()
3434
override var fog: FogManager by fog()
3535
var matrix: Mat4 by uniform("uMatrix", Mat4())
36+
3637
override var tint by uniform("uTintColor", ChatColors.WHITE) { shader, name, value -> shader.setUInt(name, value.rgb) }
3738
}

src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleShader.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Minosoft
3-
* Copyright (C) 2020-2023 Moritz Zwerger
3+
* Copyright (C) 2020-2024 Moritz Zwerger
44
*
55
* 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.
66
*
@@ -15,22 +15,23 @@ package de.bixilon.minosoft.gui.rendering.particle
1515

1616
import de.bixilon.kotlinglm.mat4x4.Mat4
1717
import de.bixilon.kotlinglm.vec3.Vec3
18+
import de.bixilon.minosoft.gui.rendering.camera.fog.FogManager
1819
import de.bixilon.minosoft.gui.rendering.light.LightmapBuffer
1920
import de.bixilon.minosoft.gui.rendering.shader.Shader
20-
import de.bixilon.minosoft.gui.rendering.shader.types.AnimatedShader
21-
import de.bixilon.minosoft.gui.rendering.shader.types.LightShader
22-
import de.bixilon.minosoft.gui.rendering.shader.types.TextureShader
23-
import de.bixilon.minosoft.gui.rendering.shader.types.ViewProjectionShader
21+
import de.bixilon.minosoft.gui.rendering.shader.types.*
2422
import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader
2523
import de.bixilon.minosoft.gui.rendering.system.base.shader.ShaderUniforms
2624
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
2725

2826
class ParticleShader(
2927
override val native: NativeShader,
30-
) : Shader(), TextureShader, AnimatedShader, LightShader, ViewProjectionShader {
28+
) : Shader(), TextureShader, AnimatedShader, LightShader, ViewProjectionShader, FogShader {
3129
override var textures: TextureManager by textureManager()
3230
override val lightmap: LightmapBuffer by lightmap()
3331
override var viewProjectionMatrix: Mat4 by viewProjectionMatrix()
32+
override var fog: FogManager by fog()
33+
override var cameraPosition: Vec3 by cameraPosition()
34+
3435
var cameraRight by uniform(ShaderUniforms.CAMERA_RIGHT, Vec3(), NativeShader::setVec3)
3536
var cameraUp by uniform(ShaderUniforms.CAMERA_UP, Vec3(), NativeShader::setVec3)
3637
}

src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLNativeShader.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class OpenGLNativeShader(
6969
glCompileShader(program)
7070

7171
if (glGetShaderi(program, GL_COMPILE_STATUS) == GL_FALSE) {
72-
throw ShaderLoadingException("Can not load shader: $file\n:" + glGetShaderInfoLog(program), glsl)
72+
throw ShaderLoadingException("Can not load shader: $file:\n" + glGetShaderInfoLog(program), glsl)
7373
}
7474

7575
return program
@@ -129,7 +129,7 @@ class OpenGLNativeShader(
129129
val location = uniformLocations.getOrPut(uniformName) {
130130
val location = glGetUniformLocation(handler, uniformName)
131131
if (location < 0) {
132-
throw IllegalArgumentException("No uniform named $uniformName in $this")
132+
throw IllegalArgumentException("No uniform named $uniformName in $this, maybe you use something that has been optimized out? Check your shader code!")
133133
}
134134
return@getOrPut location
135135
}

src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ out vec4 foutColor;
2525
#include "minosoft:animation"
2626

2727
void main() {
28+
applyDefaults();
2829
applyTint();
2930
applyTexel();
3031
}

src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.fsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ out vec4 foutColor;
2424
#include "minosoft:animation"
2525

2626
void main() {
27-
applyTexel();
27+
applyDefaults();
2828
applyTint();
29+
applyTexel();
2930
}

src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ in vec4 finFlashColor;
2727
#include "minosoft:animation"
2828

2929
void main() {
30-
applyTexel();
30+
applyDefaults();
3131
applyTint();
32+
applyTexel();
3233

3334
foutColor = mix(foutColor, finFlashColor, uFlashProgress);
3435
}

src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.fsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ out vec4 foutColor;
2525
#include "minosoft:animation"
2626

2727
void main() {
28+
applyDefaults();
2829
applyTint();
2930
applyTexel();
3031
}

src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.fsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ flat in uint finAllowTransparency;
2929

3030
void main() {
3131
if (finTintColor.a == 0.0f) discard;
32-
applyTexel();
32+
applyDefaults();
3333
applyTint();
34+
applyTexel();
3435
if (finAllowTransparency > 0u) {
3536
if (foutColor.a < 0.5f) discard;
3637
}

src/main/resources/assets/minosoft/rendering/shader/entities/player/player.fsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ flat in uint finAllowTransparency;
2929

3030
void main() {
3131
if (finTintColor.a == 0.0f) discard;
32-
applyTexel();
32+
applyDefaults();
3333
applyTint();
34+
applyTexel();
3435
if (finAllowTransparency > 0u) {
3536
if (foutColor.a < 0.5f) discard;
3637
}

src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.fsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ in vec2 finUV;
2323
#include "minosoft:animation"
2424

2525
void main() {
26-
applyTexel();
26+
applyDefaults();
2727
applyTint();
28+
applyTexel();
2829
}

0 commit comments

Comments
 (0)