Skip to content

Commit 8138da4

Browse files
committed
Added preprocessor version checking so that it now supports both 5.5 and 5.6
1 parent 0330d66 commit 8138da4

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Assets/PCSS/Shaders/PCSS.shader

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ struct appdata
2626
{
2727
float4 vertex : POSITION;
2828
float2 texcoord : TEXCOORD0;
29-
#ifdef UNITY_STEREO_INSTANCING_ENABLED
29+
#if (UNITY_VERSION < 560)
30+
float3 ray : NORMAL;
31+
#elif defined(UNITY_STEREO_INSTANCING_ENABLED)
3032
float3 ray[2] : TEXCOORD1;
3133
#else
3234
float3 ray : TEXCOORD1;
@@ -57,9 +59,11 @@ struct v2f
5759
v2f vert (appdata v)
5860
{
5961
v2f o;
62+
#if UNITY_VERSION >= 560
6063
UNITY_SETUP_INSTANCE_ID(v);
6164
UNITY_TRANSFER_INSTANCE_ID(v, o);
6265
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
66+
#endif
6367
float4 clipPos = UnityObjectToClipPos(v.vertex);
6468
o.pos = clipPos;
6569
o.uv.xy = v.texcoord;
@@ -68,7 +72,8 @@ v2f vert (appdata v)
6872
o.uv.zw = ComputeNonStereoScreenPos(clipPos);
6973

7074
// Perspective case
71-
#ifdef UNITY_STEREO_INSTANCING_ENABLED
75+
//Only do stero instancing in 5.6+
76+
#if (UNITY_VERSION >= 560) && defined(UNITY_STEREO_INSTANCING_ENABLED)
7277
o.ray = v.ray[unity_StereoEyeIndex];
7378
#else
7479
o.ray = v.ray;
@@ -93,7 +98,12 @@ v2f vert (appdata v)
9398
return o;
9499
}
95100

96-
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
101+
//changed in 5.6
102+
#if UNITY_VERSION >= 560
103+
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
104+
#else
105+
sampler2D_float _CameraDepthTexture;
106+
#endif
97107

98108
// sizes of cascade projections, relative to first one
99109
float4 unity_ShadowCascadeScales;
@@ -564,7 +574,10 @@ float PCSS_Main(float4 coords, float2 receiverPlaneDepthBias, float random)
564574
*/
565575
fixed4 frag_hard (v2f i) : SV_Target
566576
{
567-
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); // required for sampling the correct slice of the shadow map render texture array
577+
//only works in 5.6+
578+
#if UNITY_VERSION >= 560
579+
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); // required for sampling the correct slice of the shadow map render texture array
580+
#endif
568581

569582
float3 vpos = computeCameraSpacePosFromDepth(i);
570583

@@ -581,7 +594,10 @@ fixed4 frag_hard (v2f i) : SV_Target
581594
*/
582595
fixed4 frag_pcss (v2f i) : SV_Target
583596
{
597+
//only works in 5.6+
598+
#if UNITY_VERSION >= 560
584599
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); // required for sampling the correct slice of the shadow map render texture array
600+
#endif
585601

586602
float3 vpos = computeCameraSpacePosFromDepth(i);
587603

0 commit comments

Comments
 (0)