From cade9e41dc91bfa166c788fcc35f27477165f0bf Mon Sep 17 00:00:00 2001 From: routersys Date: Wed, 14 Oct 2026 08:14:38 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B7=E3=82=A7=E3=83=BC=E3=83=80=E3=83=BC?= =?UTF-8?q?=E3=81=AE=E5=90=8D=E5=89=8D=E3=81=A8=E5=AE=9A=E6=95=B0=E3=82=92?= =?UTF-8?q?=E8=AA=AD=E3=81=BF=E5=8F=96=E3=82=8A=E3=82=84=E3=81=99=E3=81=8F?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MetaballSpectrum.Shader/MetaballSpectrum.hlsl | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/MetaballSpectrum.Shader/MetaballSpectrum.hlsl b/MetaballSpectrum.Shader/MetaballSpectrum.hlsl index 543b779..84e55d6 100644 --- a/MetaballSpectrum.Shader/MetaballSpectrum.hlsl +++ b/MetaballSpectrum.Shader/MetaballSpectrum.hlsl @@ -8,6 +8,10 @@ cbuffer Constants : register(b0) float4 values[64] : packoffset(c3); }; +static const float MinimumReach = 0.0001; +static const float MinimumSlope = 0.00001; +static const float MinimumAntialias = 0.5; + float4 main( float4 position : SV_POSITION, float4 scenePosition : SCENE_POSITION, @@ -24,44 +28,44 @@ float4 main( float threshold = style.x; float rimThickness = style.y; float rimBrightness = style.z; - float bipolar = style.w; + bool bipolar = style.w > 0.5; float halfWidth = width * 0.5; float halfHeight = height * 0.5; float columnWidth = width / count; - float baseline = bipolar > 0.5 ? 0.0 : halfHeight; - float span = bipolar > 0.5 ? halfHeight : height; + float baseline = bipolar ? 0.0 : halfHeight; + float span = bipolar ? halfHeight : height; float2 local = scenePosition.xy; - float antialias = max(max(fwidth(local.x), fwidth(local.y)), 0.5); - - float density = 0.0; - float2 gradient = float2(0.0, 0.0); + float antialias = max(max(fwidth(local.x), fwidth(local.y)), MinimumAntialias); float firstReached = (local.x - radius + halfWidth) / columnWidth - 0.5; float lastReached = (local.x + radius + halfWidth) / columnWidth - 0.5; int first = (int)clamp(ceil(firstReached), 0.0, count - 1.0); int last = (int)clamp(floor(lastReached), -1.0, count - 1.0); + float density = 0.0; + float2 gradient = float2(0.0, 0.0); + [loop] for (int index = first; index <= last; index++) { float value = SpectrumLane(values[index >> 2], index & 3); - float reach = (bipolar > 0.5 ? value : abs(value)) * span; + float reach = (bipolar ? value : abs(value)) * span; float centreX = -halfWidth + (index + 0.5) * columnWidth; - float slide = abs(reach) > 0.0001 ? saturate((local.y - baseline) / -reach) : 0.0; - float2 delta = local - float2(centreX, baseline - slide * reach); + float along = abs(reach) > MinimumReach ? saturate((local.y - baseline) / -reach) : 0.0; + float2 delta = local - float2(centreX, baseline - along * reach); float ratio = length(delta) / radius; if (ratio >= 1.0) continue; - float shell = 1.0 - ratio * ratio; - density += shell * shell * shell; - gradient += delta * (-6.0 * shell * shell / (radius * radius)); + float falloff = 1.0 - ratio * ratio; + density += falloff * falloff * falloff; + gradient += delta * (-6.0 * falloff * falloff / (radius * radius)); } - float slope = max(length(gradient), 0.00001); + float slope = max(length(gradient), MinimumSlope); float signedDistance = (density - threshold) / slope; float body = saturate(signedDistance / antialias + 0.5); float rim = LineCoverage(abs(signedDistance), rimThickness * 0.5, antialias) * saturate(rimThickness / antialias);