mirror of
https://github.com/DeMuenu/MoonlightVRC.git
synced 2025-12-12 19:13:56 +00:00
Add support for multiple shadowcaster planes
Extended ShadowcasterUpdater and shaders to handle multiple shadowcaster planes by introducing indexed properties and logic for two shadowcaster sets. Updated property names and shader logic to support per-index shadowcaster textures, colors, and brightness, enabling more flexible shadow casting in scenes.
This commit is contained in:
@@ -9,15 +9,36 @@ public class ShadowcasterUpdater : UdonSharpBehaviour
|
||||
{
|
||||
|
||||
public Renderer[] rendererTargets;
|
||||
public Texture2D ShadowcasterTexture;
|
||||
public Color OutsideColor = Color.white;
|
||||
public Color TextureColor = Color.white;
|
||||
public float MinBrightness = 0.0f;
|
||||
|
||||
public int shadowcasterIndex = 1;
|
||||
|
||||
public string propertyName = "_Udon_WorldToLocal";
|
||||
private MaterialPropertyBlock _mpb;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
_mpb = new MaterialPropertyBlock();
|
||||
ApplyTextureData();
|
||||
}
|
||||
|
||||
|
||||
public void ApplyTextureData()
|
||||
{
|
||||
foreach (Renderer mat in rendererTargets)
|
||||
{
|
||||
if (mat == null) continue;
|
||||
mat.GetPropertyBlock(_mpb);
|
||||
_mpb.SetTexture("_Udon_ShadowcasterTex" + "_" + (string)shadowcasterIndex, ShadowcasterTexture);
|
||||
_mpb.SetColor("_Udon_shadowCasterColor" + "_" + (string)shadowcasterIndex, TextureColor);
|
||||
_mpb.SetColor("_Udon_OutSideColor" + "_" + (string)shadowcasterIndex, OutsideColor);
|
||||
_mpb.SetFloat("_Udon_MinBrightnessShadow" + "_" + (string)shadowcasterIndex, MinBrightness);
|
||||
mat.SetPropertyBlock(_mpb);
|
||||
}
|
||||
}
|
||||
void LateUpdate()
|
||||
{
|
||||
var w2l = transform.worldToLocalMatrix;
|
||||
@@ -27,7 +48,7 @@ public class ShadowcasterUpdater : UdonSharpBehaviour
|
||||
{
|
||||
if (mat == null) continue;
|
||||
mat.GetPropertyBlock(_mpb);
|
||||
_mpb.SetMatrix(propertyName, w2l);
|
||||
_mpb.SetMatrix(propertyName + "_" + (string)shadowcasterIndex, w2l);
|
||||
mat.SetPropertyBlock(_mpb);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,17 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
|
||||
MoonlightGlobalVariables
|
||||
|
||||
float4x4 _Udon_WorldToLocal_1;
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4x4 _Udon_WorldToLocal_2;
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
@@ -148,15 +159,22 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
|
||||
LightTypeCalculations(_Udon_LightColors, LightCounter, i, NdotL, dIntensity, _Udon_LightPositions[LightCounter].a, _Udon_LightPositions[LightCounter].xyz);
|
||||
|
||||
float4 ShadowCasterMult = float4(1,1,1,1);
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 0.5) {
|
||||
ShadowCasterMult = SampleShadowcasterPlane(_Udon_WorldToLocal, _shadowCasterTex, _Udon_LightPositions[LightCounter].xyz, i.worldPos, _OutSideColor);
|
||||
ShadowCasterMult *= _shadowCasterColor;
|
||||
ShadowCasterMult = float4(ShadowCasterMult.rgb * (1-ShadowCasterMult.a), 1);
|
||||
float4 ShadowCasterMult_1 = float4(1,1,1,1);
|
||||
float4 ShadowCasterMult_2 = float4(1,1,1,1);
|
||||
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5)) {
|
||||
ShadowCasterMult_1 = SampleShadowcasterPlane(_Udon_WorldToLocal_1, _Udon_shadowCasterTex_1, _Udon_LightPositions[LightCounter].xyz, i.worldPos, _Udon_OutSideColor_1);
|
||||
ShadowCasterMult_1 *= _Udon_shadowCasterColor_1;
|
||||
ShadowCasterMult_1 = float4(ShadowCasterMult_1.rgb * (1-ShadowCasterMult_1.a), 1);
|
||||
ShadowCasterMult_1 = max(ShadowCasterMult_1, _Udon_MinBrightnessShadow_1)
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5) {
|
||||
ShadowCasterMult_2 = SampleShadowcasterPlane(_Udon_WorldToLocal_2, _Udon_shadowCasterTex_2, _Udon_LightPositions[LightCounter].xyz, i.worldPos, _Udon_OutSideColor_2);
|
||||
ShadowCasterMult_2 *= _Udon_shadowCasterColor_2;
|
||||
ShadowCasterMult_2 = float4(ShadowCasterMult_2.rgb * (1-ShadowCasterMult_2.a), 1);
|
||||
ShadowCasterMult_2 = max(ShadowCasterMult_2, _Udon_MinBrightnessShadow_2)
|
||||
}
|
||||
|
||||
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * NdotL * max(ShadowCasterMult, _MinBrightnessShadow);
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * ShadowCasterMult_1 * ShadowCasterMult_2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,4 @@
|
||||
float _Udon_ShadowMapIndex[MAX_LIGHTS];\
|
||||
float _Udon_PlayerCount; /* set via SetFloat */ \
|
||||
|
||||
|
||||
float4x4 _Udon_WorldToLocal; \
|
||||
sampler2D _shadowCasterTex; \
|
||||
float4 _shadowCasterColor; \
|
||||
float4 _OutSideColor; \
|
||||
float _MinBrightnessShadow; \
|
||||
|
||||
|
||||
#endif
|
||||
@@ -85,6 +85,17 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
||||
|
||||
MoonlightGlobalVariables
|
||||
|
||||
float4x4 _Udon_WorldToLocal_1;
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4x4 _Udon_WorldToLocal_2;
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
@@ -121,18 +132,25 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
||||
|
||||
InLoopSetup(_Udon_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
Lambert(_Udon_LightPositions[LightCounter].xyz ,i, N); //defines NdotL
|
||||
|
||||
LightTypeCalculations(_Udon_LightColors, LightCounter, i, NdotL, dIntensity, _Udon_LightPositions[LightCounter].a, _Udon_LightPositions[LightCounter].xyz);
|
||||
LightTypeCalculations(_Udon_LightColors, LightCounter, i, 1, dIntensity, _Udon_LightPositions[LightCounter].a, _Udon_LightPositions[LightCounter].xyz);
|
||||
|
||||
float4 ShadowCasterMult = float4(1,1,1,1);
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 0.5) {
|
||||
ShadowCasterMult = SampleShadowcasterPlane(_Udon_WorldToLocal, _shadowCasterTex, _Udon_LightPositions[LightCounter].xyz, i.worldPos, _OutSideColor);
|
||||
ShadowCasterMult *= _shadowCasterColor;
|
||||
ShadowCasterMult = float4(ShadowCasterMult.rgb * (1-ShadowCasterMult.a), 1);
|
||||
float4 ShadowCasterMult_1 = float4(1,1,1,1);
|
||||
float4 ShadowCasterMult_2 = float4(1,1,1,1);
|
||||
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5)) {
|
||||
ShadowCasterMult_1 = SampleShadowcasterPlane(_Udon_WorldToLocal_1, _Udon_shadowCasterTex_1, _Udon_LightPositions[LightCounter].xyz, i.worldPos, _Udon_OutSideColor_1);
|
||||
ShadowCasterMult_1 *= _Udon_shadowCasterColor_1;
|
||||
ShadowCasterMult_1 = float4(ShadowCasterMult_1.rgb * (1-ShadowCasterMult_1.a), 1);
|
||||
ShadowCasterMult_1 = max(ShadowCasterMult_1, _Udon_MinBrightnessShadow_1)
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5) {
|
||||
ShadowCasterMult_2 = SampleShadowcasterPlane(_Udon_WorldToLocal_2, _Udon_shadowCasterTex_2, _Udon_LightPositions[LightCounter].xyz, i.worldPos, _Udon_OutSideColor_2);
|
||||
ShadowCasterMult_2 *= _Udon_shadowCasterColor_2;
|
||||
ShadowCasterMult_2 = float4(ShadowCasterMult_2.rgb * (1-ShadowCasterMult_2.a), 1);
|
||||
ShadowCasterMult_2 = max(ShadowCasterMult_2, _Udon_MinBrightnessShadow_2)
|
||||
}
|
||||
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * 1 * max(ShadowCasterMult, _MinBrightnessShadow);
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * ShadowCasterMult1 * ShadowCasterMult_2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user