Skip to content

Commit

Permalink
fix ShadowCaster pass bug when using Metal or DX11.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Jan 7, 2018
1 parent bd260e9 commit d6ffd2d
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Properties
@if ShadowCaster : true
_ShadowLoop("Shadow Loop", Range(1, 100)) = 10
_ShadowMinDistance("Shadow Minimum Distance", Range(0.001, 0.1)) = 0.01
_ShadowExtraBias("Shadow Extra Bias", Range(0.0, 1.0)) = 0.02
@endif

@block Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Properties
@if ShadowCaster : true
_ShadowLoop("Shadow Loop", Range(1, 100)) = 10
_ShadowMinDistance("Shadow Minimum Distance", Range(0.001, 0.1)) = 0.01
_ShadowExtraBias("Shadow Extra Bias", Range(0.0, 1.0)) = 0.02
@endif

@block Properties
Expand Down
Binary file modified Assets/uRaymarching/Examples/Materials/HexFloor.mat
Binary file not shown.
2 changes: 0 additions & 2 deletions Assets/uRaymarching/Examples/Shaders/HexFloor.shader
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Properties
_MinDistance("Minimum Distance", Range(0.001, 0.1)) = 0.01
_ShadowLoop("Shadow Loop", Range(1, 100)) = 10
_ShadowMinDistance("Shadow Minimum Distance", Range(0.001, 0.1)) = 0.01
_ShadowExtraBias("Shadow Extra Bias", Range(0.0, 1.0)) = 0.02

// @block Properties
[Header(Additional Properties)]
Expand Down Expand Up @@ -94,7 +93,6 @@ inline float DistanceFunction(float3 pos)
// combine
return min(d1, d2);
}

// @endblock

// @block PostEffect
Expand Down
1 change: 0 additions & 1 deletion Assets/uRaymarching/Examples/Shaders/SphereBoxMorph.shader
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Properties
_MinDistance("Minimum Distance", Range(0.001, 0.1)) = 0.01
_ShadowLoop("Shadow Loop", Range(1, 100)) = 10
_ShadowMinDistance("Shadow Minimum Distance", Range(0.001, 0.1)) = 0.01
_ShadowExtraBias("Shadow Extra Bias", Range(0.0, 1.0)) = 0.02

// @block Properties
// _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
Expand Down
5 changes: 5 additions & 0 deletions Assets/uRaymarching/Shaders/Include/Utils.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ inline float3 EncodeNormal(float3 normal)
return normal * 0.5 + 0.5;
}

inline float3 DecodeNormal(float3 normal)
{
return 2.0 * normal - 1.0;
}

inline bool IsInnerCube(float3 pos, float3 scale)
{
return all(max(scale * 0.5 - abs(pos), 0.0));
Expand Down
15 changes: 3 additions & 12 deletions Assets/uRaymarching/Shaders/Include/VertFragShadowObject.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@

float _ShadowMinDistance;
int _ShadowLoop;
float _ShadowExtraBias;

float4 ApplyLinearShadowBias(float4 clipPos)
{
clipPos.z += saturate((unity_LightShadowBias.x + _ShadowExtraBias) / clipPos.w);
float clamped = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
clipPos.z = lerp(clipPos.z, clamped, unity_LightShadowBias.y);
return clipPos;
}

VertShadowOutput Vert(VertShadowInput v)
{
VertShadowOutput o;
o.pos = UnityObjectToClipPos(v.vertex);
o.screenPos = o.pos;
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.normal = v.normal;
o.normal = mul(unity_ObjectToWorld, v.normal);
return o;
}

Expand Down Expand Up @@ -74,9 +65,9 @@ void Frag(
if (!_Raymarch(ray)) discard;

float4 opos = mul(unity_WorldToObject, float4(ray.endPos, 1.0));
float3 worldNormal = 2.0 * ray.normal - 1.0;
float3 worldNormal = DecodeNormal(ray.normal);
opos = UnityClipSpaceShadowCasterPos(opos, worldNormal);
opos = ApplyLinearShadowBias(opos);
opos = UnityApplyLinearShadowBias(opos);
outColor = outDepth = EncodeDepth(opos);
}

Expand Down
Binary file modified ProjectSettings/ProjectSettings.asset
Binary file not shown.

0 comments on commit d6ffd2d

Please sign in to comment.