38
38
#define USING_LIGHT_MULTI_COMPILE
39
39
#endif
40
40
41
+ #if (defined (SHADER_API_D3D11) && !defined (SHADER_API_XBOXONE))
42
+ // Real-support for depth-format cube shadow map.
43
+ #define SHADOWS_CUBE_IN_DEPTH_TEX
44
+ #endif
45
+
41
46
#define SCALED_NORMAL v.normal
42
47
43
48
46
51
#define EMISSIVE_RGBM_SCALE 97.0
47
52
48
53
// Should SH (light probe / ambient) calculations be performed?
49
- // - Presence of *either* of static or dynamic lightmaps means that diffuse indirect ambient is already in them, so no need for SH.
54
+ // - When both static and dynamic lightmaps are available, no SH evaluation is performed
55
+ // - When static and dynamic lightmaps are not available, SH evaluation is always performed
56
+ // - For low level LODs, static lightmap and real-time GI from light probes can be combined together
50
57
// - Passes that don't do ambient (additive, shadowcaster etc.) should not do SH either.
51
- #define UNITY_SHOULD_SAMPLE_SH (! defined (LIGHTMAP_ON) && ! defined (DYNAMICLIGHTMAP_ON ) && !defined (UNITY_PASS_FORWARDADD) && !defined (UNITY_PASS_PREPASSBASE) && !defined (UNITY_PASS_SHADOWCASTER) && !defined (UNITY_PASS_META))
58
+ #define UNITY_SHOULD_SAMPLE_SH (defined (LIGHTPROBE_SH ) && !defined (UNITY_PASS_FORWARDADD) && !defined (UNITY_PASS_PREPASSBASE) && !defined (UNITY_PASS_SHADOWCASTER) && !defined (UNITY_PASS_META))
52
59
53
60
struct appdata_base {
54
61
float4 vertex : POSITION ;
@@ -507,18 +514,20 @@ inline half3 DecodeLightmapRGBM (half4 data, half4 decodeInstructions)
507
514
}
508
515
509
516
// Decodes doubleLDR encoded lightmaps.
510
- inline half3 DecodeLightmapDoubleLDR ( fixed4 color )
517
+ inline half3 DecodeLightmapDoubleLDR ( fixed4 color, half4 decodeInstructions )
511
518
{
512
- float multiplier = IsGammaSpace () ? 2.0f : GammaToLinearSpace (2.0f ).x;
513
- return multiplier * color.rgb;
519
+ // decodeInstructions.x contains 2.0 when gamma color space is used or pow (2.0, 2.2) = 4.59 when linear color space is used on mobile platforms
520
+ return decodeInstructions.x * color.rgb;
514
521
}
515
522
516
523
inline half3 DecodeLightmap ( fixed4 color, half4 decodeInstructions)
517
524
{
518
- #if defined (UNITY_NO_RGBM)
519
- return DecodeLightmapDoubleLDR ( color );
520
- #else
521
- return DecodeLightmapRGBM ( color, decodeInstructions );
525
+ #if defined (UNITY_LIGHTMAP_DLDR_ENCODING)
526
+ return DecodeLightmapDoubleLDR (color, decodeInstructions);
527
+ #elif defined (UNITY_LIGHTMAP_RGBM_ENCODING)
528
+ return DecodeLightmapRGBM (color, decodeInstructions);
529
+ #else //defined(UNITY_LIGHTMAP_FULL_HDR)
530
+ return color.rgb;
522
531
#endif
523
532
}
524
533
@@ -741,6 +750,7 @@ float2 MultiplyUV (float4x4 mat, float2 inUV) {
741
750
v2f_img vert_img ( appdata_img v )
742
751
{
743
752
v2f_img o;
753
+ UNITY_INITIALIZE_OUTPUT (v2f_img, o);
744
754
UNITY_SETUP_INSTANCE_ID (v);
745
755
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO (o);
746
756
@@ -786,7 +796,13 @@ inline float4 ComputeGrabScreenPos (float4 pos) {
786
796
inline float4 UnityPixelSnap (float4 pos)
787
797
{
788
798
float2 hpc = _ScreenParams.xy * 0.5f ;
799
+ #if SHADER_API_PSSL
800
+ // sdk 4.5 splits round into v_floor_f32(x+0.5) ... sdk 5.0 uses v_rndne_f32, for compatabilty we use the 4.5 version
801
+ float2 temp = ((pos.xy / pos.w) * hpc) + float2 (0.5f ,0.5f );
802
+ float2 pixelPos = float2 (__v_floor_f32 (temp.x), __v_floor_f32 (temp.y));
803
+ #else
789
804
float2 pixelPos = round ((pos.xy / pos.w) * hpc);
805
+ #endif
790
806
pos.xy = pixelPos / hpc * pos.w;
791
807
return pos;
792
808
}
@@ -855,9 +871,15 @@ float4 UnityClipSpaceShadowCasterPos(float3 vertex, float3 normal)
855
871
float4 UnityApplyLinearShadowBias (float4 clipPos)
856
872
{
857
873
#if defined (UNITY_REVERSED_Z)
874
+
875
+ // For point lights that support depth cube map, the bias is applied in the fragment shader sampling the shadow map.
876
+ // This is because the legacy behaviour for point light shadow map cannot be implemented by offseting the vertex position
877
+ // in the vertex shader generating the shadow map.
878
+ # if !(defined (SHADOWS_CUBE) && defined (SHADOWS_CUBE_IN_DEPTH_TEX))
858
879
// We use max/min instead of clamp to ensure proper handling of the rare case
859
880
// where both numerator and denominator are zero and the fraction becomes NaN.
860
881
clipPos.z += max (-1 , min (unity_LightShadowBias.x / clipPos.w, 0 ));
882
+ # endif
861
883
float clamped = min (clipPos.z, clipPos.w*UNITY_NEAR_CLIP_VALUE);
862
884
#else
863
885
clipPos.z += saturate (unity_LightShadowBias.x/clipPos.w);
@@ -868,12 +890,13 @@ float4 UnityApplyLinearShadowBias(float4 clipPos)
868
890
}
869
891
870
892
871
- #ifdef SHADOWS_CUBE
893
+ #if defined ( SHADOWS_CUBE) && ! defined (SHADOWS_CUBE_IN_DEPTH_TEX)
872
894
// Rendering into point light (cubemap) shadows
873
895
#define V2F_SHADOW_CASTER_NOPOS float3 vec : TEXCOORD0 ;
874
896
#define TRANSFER_SHADOW_CASTER_NOPOS_LEGACY (o,opos) o.vec = mul (unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz; opos = UnityObjectToClipPos (v.vertex);
875
897
#define TRANSFER_SHADOW_CASTER_NOPOS (o,opos) o.vec = mul (unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz; opos = UnityObjectToClipPos (v.vertex);
876
898
#define SHADOW_CASTER_FRAGMENT (i) return UnityEncodeCubeShadowDepth ((length (i.vec) + unity_LightShadowBias.x) * _LightPositionRange.w);
899
+
877
900
#else
878
901
// Rendering into directional or spot light shadows
879
902
#define V2F_SHADOW_CASTER_NOPOS
0 commit comments