summaryrefslogtreecommitdiff
path: root/src/render/shaders
diff options
context:
space:
mode:
authorUjinT34 <41110182+UjinT34@users.noreply.github.com>2026-03-29 00:41:45 +0300
committerGitHub <noreply@github.com>2026-03-28 21:41:45 +0000
commit38a7f03cf0e5ee116794a78581634ba3dab508fa (patch)
tree969891411b2af4e437a183004018cfc359a3057e /src/render/shaders
parentef2e8dfd5f7e6ee55fa7bc48e44974e64938d14a (diff)
renderer: refactor part 7: api fixes (#13631)
Part 7 of ujin's refactors --------- Co-authored-by: Vaxry <vaxry@vaxry.net>
Diffstat (limited to 'src/render/shaders')
-rw-r--r--src/render/shaders/glsl/blurFinish.glsl22
-rw-r--r--src/render/shaders/glsl/blurfinish.frag14
-rw-r--r--src/render/shaders/glsl/border.frag38
-rw-r--r--src/render/shaders/glsl/border.glsl63
-rw-r--r--src/render/shaders/glsl/cm_helpers.glsl25
-rw-r--r--src/render/shaders/glsl/defines.h6
-rw-r--r--src/render/shaders/glsl/quad.frag6
-rw-r--r--src/render/shaders/glsl/rgbamatte.frag14
-rw-r--r--src/render/shaders/glsl/shadow.frag37
-rw-r--r--src/render/shaders/glsl/shadow.glsl59
-rw-r--r--src/render/shaders/glsl/surface.frag51
11 files changed, 243 insertions, 92 deletions
diff --git a/src/render/shaders/glsl/blurFinish.glsl b/src/render/shaders/glsl/blurFinish.glsl
index f3d225c3..e7e1f1c6 100644
--- a/src/render/shaders/glsl/blurFinish.glsl
+++ b/src/render/shaders/glsl/blurFinish.glsl
@@ -1,10 +1,26 @@
+#ifndef ALLOW_INCLUDES
+#define ALLOW_INCLUDES
+#extension GL_ARB_shading_language_include : enable
+#endif
+
+#include "defines.h"
+
+#if USE_CM
+#include "cm_helpers.glsl"
+#endif
+
float hash(vec2 p) {
vec3 p3 = fract(vec3(p.xyx) * 1689.1984);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
-vec4 blurFinish(vec4 pixColor, vec2 v_texcoord, float noise, float brightness) {
+vec4 blurFinish(vec4 pixColor, vec2 v_texcoord, float noise, float brightness
+#if USE_CM
+ ,
+ int sourceTF, int targetTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
+#endif
+) {
// noise
float noiseHash = hash(v_texcoord);
float noiseAmount = noiseHash - 0.5;
@@ -13,5 +29,9 @@ vec4 blurFinish(vec4 pixColor, vec2 v_texcoord, float noise, float brightness) {
// brightness
pixColor.rgb *= min(1.0, brightness);
+#if USE_CM
+ pixColor = doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange);
+#endif
+
return pixColor;
}
diff --git a/src/render/shaders/glsl/blurfinish.frag b/src/render/shaders/glsl/blurfinish.frag
index 0342646b..51eb7684 100644
--- a/src/render/shaders/glsl/blurfinish.frag
+++ b/src/render/shaders/glsl/blurfinish.frag
@@ -9,11 +9,23 @@ uniform sampler2D tex;
uniform float noise;
uniform float brightness;
+#include "defines.h"
+#if USE_CM
+uniform int sourceTF; // eTransferFunction
+uniform int targetTF; // eTransferFunction
+#include "CM.glsl"
+#endif
+
#include "blurFinish.glsl"
layout(location = 0) out vec4 fragColor;
void main() {
vec4 pixColor = texture(tex, v_texcoord);
- fragColor = blurFinish(pixColor, v_texcoord, noise, brightness);
+ fragColor = blurFinish(pixColor, v_texcoord, noise, brightness
+#if USE_CM
+ ,
+ sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
+#endif
+ );
}
diff --git a/src/render/shaders/glsl/border.frag b/src/render/shaders/glsl/border.frag
index 151593c1..9f97348b 100644
--- a/src/render/shaders/glsl/border.frag
+++ b/src/render/shaders/glsl/border.frag
@@ -32,29 +32,41 @@ uniform vec2 fullSize;
#include "border.glsl"
layout(location = 0) out vec4 fragColor;
+#if USE_MIRROR
+layout(location = 1) out vec4 mirrorColor;
+#endif
void main() {
- fragColor = getBorder(v_texcoord, alpha, fullSizeUntransformed, radiusOuter, thick, radius, roundingPower, topLeft, fullSize, gradientLength, gradient, angle, gradient2Length,
- gradient2, angle2, gradientLerp
+#if USE_MIRROR
+ vec4[2] pixColors =
+#else
+ fragColor =
+#endif
+ getBorder(v_texcoord, alpha, fullSizeUntransformed, radiusOuter, thick, radius, roundingPower, topLeft, fullSize, gradientLength, gradient, angle, gradient2Length,
+ gradient2, angle2, gradientLerp
#if USE_CM
- ,
- sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
+ ,
+ sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
#if USE_ICC
- ,
- iccLut3D, iccLutSize
+ ,
+ iccLut3D, iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- targetPrimariesXYZ
+ ,
+ targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
+ ,
+ maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- sdrSaturation, sdrBrightnessMultiplier
+ ,
+ sdrSaturation, sdrBrightnessMultiplier
+#endif
#endif
#endif
+ );
+#if USE_MIRROR
+ fragColor = pixColors[0];
+ mirrorColor = pixColors[1];
#endif
- );
}
diff --git a/src/render/shaders/glsl/border.glsl b/src/render/shaders/glsl/border.glsl
index fa2a6980..9028ad0d 100644
--- a/src/render/shaders/glsl/border.glsl
+++ b/src/render/shaders/glsl/border.glsl
@@ -87,30 +87,35 @@ vec4 getColorForCoord(vec2 normalizedCoord, int gradientLength, vec4 gradient[10
return okLabAToSrgb(mix(result1, result2, gradientLerp));
}
-vec4 getBorder(vec2 v_texcoord, float alpha, vec2 fullSizeUntransformed, float radiusOuter, float thick, float radius, float roundingPower, vec2 topLeft, vec2 fullSize,
- int gradientLength, vec4 gradient[10], float angle, int gradient2Length, vec4 gradient2[10], float angle2, float gradientLerp
+#if USE_MIRROR
+vec4[2]
+#else
+vec4
+#endif
+ getBorder(vec2 v_texcoord, float alpha, vec2 fullSizeUntransformed, float radiusOuter, float thick, float radius, float roundingPower, vec2 topLeft, vec2 fullSize,
+ int gradientLength, vec4 gradient[10], float angle, int gradient2Length, vec4 gradient2[10], float angle2, float gradientLerp
#if USE_CM
- ,
- int sourceTF, int targetTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
+ ,
+ int sourceTF, int targetTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
#if USE_ICC
- ,
- highp sampler3D iccLut3D, float iccLutSize
+ ,
+ highp sampler3D iccLut3D, float iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- mat3 targetPrimariesXYZ
+ ,
+ mat3 targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- float maxLuminance, float dstMaxLuminance, float dstRefLuminance, float srcRefLuminance
+ ,
+ float maxLuminance, float dstMaxLuminance, float dstRefLuminance, float srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- float sdrSaturation, float sdrBrightnessMultiplier
+ ,
+ float sdrSaturation, float sdrBrightnessMultiplier
#endif
#endif
#endif
-) {
+ ) {
vec2 pixCoord = vec2(gl_FragCoord);
vec2 pixCoordOuter = pixCoord;
vec2 originalPixCoord = v_texcoord;
@@ -176,28 +181,38 @@ vec4 getBorder(vec2 v_texcoord, float alpha, vec2 fullSizeUntransformed, float r
pixColor.rgb *= pixColor[3];
#if USE_CM
- pixColor = doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
+#if USE_MIRROR
+ vec4[2] pixColors =
+#else
+ pixColor =
+#endif
+ doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
#if USE_ICC
- ,
- iccLut3D, iccLutSize
+ ,
+ iccLut3D, iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- targetPrimariesXYZ
+ ,
+ targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
+ ,
+ maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- sdrSaturation, sdrBrightnessMultiplier
+ ,
+ sdrSaturation, sdrBrightnessMultiplier
#endif
#endif
- );
+ );
#endif
+#if USE_MIRROR
+ pixColors[0] *= alpha * additionalAlpha;
+ pixColors[1] *= alpha * additionalAlpha;
+ return pixColors;
+#else
pixColor *= alpha * additionalAlpha;
-
return pixColor;
+#endif
}
diff --git a/src/render/shaders/glsl/cm_helpers.glsl b/src/render/shaders/glsl/cm_helpers.glsl
index 5e0d14f6..472c6ea5 100644
--- a/src/render/shaders/glsl/cm_helpers.glsl
+++ b/src/render/shaders/glsl/cm_helpers.glsl
@@ -204,10 +204,15 @@ vec4 fromLinearNit(vec4 color, int tf, vec2 range) {
#include "tonemap.glsl"
#endif
-vec4 doColorManagement(vec4 pixColor, int srcTF, int dstTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
+#if USE_MIRROR
+vec4[2]
+#else
+vec4
+#endif
+ doColorManagement(vec4 pixColor, int srcTF, int dstTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
#if USE_ICC
- ,
- highp sampler3D iccLut3D, float iccLutSize
+ ,
+ highp sampler3D iccLut3D, float iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
,
@@ -222,7 +227,7 @@ vec4 doColorManagement(vec4 pixColor, int srcTF, int dstTF, mat3 convertMatrix,
float sdrSaturation, float sdrBrightnessMultiplier
#endif
#endif
-) {
+ ) {
pixColor.rgb /= max(pixColor.a, 0.001);
pixColor.rgb = toLinearRGB(pixColor.rgb, srcTF);
#if USE_ICC
@@ -235,6 +240,11 @@ vec4 doColorManagement(vec4 pixColor, int srcTF, int dstTF, mat3 convertMatrix,
#if USE_TONEMAP
pixColor = tonemap(pixColor, dstxyz, maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance);
#endif
+#if USE_MIRROR
+ // TODO HDR -> SDR tonemap
+ vec4 mirrorColor = fromLinearNit(pixColor, CM_TRANSFER_FUNCTION_GAMMA22,
+ srcTF == CM_TRANSFER_FUNCTION_GAMMA22 || srcTF == CM_TRANSFER_FUNCTION_SRGB ? srcTFRange : vec2(SDR_MIN_LUMINANCE, SDR_MAX_LUMINANCE));
+#endif
pixColor = fromLinearNit(pixColor, dstTF, dstTFRange);
#if USE_SDR_MOD
pixColor = saturate(pixColor, dstxyz, sdrSaturation);
@@ -242,7 +252,14 @@ vec4 doColorManagement(vec4 pixColor, int srcTF, int dstTF, mat3 convertMatrix,
#endif
#endif
+#if USE_MIRROR
+ vec4[2] pixColors;
+ pixColors[0] = pixColor;
+ pixColors[1] = mirrorColor;
+ return pixColors;
+#else
return pixColor;
+#endif
}
#endif \ No newline at end of file
diff --git a/src/render/shaders/glsl/defines.h b/src/render/shaders/glsl/defines.h
index 31b120a4..a04e0250 100644
--- a/src/render/shaders/glsl/defines.h
+++ b/src/render/shaders/glsl/defines.h
@@ -1,4 +1,7 @@
// DO NOT EDIT. Will be overwritten in runtime
+// Values here are only for highlighting and static checking
+// 1 assumes that a shader either supports this feature or doesn't use any code supporting it
+// 0 assumes that shader uses some code supporting the feature but will never have this feature enabled
#define USE_RGBA 1
#define USE_DISCARD 1
#define USE_TINT 1
@@ -7,4 +10,5 @@
#define USE_TONEMAP 1
#define USE_SDR_MOD 1
#define USE_BLUR 1
-#define USE_ICC 1
+#define USE_ICC 0
+#define USE_MIRROR 0
diff --git a/src/render/shaders/glsl/quad.frag b/src/render/shaders/glsl/quad.frag
index 61895a60..dc1945af 100644
--- a/src/render/shaders/glsl/quad.frag
+++ b/src/render/shaders/glsl/quad.frag
@@ -16,6 +16,9 @@ uniform vec2 fullSize;
#endif
layout(location = 0) out vec4 fragColor;
+#if USE_MIRROR
+layout(location = 1) out vec4 mirrorColor;
+#endif
void main() {
vec4 pixColor = v_color;
@@ -24,4 +27,7 @@ void main() {
#endif
fragColor = pixColor;
+#if USE_MIRROR
+ mirrorColor = fragColor;
+#endif
}
diff --git a/src/render/shaders/glsl/rgbamatte.frag b/src/render/shaders/glsl/rgbamatte.frag
index a7213cfe..72fdc1d6 100644
--- a/src/render/shaders/glsl/rgbamatte.frag
+++ b/src/render/shaders/glsl/rgbamatte.frag
@@ -1,11 +1,21 @@
#version 300 es
+#define ALLOW_INCLUDES
+#extension GL_ARB_shading_language_include : enable
-precision highp float;
-in vec2 v_texcoord; // is in 0-1
+#include "defines.h"
+
+precision highp float;
+in vec2 v_texcoord; // is in 0-1
uniform sampler2D tex;
uniform sampler2D texMatte;
layout(location = 0) out vec4 fragColor;
+#if USE_MIRROR
+layout(location = 1) out vec4 mirrorColor;
+#endif
void main() {
fragColor = texture(tex, v_texcoord) * texture(texMatte, v_texcoord)[0]; // I know it only uses R, but matte should be black/white anyways.
+#if USE_MIRROR
+ mirrorColor = fragColor;
+#endif
}
diff --git a/src/render/shaders/glsl/shadow.frag b/src/render/shaders/glsl/shadow.frag
index c23ebd5d..5ba3d879 100644
--- a/src/render/shaders/glsl/shadow.frag
+++ b/src/render/shaders/glsl/shadow.frag
@@ -28,30 +28,41 @@ uniform float shadowPower;
#include "shadow.glsl"
layout(location = 0) out vec4 fragColor;
+#if USE_MIRROR
+layout(location = 1) out vec4 mirrorColor;
+#endif
void main() {
vec4 pixColor = v_color;
-
- fragColor = getShadow(pixColor, v_texcoord, radius, roundingPower, topLeft, fullSize, range, shadowPower, bottomRight
+#if USE_MIRROR
+ vec4[2] pixColors =
+#else
+ fragColor =
+#endif
+ getShadow(pixColor, v_texcoord, radius, roundingPower, topLeft, fullSize, range, shadowPower, bottomRight
#if USE_CM
- ,
- sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
+ ,
+ sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
#if USE_ICC
- ,
- iccLut3D, iccLutSize
+ ,
+ iccLut3D, iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- targetPrimariesXYZ
+ ,
+ targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
+ ,
+ maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- sdrSaturation, sdrBrightnessMultiplier
+ ,
+ sdrSaturation, sdrBrightnessMultiplier
+#endif
#endif
#endif
+ );
+#if USE_MIRROR
+ fragColor = pixColors[0];
+ mirrorColor = pixColors[1];
#endif
- );
} \ No newline at end of file
diff --git a/src/render/shaders/glsl/shadow.glsl b/src/render/shaders/glsl/shadow.glsl
index 48cde562..265dba00 100644
--- a/src/render/shaders/glsl/shadow.glsl
+++ b/src/render/shaders/glsl/shadow.glsl
@@ -23,29 +23,34 @@ float modifiedLength(vec2 a, float roundingPower) {
return pow(pow(abs(a.x), roundingPower) + pow(abs(a.y), roundingPower), 1.0 / roundingPower);
}
-vec4 getShadow(vec4 pixColor, vec2 v_texcoord, float radius, float roundingPower, vec2 topLeft, vec2 fullSize, float range, float shadowPower, vec2 bottomRight
+#if USE_MIRROR
+vec4[2]
+#else
+vec4
+#endif
+ getShadow(vec4 pixColor, vec2 v_texcoord, float radius, float roundingPower, vec2 topLeft, vec2 fullSize, float range, float shadowPower, vec2 bottomRight
#if USE_CM
- ,
- int sourceTF, int targetTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
+ ,
+ int sourceTF, int targetTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
#if USE_ICC
- ,
- highp sampler3D iccLut3D, float iccLutSize
+ ,
+ highp sampler3D iccLut3D, float iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- mat3 targetPrimariesXYZ
+ ,
+ mat3 targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- float maxLuminance, float dstMaxLuminance, float dstRefLuminance, float srcRefLuminance
+ ,
+ float maxLuminance, float dstMaxLuminance, float dstRefLuminance, float srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- float sdrSaturation, float sdrBrightnessMultiplier
+ ,
+ float sdrSaturation, float sdrBrightnessMultiplier
#endif
#endif
#endif
-) {
+ ) {
float originalAlpha = pixColor[3];
bool done = false;
@@ -100,27 +105,35 @@ vec4 getShadow(vec4 pixColor, vec2 v_texcoord, float radius, float roundingPower
pixColor.rgb *= pixColor[3];
#if USE_CM
- pixColor = doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
+#if USE_MIRROR
+ vec4[2] pixColors =
+#else
+ pixColor =
+#endif
+ doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
#if USE_ICC
- ,
- iccLut3D, iccLutSize
+ ,
+ iccLut3D, iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- targetPrimariesXYZ
+ ,
+ targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
+ ,
+ maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- sdrSaturation, sdrBrightnessMultiplier
+ ,
+ sdrSaturation, sdrBrightnessMultiplier
#endif
#endif
- );
+ );
#endif
-
+#if USE_MIRROR
+ return pixColors;
+#else
return pixColor;
+#endif
}
#endif \ No newline at end of file
diff --git a/src/render/shaders/glsl/surface.frag b/src/render/shaders/glsl/surface.frag
index 30023bc8..076ca62c 100644
--- a/src/render/shaders/glsl/surface.frag
+++ b/src/render/shaders/glsl/surface.frag
@@ -47,6 +47,9 @@ const mat3 targetPrimariesXYZ = mat3(0.0);
#endif
layout(location = 0) out vec4 fragColor;
+#if USE_MIRROR
+layout(location = 1) out vec4 mirrorColor;
+#endif
void main() {
#if USE_RGBA
vec4 pixColor = texture(tex, v_texcoord);
@@ -63,25 +66,34 @@ void main() {
#endif
#if USE_CM
- pixColor = doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
+#if USE_MIRROR
+ vec4[2] pixColors =
+#else
+ pixColor =
+#endif
+ doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange
#if USE_ICC
- ,
- iccLut3D, iccLutSize
+ ,
+ iccLut3D, iccLutSize
#else
#if USE_TONEMAP || USE_SDR_MOD
- ,
- targetPrimariesXYZ
+ ,
+ targetPrimariesXYZ
#endif
#if USE_TONEMAP
- ,
- maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
+ ,
+ maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance
#endif
#if USE_SDR_MOD
- ,
- sdrSaturation, sdrBrightnessMultiplier
+ ,
+ sdrSaturation, sdrBrightnessMultiplier
+#endif
#endif
+ );
#endif
- );
+#if USE_MIRROR
+ pixColor = pixColors[0];
+ mirrorColor = pixColors[1];
#endif
#if USE_TINT
@@ -101,4 +113,23 @@ void main() {
#endif
fragColor = pixColor * alpha;
+#if USE_MIRROR
+#if USE_TINT
+ mirrorColor.rgb = mirrorColor.rgb * tint;
+#endif
+
+#if USE_ROUNDING
+ mirrorColor = rounding(mirrorColor, radius, roundingPower, topLeft, fullSize);
+#endif
+#if USE_BLUR
+#if USE_DISCARD
+ mirrorColor = mix(mirrorColor, vec4(mix(texture(blurredBG, v_texcoord * uvSize + uvOffset).rgb, mirrorColor.rgb, mirrorColor.a), 1.0),
+ discardAlpha && (mirrorColor.a <= discardAlphaValue) ? 0.0 : 1.0);
+#else
+ mirrorColor = vec4(mix(texture(blurredBG, v_texcoord * uvSize + uvOffset).rgb, mirrorColor.rgb, mirrorColor.a), 1.0);
+#endif
+#endif
+
+ mirrorColor = mirrorColor * alpha;
+#endif
}