Skip to content

Commit

Permalink
added cascade property
Browse files Browse the repository at this point in the history
  • Loading branch information
Phunkyio committed Mar 9, 2019
1 parent 61a62a3 commit 93423d3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions phunky-shaders/shader-dev/barrier-projector.shader
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Derivative of https://www.youtube.com/watch?v=C6lGEgcHbWc
// added Cascading Speed property

Shader "Phunky/Barrier"
Shader "Phunky/Dev/Barrier"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (0,0,0,0)
_CascadeSpeed ("Cascade Speed", Int) = 5
}

SubShader
Expand Down Expand Up @@ -47,6 +49,7 @@ Shader "Phunky/Barrier"
float4 vertex : SV_POSITION;
float depth : DEPTH;
float3 normal : NORMAL;
float4 projPos : TEXCOORD04;
};

sampler2D _MainTex;
Expand All @@ -69,9 +72,10 @@ Shader "Phunky/Barrier"
return o;
}

// UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
//sampler2D _CameraDepthTexture;
fixed4 _Color;
float _CascadeSpeed;

float triWave(float t, float offset, float yOffset)
{
Expand All @@ -81,19 +85,20 @@ Shader "Phunky/Barrier"
fixed4 texColor(v2f i, float rim)
{
fixed4 mainTex = tex2D(_MainTex, i.uv);
mainTex.r *= triWave(_Time.x * 5, abs(i.objectPos.y) * 2, -0.7) * 6;
// I ended up saturaing the rim calculation because negative values caused weird artifacts
mainTex.r *= triWave(_Time.x * _CascadeSpeed, abs(i.objectPos.y) * 2, -0.7) * 6;
mainTex.g *= saturate(rim) * (sin(_Time.z + mainTex.b * 5) + 1);
return mainTex.r * _Color + mainTex.g * _Color;
}

fixed4 frag (v2f i) : SV_Target
{
float screenDepth = DecodeFloatRG(tex2D(_CameraDepthTexture, i.screenuv).zw);
// float screenDepth = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
//this is not working, idk why, so sad
// float screenDepth = DecodeFloatRG(tex2D(_CameraDepthNormalsTexture, i.uv).zw); barrier
// float screenDepth = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))); world triplanar
float screenDepth = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float diff = screenDepth - i.depth;
float intersect = 0;

if (diff > 0)
intersect = 1 - smoothstep(0, _ProjectionParams.w * 0.5, diff);

Expand Down

0 comments on commit 93423d3

Please sign in to comment.