From c6272069172644c5587eb10cd33445ae283dc44a Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 13 Oct 2026 16:05:50 +0900 Subject: [PATCH] =?UTF-8?q?sRGB=E3=81=AE=E5=A4=89=E6=8F=9B=E3=81=AE?= =?UTF-8?q?=E5=90=8D=E5=89=8D=E3=81=AB=E6=8E=A5=E9=A0=AD=E8=BE=9E=E3=82=92?= =?UTF-8?q?=E4=BB=98=E3=81=91=E3=80=81=E4=BD=BF=E3=82=8F=E3=82=8C=E3=81=AA?= =?UTF-8?q?=E3=81=84=E5=AE=9A=E6=95=B0=E3=82=92=E9=99=A4=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpectrumColorShift.Shader/Physical.hlsli | 1 - SpectrumColorShift.Shader/Srgb.hlsli | 32 +++++++++---------- .../SpectralShaderContractTests.cs | 21 ++++++------ 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/SpectrumColorShift.Shader/Physical.hlsli b/SpectrumColorShift.Shader/Physical.hlsli index 3adc5d1..7cdf0c4 100644 --- a/SpectrumColorShift.Shader/Physical.hlsli +++ b/SpectrumColorShift.Shader/Physical.hlsli @@ -7,7 +7,6 @@ Texture2D LightTexture : register(t1); SamplerState LightSampler : register(s1); -static const int MaxSteps = 64; static const int TableSize = 128; static const int FilterTableSize = 132; static const int ModeRadial = 2; diff --git a/SpectrumColorShift.Shader/Srgb.hlsli b/SpectrumColorShift.Shader/Srgb.hlsli index f01a79c..2be0f7c 100644 --- a/SpectrumColorShift.Shader/Srgb.hlsli +++ b/SpectrumColorShift.Shader/Srgb.hlsli @@ -1,22 +1,22 @@ -static const float DecodeThreshold = 0.04045; -static const float EncodeThreshold = 0.0031308; -static const float LowSlope = 12.92; -static const float Offset = 0.055; -static const float Scale = 1.055; -static const float Exponent = 2.4; +static const float SrgbDecodeThreshold = 0.04045; +static const float SrgbEncodeThreshold = 0.0031308; +static const float SrgbLowSlope = 12.92; +static const float SrgbOffset = 0.055; +static const float SrgbScale = 1.055; +static const float SrgbExponent = 2.4; -float3 Decode(float3 encoded) +float3 SrgbDecode(float3 encoded) { - float3 low = encoded / LowSlope; - float3 high = pow((encoded + Offset) / Scale, Exponent); - return encoded <= DecodeThreshold ? low : high; + float3 low = encoded / SrgbLowSlope; + float3 high = pow((encoded + SrgbOffset) / SrgbScale, SrgbExponent); + return encoded <= SrgbDecodeThreshold ? low : high; } -float3 Encode(float3 linearColor) +float3 SrgbEncode(float3 linearColor) { - float3 low = linearColor * LowSlope; - float3 high = Scale * pow(linearColor, 1.0 / Exponent) - Offset; - return linearColor <= EncodeThreshold ? low : high; + float3 low = linearColor * SrgbLowSlope; + float3 high = SrgbScale * pow(linearColor, 1.0 / SrgbExponent) - SrgbOffset; + return linearColor <= SrgbEncodeThreshold ? low : high; } float3 Unpremultiply(float4 premultiplied) @@ -26,10 +26,10 @@ float3 Unpremultiply(float4 premultiplied) float4 DecodePremultiplied(float4 encoded) { - return float4(Decode(Unpremultiply(encoded)) * encoded.a, encoded.a); + return float4(SrgbDecode(Unpremultiply(encoded)) * encoded.a, encoded.a); } float4 EncodePremultiplied(float4 linearColor) { - return float4(Encode(Unpremultiply(linearColor)) * linearColor.a, linearColor.a); + return float4(SrgbEncode(Unpremultiply(linearColor)) * linearColor.a, linearColor.a); } diff --git a/SpectrumColorShift.Tests/SpectralShaderContractTests.cs b/SpectrumColorShift.Tests/SpectralShaderContractTests.cs index ba5a353..248410b 100644 --- a/SpectrumColorShift.Tests/SpectralShaderContractTests.cs +++ b/SpectrumColorShift.Tests/SpectralShaderContractTests.cs @@ -52,7 +52,6 @@ public sealed partial class SpectralShaderContractTests [Fact] public void TheShaderAndTheEffectAgreeOnTheConstants() { - Assert.Equal(Spectrum.MaxSteps, Constant("MaxSteps")); Assert.Equal(Spectrum.SpectralTableLength, Constant("TableSize")); Assert.Equal(SpectralFilter.TableLength, Constant("FilterTableSize")); Assert.Equal((int)ShiftMode.Radial, Constant("ModeRadial")); @@ -75,23 +74,23 @@ public sealed partial class SpectralShaderContractTests } [Theory] - [InlineData("DecodeThreshold", 0.04045f)] - [InlineData("EncodeThreshold", 0.0031308f)] - [InlineData("LowSlope", 12.92f)] - [InlineData("Offset", 0.055f)] - [InlineData("Scale", 1.055f)] - [InlineData("Exponent", 2.4f)] + [InlineData("SrgbDecodeThreshold", 0.04045f)] + [InlineData("SrgbEncodeThreshold", 0.0031308f)] + [InlineData("SrgbLowSlope", 12.92f)] + [InlineData("SrgbOffset", 0.055f)] + [InlineData("SrgbScale", 1.055f)] + [InlineData("SrgbExponent", 2.4f)] public void TheSrgbHeaderHoldsTheStandardTransferConstants(string name, float expected) => Assert.Equal(expected, Constant(SrgbSource, name)); [Fact] public void TheSrgbCurvesMeetAtTheThresholds() { - var slope = Constant(SrgbSource, "LowSlope"); - var linearEnd = Constant(SrgbSource, "EncodeThreshold"); - var power = Constant(SrgbSource, "Scale") * MathF.Pow(linearEnd, 1f / Constant(SrgbSource, "Exponent")) - Constant(SrgbSource, "Offset"); + var slope = Constant(SrgbSource, "SrgbLowSlope"); + var linearEnd = Constant(SrgbSource, "SrgbEncodeThreshold"); + var power = Constant(SrgbSource, "SrgbScale") * MathF.Pow(linearEnd, 1f / Constant(SrgbSource, "SrgbExponent")) - Constant(SrgbSource, "SrgbOffset"); - Assert.Equal(Constant(SrgbSource, "DecodeThreshold"), slope * linearEnd, 1e-5f); + Assert.Equal(Constant(SrgbSource, "SrgbDecodeThreshold"), slope * linearEnd, 1e-5f); Assert.Equal(slope * linearEnd, power, 1e-5f); }