From c7e2397d81ef3c393838b20997d866aa771eba0e Mon Sep 17 00:00:00 2001 From: DeMuenu <96650288+DeMuenu@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:31:00 +0200 Subject: [PATCH 1/2] Update shader property handling for VRCShader API Changed shader property names to use '_Udon_' prefix and switched to using VRCShader.PropertyToID and VRCShader.SetGlobal* methods for setting shader properties. Added update throttling in LateUpdate for performance. These changes improve compatibility and efficiency with the VRC SDK3 Rendering API. --- Scripts/PlayerPositionsToShader.cs | 42 +++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Scripts/PlayerPositionsToShader.cs b/Scripts/PlayerPositionsToShader.cs index db1000f..35ad3f1 100644 --- a/Scripts/PlayerPositionsToShader.cs +++ b/Scripts/PlayerPositionsToShader.cs @@ -4,6 +4,7 @@ using Unity.Mathematics; using UnityEngine; using VRC.SDKBase; using VRC.Udon; +using VRC.SDK3.Rendering; public partial class PlayerPositionsToShader : UdonSharpBehaviour { @@ -28,19 +29,19 @@ public partial class PlayerPositionsToShader : UdonSharpBehaviour [Header("Shader property names (advanced users)")] [Tooltip("Vector4 array: xyz = position, w = range")] - public string positionsProperty = "_PlayerPositions"; + public string positionsProperty = "_Udon_PlayerPositions"; [Tooltip("Actual array count")] - public string countProperty = "_PlayerCount"; + public string countProperty = "_Udon_PlayerCount"; [Tooltip("RGBA array: rgb = color, a = intensity")] - public string colorProperty = "_LightColors"; + public string colorProperty = "_Udon_LightColors"; [Tooltip("Vector4 array: xyz = direction, w = spot in degrees")] - public string directionsProperty = "_LightDirections"; + public string directionsProperty = "_Udon_LightDirections"; [Tooltip("float array: light type (1=area, 2=cone, etc)")] - public string typeProperty = "_LightType"; + public string typeProperty = "_Udon_LightType"; [Header("Max Lights (advanced users)")] [Tooltip("Hard cap / array size. 80 = default cap")] @@ -64,6 +65,14 @@ public partial class PlayerPositionsToShader : UdonSharpBehaviour public int currentCount { get; private set; } + private float _nextUpdate = 0f; + + private static readonly int UdonID_PlayerPositions; + private static readonly int UdonID_LightCount; + private static readonly int UdonID_LightColors; + private static readonly int UdonID_LightDirections; + private static readonly int UdonID_LightType; + void Start() { if (maxLights < 1) maxLights = 1; @@ -76,12 +85,22 @@ public partial class PlayerPositionsToShader : UdonSharpBehaviour _players = new VRCPlayerApi[maxLights]; _mpb = new MaterialPropertyBlock(); + UdonID_PlayerPositions = VRCShader.PropertyToID(positionsProperty); + UdonID_LightCount = VRCShader.PropertyToID(countProperty); + UdonID_LightColors = VRCShader.PropertyToID(colorProperty); + UdonID_LightDirections = VRCShader.PropertyToID(directionsProperty); + UdonID_LightType = VRCShader.PropertyToID(typeProperty); + + UpdateData(); PushToRenderers(); } void LateUpdate() { + if (Time.time < _nextUpdate) return; + _nextUpdate = Time.time + 0.05f; + UpdateData(); PushToRenderers(); } @@ -260,15 +279,12 @@ public partial class PlayerPositionsToShader : UdonSharpBehaviour Renderer rd = targets[r]; if (!Utilities.IsValid(rd)) continue; - rd.GetPropertyBlock(_mpb); + if (pushPositions) VRCShader.SetGlobalVectorArray(UdonID_PlayerPositions, _positions); + if (pushColors) VRCShader.SetGlobalVectorArray(UdonID_LightColors, _lightColors); + if (pushDirs) VRCShader.SetGlobalVectorArray(UdonID_LightDirections, _directions); + if (pushTypes) _mpb.SetFloatArray(UdonID_LightType, _TypeArray); - if (pushPositions) _mpb.SetVectorArray(positionsProperty, _positions); - if (pushColors) _mpb.SetVectorArray(colorProperty, _lightColors); - if (pushDirs) _mpb.SetVectorArray(directionsProperty, _directions); - if (pushTypes) _mpb.SetFloatArray(typeProperty, _TypeArray); - - _mpb.SetFloat(countProperty, currentCount); - rd.SetPropertyBlock(_mpb); + VRCShader.SetGlobalFloat(UdonID_LightCount, currentCount); } // Only now mark them clean From e5f18d74641fd2a3c80a97994ecf3963a85807d5 Mon Sep 17 00:00:00 2001 From: DeMuenu <96650288+DeMuenu@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:56:36 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d28b748..2457c8b 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ On PC, I haven't encountered any frame drops in the editor at all, even with 400 3. For lights, attach `LightdataStorage` to a Transform and configure: - `range`, `type`, `color`, `intensity`, and `spotAngleDeg`. -4. Use the provided shader include `Shader/MoonsLight.cginc` in your CGPROGRAM blocks to consume the arrays and compute lighting. +4. Use one of the premade shaders on your objects. Or if you feel like it, use the provided .hlsl in your own shader. You just need to copy everything surrounded by Moonlight comments, and applying it at the end of your shader. ---