From bb31145e4d1b6ae464e3d0558245b14260679cef Mon Sep 17 00:00:00 2001 From: DeMuenu <96650288+DeMuenu@users.noreply.github.com> Date: Fri, 3 Oct 2025 23:27:27 +0200 Subject: [PATCH] smooth falloff, but not correct angles Replaced usage of GetCosHalfAngle() with spotAngleDeg for spot light calculations in both editor and runtime scripts. Updated shader logic to use smoothstep for light contribution falloff, improving spot light edge smoothness. --- EditorPreview/LightUpdater.Editor.cs | 2 +- Scripts/LightUpdater.cs | 4 ++-- Shader/Includes/LightStrength.hlsl | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/EditorPreview/LightUpdater.Editor.cs b/EditorPreview/LightUpdater.Editor.cs index 9dc7024..41543d8 100644 --- a/EditorPreview/LightUpdater.Editor.cs +++ b/EditorPreview/LightUpdater.Editor.cs @@ -38,7 +38,7 @@ public partial class LightUpdater float intensity = (data != null) ? data.intensity * t.localScale.x : 1f; // w = cosHalfAngle (0 for omni) - float cosHalf = (data != null) ? data.GetCosHalfAngle() : 0f; + float cosHalf = (data != null) ? data.spotAngleDeg : 0f; // 0=Omni, 1=Spot, 2=Directional (your custom enum) int typeId = (data != null) ? data.GetTypeId() : 0; diff --git a/Scripts/LightUpdater.cs b/Scripts/LightUpdater.cs index b9ad5be..372a024 100644 --- a/Scripts/LightUpdater.cs +++ b/Scripts/LightUpdater.cs @@ -221,7 +221,7 @@ public partial class LightUpdater : UdonSharpBehaviour Vector3 fwd = rot * Vector3.down; - float cosHalf = (data != null) ? data.GetCosHalfAngle() : 0f; + float Lightangle = (data != null) ? data.spotAngleDeg : 0f; Vector4 posTemp = new Vector4(pos.x, pos.y, pos.z, range); if (_positions[currentCount] != posTemp) @@ -235,7 +235,7 @@ public partial class LightUpdater : UdonSharpBehaviour _lightColors[currentCount] = colorTemp; _lightColors_isDirty = true; } - Vector4 dirTemp = new Vector4(fwd.x, fwd.y, fwd.z, cosHalf); + Vector4 dirTemp = new Vector4(fwd.x, fwd.y, fwd.z, Lightangle); if (_directions[currentCount] != dirTemp) { _directions[currentCount] = dirTemp; diff --git a/Shader/Includes/LightStrength.hlsl b/Shader/Includes/LightStrength.hlsl index d9119d0..d858403 100644 --- a/Shader/Includes/LightStrength.hlsl +++ b/Shader/Includes/LightStrength.hlsl @@ -14,7 +14,7 @@ float threshold = (-1 + _Udon_LightDirections[LightCounter].w / 180); \ \ contrib = min(dot(normalize(i.worldPos - Lightposition), -normalize(_Udon_LightDirections[LightCounter].xyz)), 0); \ - contrib= 1 - step(threshold, contrib); \ + contrib= 1 - smoothstep(threshold, threshold + radius / 180, contrib); \ \ contrib = contrib * invSq; \ dIntensity += contrib; \