Skip to content

Commit

Permalink
fix shadow problem #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Jan 7, 2018
1 parent d6ffd2d commit 37b34e4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
Expand Up @@ -16,6 +16,7 @@ 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.01
@endif

@block Properties
Expand Down
Expand Up @@ -16,6 +16,7 @@ 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.01
@endif

@block Properties
Expand Down
Binary file modified Assets/uRaymarching/Examples/Scenes/Hex Floor.unity
Binary file not shown.
2 changes: 2 additions & 0 deletions Assets/uRaymarching/Examples/Shaders/HexFloor.shader
Expand Up @@ -13,6 +13,7 @@ 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.01

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

// @endblock

// @block PostEffect
Expand Down
1 change: 1 addition & 0 deletions Assets/uRaymarching/Examples/Shaders/SphereBoxMorph.shader
Expand Up @@ -13,6 +13,7 @@ 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.01

// @block Properties
// _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
Expand Down
16 changes: 15 additions & 1 deletion Assets/uRaymarching/Shaders/Include/VertFragShadowObject.cginc
Expand Up @@ -6,9 +6,23 @@
#include "./Raymarching.cginc"
#include "./Utils.cginc"

float _ShadowExtraBias;
float _ShadowMinDistance;
int _ShadowLoop;

float4 ApplyLinearShadowBias(float4 clipPos)
{
#if defined(UNITY_REVERSED_Z)
clipPos.z += max(-1.0, min((unity_LightShadowBias.x - _ShadowExtraBias) / clipPos.w, 0.0));
float clamped = min(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
#else
clipPos.z += saturate((unity_LightShadowBias.x + _ShadowExtraBias) / clipPos.w);
float clamped = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
#endif
clipPos.z = lerp(clipPos.z, clamped, unity_LightShadowBias.y);
return clipPos;
}

VertShadowOutput Vert(VertShadowInput v)
{
VertShadowOutput o;
Expand Down Expand Up @@ -67,7 +81,7 @@ void Frag(
float4 opos = mul(unity_WorldToObject, float4(ray.endPos, 1.0));
float3 worldNormal = DecodeNormal(ray.normal);
opos = UnityClipSpaceShadowCasterPos(opos, worldNormal);
opos = UnityApplyLinearShadowBias(opos);
opos = ApplyLinearShadowBias(opos);
outColor = outDepth = EncodeDepth(opos);
}

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

0 comments on commit 37b34e4

Please sign in to comment.