From cd9b17e05756a95a0a73dd92436da0217707cc8b Mon Sep 17 00:00:00 2001 From: routersys Date: Mon, 12 Oct 2026 22:23:00 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=89=E3=81=AE=E9=87=8F=E3=81=B8=E5=A4=89?= =?UTF-8?q?=E6=8F=9B=E3=81=99=E3=82=8B=E5=89=8D=E5=87=A6=E7=90=86=E3=81=AE?= =?UTF-8?q?=E3=82=B7=E3=82=A7=E3=83=BC=E3=83=80=E3=83=BC=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SpectrumColorShift.Shader.vcxproj | 9 +++++ .../SpectrumColorShift.Shader.vcxproj.filters | 8 +++++ .../SpectrumColorShiftLinearize.hlsl | 13 +++++++ SpectrumColorShift.Shader/Srgb.hlsli | 35 +++++++++++++++++++ SpectrumColorShift/SpectrumColorShift.csproj | 1 + 5 files changed, 66 insertions(+) create mode 100644 SpectrumColorShift.Shader/SpectrumColorShiftLinearize.hlsl create mode 100644 SpectrumColorShift.Shader/Srgb.hlsli diff --git a/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj b/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj index 2c6ea7e..2253d57 100644 --- a/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj +++ b/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj @@ -156,6 +156,15 @@ Pixel Pixel + + Pixel + Pixel + Pixel + Pixel + + + + diff --git a/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj.filters b/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj.filters index 0055461..f943c89 100644 --- a/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj.filters +++ b/SpectrumColorShift.Shader/SpectrumColorShift.Shader.vcxproj.filters @@ -21,5 +21,13 @@ ソース ファイル + + ソース ファイル + + + + + ヘッダー ファイル + diff --git a/SpectrumColorShift.Shader/SpectrumColorShiftLinearize.hlsl b/SpectrumColorShift.Shader/SpectrumColorShiftLinearize.hlsl new file mode 100644 index 0000000..cffd895 --- /dev/null +++ b/SpectrumColorShift.Shader/SpectrumColorShiftLinearize.hlsl @@ -0,0 +1,13 @@ +#include "Srgb.hlsli" + +Texture2D SourceTexture : register(t0); +SamplerState SourceSampler : register(s0); + +float4 main( + float4 position : SV_POSITION, + float4 scenePosition : SCENE_POSITION, + float4 uv0 : TEXCOORD0 +) : SV_TARGET +{ + return DecodePremultiplied(SourceTexture.SampleLevel(SourceSampler, uv0.xy, 0)); +} diff --git a/SpectrumColorShift.Shader/Srgb.hlsli b/SpectrumColorShift.Shader/Srgb.hlsli new file mode 100644 index 0000000..f01a79c --- /dev/null +++ b/SpectrumColorShift.Shader/Srgb.hlsli @@ -0,0 +1,35 @@ +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; + +float3 Decode(float3 encoded) +{ + float3 low = encoded / LowSlope; + float3 high = pow((encoded + Offset) / Scale, Exponent); + return encoded <= DecodeThreshold ? low : high; +} + +float3 Encode(float3 linearColor) +{ + float3 low = linearColor * LowSlope; + float3 high = Scale * pow(linearColor, 1.0 / Exponent) - Offset; + return linearColor <= EncodeThreshold ? low : high; +} + +float3 Unpremultiply(float4 premultiplied) +{ + return premultiplied.a > 0.0 ? saturate(premultiplied.rgb / premultiplied.a) : 0.0; +} + +float4 DecodePremultiplied(float4 encoded) +{ + return float4(Decode(Unpremultiply(encoded)) * encoded.a, encoded.a); +} + +float4 EncodePremultiplied(float4 linearColor) +{ + return float4(Encode(Unpremultiply(linearColor)) * linearColor.a, linearColor.a); +} diff --git a/SpectrumColorShift/SpectrumColorShift.csproj b/SpectrumColorShift/SpectrumColorShift.csproj index bc2333a..ad2da52 100644 --- a/SpectrumColorShift/SpectrumColorShift.csproj +++ b/SpectrumColorShift/SpectrumColorShift.csproj @@ -63,6 +63,7 @@ +