// 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; }