mirror of
https://github.com/DeMuenu/MoonlightVRC.git
synced 2025-12-12 19:13:56 +00:00
Add shadow casting toggle to shaders
Introduced an _EnableShadowCasting property to BlendinShader, LitParticles, and Water shaders, allowing shadow casting to be enabled or disabled via a material parameter. Updated shadow sampling logic to respect this toggle, and added related parameters and includes where necessary. Also added a Cull Mode property to BlendinShader for improved rendering control.
This commit is contained in:
@@ -16,9 +16,11 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
|||||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||||
|
|
||||||
|
_EnableShadowCasting ("Enable Shadowcasting", Float) = 0
|
||||||
_BlurPixels ("Shadowcaster Blur Pixels", Float) = 0
|
_BlurPixels ("Shadowcaster Blur Pixels", Float) = 0
|
||||||
//Moonlight END
|
//Moonlight END
|
||||||
|
|
||||||
|
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull Mode", Float) = 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
|||||||
{
|
{
|
||||||
Tags { "RenderType"="Opaque" }
|
Tags { "RenderType"="Opaque" }
|
||||||
LOD 100
|
LOD 100
|
||||||
|
Cull[_Cull]
|
||||||
|
|
||||||
Pass
|
Pass
|
||||||
{
|
{
|
||||||
@@ -113,6 +116,8 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
|||||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||||
|
|
||||||
|
bool _EnableShadowCasting;
|
||||||
|
|
||||||
v2f vert (appdata v)
|
v2f vert (appdata v)
|
||||||
{
|
{
|
||||||
v2f o;
|
v2f o;
|
||||||
@@ -171,7 +176,7 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
|||||||
float4 ShadowCasterMult_1 = 1;
|
float4 ShadowCasterMult_1 = 1;
|
||||||
float4 ShadowCasterMult_2 = 1;
|
float4 ShadowCasterMult_2 = 1;
|
||||||
|
|
||||||
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5))
|
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5) && (_EnableShadowCasting > 0.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5 && _EnableShadowCasting))
|
||||||
{
|
{
|
||||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||||
@@ -179,7 +184,7 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
|||||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||||
}
|
}
|
||||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5)
|
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5))
|
||||||
{
|
{
|
||||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
|||||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||||
|
|
||||||
|
_EnableShadowCasting ("Enable Shadowcasting", Float) = 0
|
||||||
_BlurPixels ("Shadowcaster Blur Pixels", Float) = 0
|
_BlurPixels ("Shadowcaster Blur Pixels", Float) = 0
|
||||||
//Moonlight END
|
//Moonlight END
|
||||||
|
|
||||||
@@ -106,6 +106,8 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
|||||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||||
|
|
||||||
|
bool _EnableShadowCasting;
|
||||||
|
|
||||||
v2f vert (appdata v)
|
v2f vert (appdata v)
|
||||||
{
|
{
|
||||||
v2f o;
|
v2f o;
|
||||||
@@ -147,7 +149,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
|||||||
float4 ShadowCasterMult_1 = 1;
|
float4 ShadowCasterMult_1 = 1;
|
||||||
float4 ShadowCasterMult_2 = 1;
|
float4 ShadowCasterMult_2 = 1;
|
||||||
|
|
||||||
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5))
|
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5) && (_EnableShadowCasting > 0.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5 && _EnableShadowCasting))
|
||||||
{
|
{
|
||||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||||
@@ -155,8 +157,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
|||||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||||
}
|
}
|
||||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5)
|
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5)) {
|
||||||
{
|
|
||||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ Shader "DeMuenu/World/Hoppou/Water"
|
|||||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||||
|
|
||||||
|
_EnableShadowCasting ("Enable Shadowcasting", Float) = 0
|
||||||
|
_BlurPixels ("Shadowcaster Blur Pixels", Float) = 0
|
||||||
|
//Moonlight END
|
||||||
|
|
||||||
_SpecPower ("Spec Power", Range(4,256)) = 64
|
_SpecPower ("Spec Power", Range(4,256)) = 64
|
||||||
_SpecIntensity ("Spec Intensity", Range(0,10)) = 1
|
_SpecIntensity ("Spec Intensity", Range(0,10)) = 1
|
||||||
_AmbientFloor ("Ambient Floor", Range(0,1)) = 0.08
|
_AmbientFloor ("Ambient Floor", Range(0,1)) = 0.08
|
||||||
@@ -24,7 +28,6 @@ Shader "DeMuenu/World/Hoppou/Water"
|
|||||||
_F0 ("F0", Range(0,1)) = 0.02
|
_F0 ("F0", Range(0,1)) = 0.02
|
||||||
_FresnelPower ("Fresnel Power", Range(1,8)) = 5
|
_FresnelPower ("Fresnel Power", Range(1,8)) = 5
|
||||||
_ReflectionStrength ("Reflection Strength", Range(0,1)) = 0.7
|
_ReflectionStrength ("Reflection Strength", Range(0,1)) = 0.7
|
||||||
//Moonlight END
|
|
||||||
|
|
||||||
_WaveInput ("Wave Input", 2D) = "black" {}
|
_WaveInput ("Wave Input", 2D) = "black" {}
|
||||||
_CameraScale ("Camera Scale", Float) = 15
|
_CameraScale ("Camera Scale", Float) = 15
|
||||||
@@ -51,6 +54,7 @@ Shader "DeMuenu/World/Hoppou/Water"
|
|||||||
#include "Includes/Lambert.hlsl"
|
#include "Includes/Lambert.hlsl"
|
||||||
#include "Includes/DefaultSetup.hlsl"
|
#include "Includes/DefaultSetup.hlsl"
|
||||||
#include "Includes/Variables.hlsl"
|
#include "Includes/Variables.hlsl"
|
||||||
|
#include "Includes/Shadowcaster.cginc"
|
||||||
|
|
||||||
//Moonlight Defines
|
//Moonlight Defines
|
||||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||||
@@ -94,6 +98,33 @@ Shader "DeMuenu/World/Hoppou/Water"
|
|||||||
|
|
||||||
MoonlightGlobalVariables
|
MoonlightGlobalVariables
|
||||||
|
|
||||||
|
float4 _Udon_Plane_Origin_1; // xyz = origin (world), w unused
|
||||||
|
float4 _Udon_Plane_Uinv_1; // xyz = Udir / (2*halfWidth)
|
||||||
|
float4 _Udon_Plane_Vinv_1; // xyz = Vdir / (2*halfHeight)
|
||||||
|
float4 _Udon_Plane_Normal_1; // xyz = unit normal
|
||||||
|
|
||||||
|
sampler2D _Udon_shadowCasterTex_1;
|
||||||
|
float4 _Udon_shadowCasterColor_1;
|
||||||
|
float4 _Udon_OutSideColor_1;
|
||||||
|
float _Udon_MinBrightnessShadow_1;
|
||||||
|
|
||||||
|
float4 _Udon_Plane_Origin_2;
|
||||||
|
float4 _Udon_Plane_Uinv_2;
|
||||||
|
float4 _Udon_Plane_Vinv_2;
|
||||||
|
float4 _Udon_Plane_Normal_2;
|
||||||
|
|
||||||
|
sampler2D _Udon_shadowCasterTex_2;
|
||||||
|
float4 _Udon_shadowCasterColor_2;
|
||||||
|
float4 _Udon_OutSideColor_2;
|
||||||
|
float _Udon_MinBrightnessShadow_2;
|
||||||
|
|
||||||
|
float _BlurPixels;
|
||||||
|
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||||
|
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||||
|
|
||||||
|
bool _EnableShadowCasting;
|
||||||
|
|
||||||
|
|
||||||
//Watershader specific
|
//Watershader specific
|
||||||
float _SpecPower, _SpecIntensity;
|
float _SpecPower, _SpecIntensity;
|
||||||
float3 _AmbientFloor;
|
float3 _AmbientFloor;
|
||||||
@@ -185,13 +216,30 @@ Shader "DeMuenu/World/Hoppou/Water"
|
|||||||
|
|
||||||
LightTypeCalculations(_Udon_LightColors, LightCounter, i, 1, 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_1 = 1;
|
||||||
|
float4 ShadowCasterMult_2 = 1;
|
||||||
|
|
||||||
|
if (((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5) && (_EnableShadowCasting > 0.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5 && _EnableShadowCasting))
|
||||||
|
{
|
||||||
|
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||||
|
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||||
|
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||||
|
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||||
|
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||||
|
}
|
||||||
|
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5)) {
|
||||||
|
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||||
|
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||||
|
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||||
|
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||||
|
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||||
|
}
|
||||||
|
|
||||||
//Watershader specific
|
//Watershader specific
|
||||||
//float fres = Schlick(saturate(dot(N, V)), _F0, _FresnelPower);
|
//float fres = Schlick(saturate(dot(N, V)), _F0, _FresnelPower);
|
||||||
float spec = pow(saturate(dot(R, L)), _SpecPower);
|
float spec = pow(saturate(dot(R, L)), _SpecPower);
|
||||||
//return float4(spec, spec, spec,1);
|
//return float4(spec, spec, spec,1);
|
||||||
dmax.rgb += _Udon_LightColors[LightCounter].rgb * contrib + _Udon_LightColors[LightCounter].rgb * _SpecIntensity * spec * contrib;
|
dmax.rgb += _Udon_LightColors[LightCounter].rgb * contrib * ShadowCasterMult_1 * ShadowCasterMult_2 + _Udon_LightColors[LightCounter].rgb * _SpecIntensity * spec * contrib * ShadowCasterMult_1 * ShadowCasterMult_2;
|
||||||
dmax.a -= _SpecIntensity * spec;
|
dmax.a -= _SpecIntensity * spec;
|
||||||
//dmax = dmax + contrib * float4(LightColor, 1); // accumulate light contributions
|
//dmax = dmax + contrib * float4(LightColor, 1); // accumulate light contributions
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user