From 6374a4b274e5048c56a820402275e28cf5ac1d39 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 29 Jun 2026 11:15:01 -0400 Subject: Cleanup and test some lighting stuff Signed-off-by: Andrew Opalach --- Shaders/alpha_as_luma.hlsl | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Shaders/alpha_as_luma.hlsl (limited to 'Shaders/alpha_as_luma.hlsl') 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 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; +} -- cgit v1.2.3-101-g0448