summaryrefslogtreecommitdiff
path: root/Shaders/alpha_as_luma.hlsl
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-06-29 11:15:01 -0400
committerAndrew Opalach <andrew@akon.city> 2026-06-29 11:15:01 -0400
commit6374a4b274e5048c56a820402275e28cf5ac1d39 (patch)
tree6578b5ea21da09740d70b5f7492ea8925f9ed467 /Shaders/alpha_as_luma.hlsl
parent9ea738140d941ef0a7193e4f45278f2923997cc2 (diff)
downloadWorldTuningTool-6374a4b274e5048c56a820402275e28cf5ac1d39.tar.gz
WorldTuningTool-6374a4b274e5048c56a820402275e28cf5ac1d39.tar.bz2
WorldTuningTool-6374a4b274e5048c56a820402275e28cf5ac1d39.zip
Cleanup and test some lighting stuff
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'Shaders/alpha_as_luma.hlsl')
-rw-r--r--Shaders/alpha_as_luma.hlsl58
1 files changed, 58 insertions, 0 deletions
diff --git a/Shaders/alpha_as_luma.hlsl b/Shaders/alpha_as_luma.hlsl
new file mode 100644
index 0000000..525f3c6
--- /dev/null
+++ b/Shaders/alpha_as_luma.hlsl
@@ -0,0 +1,58 @@
+// https://stackoverflow.com/a/37624009
+float inverseGamma(float t)
+{
+ return ((t <= 0.0404482362771076) ? (t/12.92) : pow((t + 0.055)/1.055, 2.4));
+}
+
+// CIE L*a*b* f function (used to convert XYZ to L*a*b*)
+// http://en.wikipedia.org/wiki/Lab_color_space
+float LABF(float t)
+{
+ return ((t >= 8.85645167903563082e-3) ? pow(t, (1.0/3.0)) : (841.0/108.0)*t + (4.0/29.0));
+}
+
+float rgbToCIEL(float3 p)
+{
+ float r = inverseGamma(p.r);
+ float g = inverseGamma(p.g);
+ float b = inverseGamma(p.b);
+
+ // Observer = 2°, Illuminant = D65
+ float y = 0.2125862307855955516*r + 0.7151703037034108499*g + 0.07220049864333622685*b;
+
+ // At this point we've done RGBtoXYZ now do XYZ to Lab
+
+ // y /= WHITEPOINT_Y; The white point for y in D65 is 1.0
+ y = LABF(y);
+
+ // This is the "normal" conversion which produces values scaled to 100
+ // Lab.L = 116.0*y - 16.0;
+ return 1.16*y - 0.16;
+}
+
+// ---- Created with 3Dmigoto v1.4.9 on Sun Jun 28 13:42:41 2026
+
+cbuffer CBSystem : register(b3)
+{
+ uint4 iRegion : packoffset(c0);
+ float fSourceMipLevel : packoffset(c1) = {0};
+ float fGammaCorrect : packoffset(c1.y) = {0.454545468};
+ float fGammaCorrectEx : packoffset(c1.z) = {1};
+}
+
+SamplerState SSSystemCopy : register(s0);
+Texture2D<float4> tBaseMap : register(t0);
+
+void main(
+ float4 v0 : SV_POSITION0,
+ float2 v1 : TexCoord0,
+ out float4 o0 : SV_TARGET0)
+{
+ float4 r0;
+ r0.xyz = tBaseMap.SampleLevel(SSSystemCopy, v1.xy, fSourceMipLevel).xyz;
+ o0.w = rgbToCIEL(r0.xyz);
+ //o0.w = sqrt(dot(r0.xyz, float3(0.298999995, 0.587000012, 0.114)));
+ //o0.w = dot(r0.xyz, float3(0.298999995, 0.587000012, 0.114));
+ o0.xyz = r0.xyz;
+ return;
+}