Skip to content
This repository was archived by the owner on Nov 14, 2021. It is now read-only.

Commit 6811982

Browse files
author
Joshua Ols
committed
Added Unity 2017.3 support.
1 parent ea66559 commit 6811982

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## 4.2.1
3+
## 4.3.0
44
### Shaders
5+
* Added Unity 2017.3 support.
56
* Moved "Legacy" and "Mods" into the "Alloy" folder as part of the transition to open-source.
67

78
### Integration

Shaders/Defaults/HairDefault_AlloyPM.png.meta

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shaders/Deferred/ReflectionProbe.cginc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ half4 aMainFragmentShader(
2727
d.worldPos = s.positionWorld;
2828
d.worldViewDir = s.viewDirWorld; // ???
2929
d.probeHDR[0] = unity_SpecCube0_HDR;
30+
d.boxMin[0].w = 1; // 1 in .w allow to disable blending in UnityGI_IndirectSpecular call since it doesn't work in Deferred
3031

3132
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
3233
d.probePosition[0] = unity_SpecCube0_ProbePosition;
3334
d.boxMin[0].xyz = unity_SpecCube0_BoxMin - float4(blendDistance,blendDistance,blendDistance,0);
34-
d.boxMin[0].w = 1; // 1 in .w allow to disable blending in UnityGI_IndirectSpecular call
3535
d.boxMax[0].xyz = unity_SpecCube0_BoxMax + float4(blendDistance,blendDistance,blendDistance,0);
3636
#endif
3737

Shaders/Unity/AutoLight.cginc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,16 @@ half UnityComputeForwardShadows(float2 lightmapUV, float3 worldPos, float4 scree
128128
# define UNITY_SHADOW_ATTENUATION(a, worldPos) UnityComputeForwardShadows(0, worldPos, a._ShadowCoord)
129129
# endif
130130
#else
131-
# define UNITY_SHADOW_COORDS(idx1) unityShadowCoord2 _ShadowCoord : TEXCOORD##idx1;
132131
# if defined(SHADOWS_SHADOWMASK)
132+
# define UNITY_SHADOW_COORDS(idx1) unityShadowCoord2 _ShadowCoord : TEXCOORD##idx1;
133133
# define UNITY_TRANSFER_SHADOW(a, coord) a._ShadowCoord = coord * unity_LightmapST.xy + unity_LightmapST.zw;
134134
# if (defined(SHADOWS_DEPTH) || defined(SHADOWS_SCREEN) || defined(SHADOWS_CUBE) || UNITY_LIGHT_PROBE_PROXY_VOLUME)
135135
# define UNITY_SHADOW_ATTENUATION(a, worldPos) UnityComputeForwardShadows(a._ShadowCoord, worldPos, 0)
136136
# else
137137
# define UNITY_SHADOW_ATTENUATION(a, worldPos) UnityComputeForwardShadows(a._ShadowCoord, 0, 0)
138138
# endif
139139
# else
140+
# define UNITY_SHADOW_COORDS(idx1) SHADOW_COORDS(idx1)
140141
# define UNITY_TRANSFER_SHADOW(a, coord)
141142
# if (defined(SHADOWS_DEPTH) || defined(SHADOWS_SCREEN) || defined(SHADOWS_CUBE))
142143
# define UNITY_SHADOW_ATTENUATION(a, worldPos) UnityComputeForwardShadows(0, worldPos, 0)

Shaders/Unity/UnityCG.cginc

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
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

@@ -46,9 +51,11 @@
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

5360
struct 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

516523
inline 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) {
741750
v2f_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) {
786796
inline 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)
855871
float4 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

Comments
 (0)