From 285145d105bc2bc420d5c4713bea5ae362e1fe75 Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 20 Oct 2026 18:36:47 +0900 Subject: [PATCH] =?UTF-8?q?=E9=87=8F=E5=AD=90=E5=8C=96=E3=81=A8=E3=83=8F?= =?UTF-8?q?=E3=83=83=E3=82=B7=E3=83=A5=E3=81=AE=E5=AE=9A=E6=95=B0=E3=81=AB?= =?UTF-8?q?=E5=90=8D=E5=89=8D=E3=82=92=E4=BB=98=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inflate/InflateGpuShaders.cs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Inflate/InflateGpuShaders.cs b/Inflate/InflateGpuShaders.cs index 2523882..8a5462e 100644 --- a/Inflate/InflateGpuShaders.cs +++ b/Inflate/InflateGpuShaders.cs @@ -814,26 +814,37 @@ internal readonly partial struct CopyShader( internal static class InflateShaderMath { + private const float ChannelMaximum = 255f; + private const int BitsPerChannel = 8; + private const uint GoldenRatioMultiplier = 0x9E3779B9u; + private const uint Murmur3FirstMultiplier = 0x85EBCA6Bu; + private const uint Murmur3SecondMultiplier = 0xC2B2AE35u; + private const int Murmur3FirstShift = 16; + private const int Murmur3SecondShift = 13; + public static uint MixTexel(uint index, Float4 texel) { - var packed = (uint)(texel.X * 255f + 0.5f) - | ((uint)(texel.Y * 255f + 0.5f) << 8) - | ((uint)(texel.Z * 255f + 0.5f) << 16) - | ((uint)(texel.W * 255f + 0.5f) << 24); + var packed = Quantize(texel.X) + | (Quantize(texel.Y) << BitsPerChannel) + | (Quantize(texel.Z) << (2 * BitsPerChannel)) + | (Quantize(texel.W) << (3 * BitsPerChannel)); return Mix(index, packed); } public static uint MixAlpha(uint index, float alpha) - => Mix(index, (uint)(alpha * 255f + 0.5f)); + => Mix(index, Quantize(alpha)); + + private static uint Quantize(float value) + => (uint)(value * ChannelMaximum + 0.5f); private static uint Mix(uint index, uint packed) { - var mixed = index * 0x9E3779B9u ^ packed; - mixed ^= mixed >> 16; - mixed *= 0x85EBCA6Bu; - mixed ^= mixed >> 13; - mixed *= 0xC2B2AE35u; - mixed ^= mixed >> 16; + var mixed = index * GoldenRatioMultiplier ^ packed; + mixed ^= mixed >> Murmur3FirstShift; + mixed *= Murmur3FirstMultiplier; + mixed ^= mixed >> Murmur3SecondShift; + mixed *= Murmur3SecondMultiplier; + mixed ^= mixed >> Murmur3FirstShift; return mixed; } }