3838#define USING_LIGHT_MULTI_COMPILE
3939#endif
4040
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+
4146#define SCALED_NORMAL v.normal
4247
4348
4651#define EMISSIVE_RGBM_SCALE 97.0
4752
4853// 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
5057// - 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))
5259
5360struct appdata_base {
5461 float4 vertex : POSITION ;
@@ -507,18 +514,20 @@ inline half3 DecodeLightmapRGBM (half4 data, half4 decodeInstructions)
507514}
508515
509516// Decodes doubleLDR encoded lightmaps.
510- inline half3 DecodeLightmapDoubleLDR ( fixed4 color )
517+ inline half3 DecodeLightmapDoubleLDR ( fixed4 color, half4 decodeInstructions )
511518{
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;
514521}
515522
516523inline half3 DecodeLightmap ( fixed4 color, half4 decodeInstructions)
517524{
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;
522531#endif
523532}
524533
@@ -741,6 +750,7 @@ float2 MultiplyUV (float4x4 mat, float2 inUV) {
741750v2f_img vert_img ( appdata_img v )
742751{
743752 v2f_img o;
753+ UNITY_INITIALIZE_OUTPUT (v2f_img, o);
744754 UNITY_SETUP_INSTANCE_ID (v);
745755 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO (o);
746756
@@ -786,7 +796,13 @@ inline float4 ComputeGrabScreenPos (float4 pos) {
786796inline float4 UnityPixelSnap (float4 pos)
787797{
788798 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
789804 float2 pixelPos = round ((pos.xy / pos.w) * hpc);
805+ #endif
790806 pos.xy = pixelPos / hpc * pos.w;
791807 return pos;
792808}
@@ -855,9 +871,15 @@ float4 UnityClipSpaceShadowCasterPos(float3 vertex, float3 normal)
855871float4 UnityApplyLinearShadowBias (float4 clipPos)
856872{
857873#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))
858879 // We use max/min instead of clamp to ensure proper handling of the rare case
859880 // where both numerator and denominator are zero and the fraction becomes NaN.
860881 clipPos.z += max (-1 , min (unity_LightShadowBias.x / clipPos.w, 0 ));
882+ # endif
861883 float clamped = min (clipPos.z, clipPos.w*UNITY_NEAR_CLIP_VALUE);
862884#else
863885 clipPos.z += saturate (unity_LightShadowBias.x/clipPos.w);
@@ -868,12 +890,13 @@ float4 UnityApplyLinearShadowBias(float4 clipPos)
868890}
869891
870892
871- #ifdef SHADOWS_CUBE
893+ #if defined ( SHADOWS_CUBE) && ! defined (SHADOWS_CUBE_IN_DEPTH_TEX)
872894 // Rendering into point light (cubemap) shadows
873895 #define V2F_SHADOW_CASTER_NOPOS float3 vec : TEXCOORD0 ;
874896 #define TRANSFER_SHADOW_CASTER_NOPOS_LEGACY (o,opos) o.vec = mul (unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz; opos = UnityObjectToClipPos (v.vertex);
875897 #define TRANSFER_SHADOW_CASTER_NOPOS (o,opos) o.vec = mul (unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz; opos = UnityObjectToClipPos (v.vertex);
876898 #define SHADOW_CASTER_FRAGMENT (i) return UnityEncodeCubeShadowDepth ((length (i.vec) + unity_LightShadowBias.x) * _LightPositionRange.w);
899+
877900#else
878901 // Rendering into directional or spot light shadows
879902 #define V2F_SHADOW_CASTER_NOPOS
0 commit comments