From f763d6284d11b3986a57f708297c4f5489b4c339 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Sun, 10 Dec 2023 01:45:17 +0100 Subject: [PATCH] shaders: extract tint to include Some shaders don't need tinting, that fixes them (was 0,0,0,0 color before, thus breaking it) --- .../minosoft/rendering/shader/chunk/chunk.fsh | 2 ++ .../minosoft/rendering/shader/chunk/chunk.vsh | 1 + .../shader/entities/features/block/block.fsh | 2 ++ .../shader/entities/features/block/block.vsh | 1 + .../features/block/flashing/flashing.fsh | 2 ++ .../features/block/flashing/flashing.vsh | 1 + .../shader/entities/features/text/text.fsh | 2 ++ .../shader/entities/features/text/text.vsh | 1 + .../shader/entities/player/arm/arm.fsh | 2 ++ .../shader/entities/player/arm/arm.vsh | 8 ++--- .../shader/entities/player/player.fsh | 2 ++ .../shader/entities/player/player.vsh | 3 +- .../shader/generic/texture/texture.fsh | 2 ++ .../shader/generic/texture/texture.vsh | 1 + .../shader/generic/texture_2d/texture_2d.fsh | 2 ++ .../shader/generic/texture_2d/texture_2d.vsh | 1 + .../minosoft/rendering/shader/gui/gui.fsh | 2 ++ .../minosoft/rendering/shader/gui/gui.vsh | 1 + .../rendering/shader/includes/animation.glsl | 9 +----- .../shader/includes/skeletal/shade.glsl | 2 +- .../rendering/shader/includes/tint.glsl | 32 +++++++++++++++++++ .../rendering/shader/particle/particle.fsh | 2 ++ .../rendering/shader/particle/particle.gsh | 3 ++ .../rendering/shader/particle/particle.vsh | 3 -- .../shader/skeletal/lightmap/lightmap.fsh | 2 ++ .../shader/skeletal/lightmap/lightmap.vsh | 1 + .../shader/skeletal/normal/normal.fsh | 2 ++ .../shader/skeletal/normal/normal.vsh | 1 + 28 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/assets/minosoft/rendering/shader/includes/tint.glsl diff --git a/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh b/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh index 47ba54079..f187f8070 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.fsh @@ -18,6 +18,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -25,4 +26,5 @@ out vec4 foutColor; void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.vsh b/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.vsh index 59e254203..b7aa88dbf 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/chunk/chunk.vsh @@ -22,6 +22,7 @@ out vec3 finFragmentPosition; uniform mat4 uViewProjectionMatrix; +#include "minosoft:tint" #include "minosoft:color" #include "minosoft:light" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.fsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.fsh index 9ae29aea2..a59fb1818 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.fsh @@ -18,6 +18,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -25,4 +26,5 @@ out vec4 foutColor; void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.vsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.vsh index 77615cae6..214d5fb00 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/block.vsh @@ -25,6 +25,7 @@ uniform uint uTintColor; out vec3 finFragmentPosition; +#include "minosoft:tint" #include "minosoft:animation" #include "minosoft:color" diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh index feeb49b99..18dfaa5c8 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.fsh @@ -21,6 +21,7 @@ uniform float uFlashProgress; in vec4 finFlashColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -28,6 +29,7 @@ in vec4 finFlashColor; void main() { applyTexel(); + applyTint(); foutColor = mix(foutColor, finFlashColor, uFlashProgress); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh index 3c5426fe4..30f05d9cf 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/block/flashing/flashing.vsh @@ -27,6 +27,7 @@ out vec4 finFlashColor; out vec3 finFragmentPosition; +#include "minosoft:tint" #include "minosoft:animation" #include "minosoft:color" diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.fsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.fsh index dc6793123..bf9254fdf 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.fsh @@ -18,6 +18,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -25,4 +26,5 @@ out vec4 foutColor; void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.vsh b/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.vsh index 5fcb7a028..6cb2d71ea 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/features/text/text.vsh @@ -25,6 +25,7 @@ uniform uint uTintColor; out vec3 finFragmentPosition; +#include "minosoft:tint" #include "minosoft:color" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.fsh b/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.fsh index a3b1db04e..f1e288234 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.fsh @@ -19,6 +19,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -29,6 +30,7 @@ flat in uint finAllowTransparency; void main() { if (finTintColor.a == 0.0f) discard; applyTexel(); + applyTint(); if (finAllowTransparency > 0u) { if (foutColor.a < 0.5f) discard; } diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.vsh b/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.vsh index 6dc71cfad..4f184467a 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/player/arm/arm.vsh @@ -13,6 +13,8 @@ #version 330 core +#define POSITIVE_INFINITY 1.0f / 0.0f + layout (location = 0) in vec3 vinPosition; layout (location = 1) in vec2 vinUV; layout (location = 2) in float vinPartTransformNormal; // part(0x1FD0000) transform (0x7F000), normal (0xFFF) @@ -28,13 +30,9 @@ uniform mat4 uTransform; flat out uint finAllowTransparency; -out vec4 finTintColor; +#include "minosoft:tint" #include "minosoft:color" - - -#define POSITIVE_INFINITY 1.0f / 0.0f - #include "minosoft:skeletal/shade" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.fsh b/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.fsh index a3b1db04e..f1e288234 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.fsh @@ -19,6 +19,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -29,6 +30,7 @@ flat in uint finAllowTransparency; void main() { if (finTintColor.a == 0.0f) discard; applyTexel(); + applyTint(); if (finAllowTransparency > 0u) { if (foutColor.a < 0.5f) discard; } diff --git a/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.vsh b/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.vsh index a5ea57388..90810a889 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/entities/player/player.vsh @@ -26,8 +26,7 @@ uniform uint uSkinParts; flat out uint finAllowTransparency; -out vec4 finTintColor; - +#include "minosoft:tint" #include "minosoft:skeletal/vertex" #include "minosoft:color" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.fsh b/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.fsh index 00bb026cd..3f97dc3d8 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.fsh @@ -17,10 +17,12 @@ out vec4 foutColor; in vec2 finUV; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:animation" void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.vsh b/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.vsh index 461a81f40..6dd10103a 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/generic/texture/texture.vsh @@ -18,6 +18,7 @@ layout (location = 1) in vec2 vinUV; layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000), animation index (0x00000FFF) layout (location = 3) in float vinTintColor;// Light (0xFF000000); 3 bytes color (0x00FFFFFF) +#include "minosoft:tint" #include "minosoft:color" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.fsh b/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.fsh index dcb4a478b..f8b883eef 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.fsh @@ -18,10 +18,12 @@ out vec4 foutColor; in vec2 finUV; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:animation" void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.vsh b/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.vsh index 8774c240c..73b4940ea 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/generic/texture_2d/texture_2d.vsh @@ -18,6 +18,7 @@ layout (location = 1) in vec2 vinUV; layout (location = 2) in float vinIndexLayerAnimation;// texture index (0xF0000000), texture layer (0x0FFFF000), animation index (0x00000FFF) layout (location = 3) in float vinTintColor; +#include "minosoft:tint" #include "minosoft:color" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/gui/gui.fsh b/src/main/resources/assets/minosoft/rendering/shader/gui/gui.fsh index d55f9c861..ccda9e57a 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/gui/gui.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/gui/gui.fsh @@ -17,10 +17,12 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:animation" void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/gui/gui.vsh b/src/main/resources/assets/minosoft/rendering/shader/gui/gui.vsh index 9d95a1272..74e4d0753 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/gui/gui.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/gui/gui.vsh @@ -19,6 +19,7 @@ layout (location = 2) in float vinIndexLayerAnimation; layout (location = 3) in float vinTintColor; +#include "minosoft:tint" #include "minosoft:color" #include "minosoft:animation" diff --git a/src/main/resources/assets/minosoft/rendering/shader/includes/animation.glsl b/src/main/resources/assets/minosoft/rendering/shader/includes/animation.glsl index e1e8f2ead..6e2853012 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/includes/animation.glsl +++ b/src/main/resources/assets/minosoft/rendering/shader/includes/animation.glsl @@ -35,17 +35,10 @@ layout(std140) uniform uSpriteBuffer flat out uint finAnimationArray1; out vec3 finAnimationPosition1; flat out uint finAnimationArray2; out vec3 finAnimationPosition2; out float finAnimationInterpolation; - -// TODO: remove -#ifndef NO_TINT_COLOR -out vec4 finTintColor; -#endif #elif defined SHADER_TYPE_FRAGMENT flat in uint finAnimationArray1; in vec3 finAnimationPosition1; flat in uint finAnimationArray2; in vec3 finAnimationPosition2; in float finAnimationInterpolation; - -in vec4 finTintColor;// TODO: remove #endif @@ -70,7 +63,7 @@ vec4 getAnimationTexture() { } void applyTexel() { - vec4 texel = getAnimationTexture() * finTintColor; + vec4 texel = getAnimationTexture(); foutColor = texel; #ifdef TRANSPARENT diff --git a/src/main/resources/assets/minosoft/rendering/shader/includes/skeletal/shade.glsl b/src/main/resources/assets/minosoft/rendering/shader/includes/skeletal/shade.glsl index 8085b5fd7..64ed9bffb 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/includes/skeletal/shade.glsl +++ b/src/main/resources/assets/minosoft/rendering/shader/includes/skeletal/shade.glsl @@ -11,7 +11,7 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ #define DEGREE_90 1.5707964f -#define NO_TINT_COLOR +#include "minosoft:tint" float decodeNormalPart(uint data) { if (data < 8u) return (data / 8.0f) - 1.0f; diff --git a/src/main/resources/assets/minosoft/rendering/shader/includes/tint.glsl b/src/main/resources/assets/minosoft/rendering/shader/includes/tint.glsl new file mode 100644 index 000000000..f12749143 --- /dev/null +++ b/src/main/resources/assets/minosoft/rendering/shader/includes/tint.glsl @@ -0,0 +1,32 @@ +/* + * Minosoft + * Copyright (C) 2020 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. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +#ifndef INCLUDE_MINOSOFT_TINT +#define INCLUDE_MINOSOFT_TINT + +#ifdef SHADER_TYPE_VERTEX +out vec4 finTintColor; +#endif + +#ifdef SHADER_TYPE_FRAGMENT +in vec4 finTintColor; + + +void applyTint() { + if (finTintColor.a <= 0.0f) discard; + foutColor *= finTintColor; +} +#endif + + +#endif diff --git a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.fsh b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.fsh index d38ba482a..3fa1f471c 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.fsh @@ -15,10 +15,12 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:animation" void main() { applyTexel(); + applyTint(); } 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 fbac40835..5f914286d 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.gsh +++ b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.gsh @@ -36,6 +36,9 @@ in Vertex } ginVertex[]; +#include "minosoft:tint" + + void emit(vec3 offset, vec2 uv) { vec3 pointPosition = gl_in[0].gl_Position.xyz; diff --git a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh index a49450b1c..48d65c34c 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/particle/particle.vsh @@ -13,8 +13,6 @@ #version 330 core -#define NO_TINT_COLOR - layout (location = 0) in vec3 vinPosition; layout (location = 1) in vec2 vinMinUV; layout (location = 2) in vec2 vinMaxUV; @@ -25,7 +23,6 @@ layout (location = 5) in float vinTintColor; layout (location = 6) in float vinLight; - #include "minosoft:light" diff --git a/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.fsh b/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.fsh index 4282a35ff..beec3c005 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.fsh @@ -18,6 +18,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -25,4 +26,5 @@ out vec4 foutColor; void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.vsh b/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.vsh index abcf6b27a..48cb4c3c9 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/skeletal/lightmap/lightmap.vsh @@ -20,6 +20,7 @@ layout (location = 3) in float vinIndexLayerAnimation;// texture index (0xF00000 out vec3 finFragmentPosition; +#include "minosoft:tint" #include "minosoft:animation" #include "minosoft:light" #include "minosoft:skeletal/vertex" diff --git a/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.fsh b/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.fsh index b0894f12d..a75ab6c18 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.fsh @@ -19,6 +19,7 @@ out vec4 foutColor; +#include "minosoft:tint" #include "minosoft:texture" #include "minosoft:alpha" #include "minosoft:fog" @@ -26,4 +27,5 @@ out vec4 foutColor; void main() { applyTexel(); + applyTint(); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.vsh b/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.vsh index 0fe11e4bc..d298b02d9 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/skeletal/normal/normal.vsh @@ -20,6 +20,7 @@ layout (location = 3) in float vinIndexLayerAnimation;// texture index (0xF00000 out vec3 finFragmentPosition; +#include "minosoft:tint" #include "minosoft:animation" #include "minosoft:color" #include "minosoft:skeletal/vertex"