Advertisement
tonynogo

Demo 22 - Echolocation

Jul 6th, 2017
8,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Echolocation" {
  2.     Properties {
  3.         _Color ("Color", Color) = (1, 1, 1, 1)
  4.         _Center ("CenterX", vector) = (0, 0, 0)
  5.         _Radius ("Radius", float) = 0
  6.     }
  7.     SubShader {
  8.         Pass {
  9.             Tags { "RenderType"="Opaque" }
  10.        
  11.             CGPROGRAM
  12.             #pragma vertex vert
  13.             #pragma fragment frag
  14.             #include "UnityCG.cginc"
  15.  
  16.             float4 _Color;
  17.             float3 _Center;
  18.             float _Radius;
  19.  
  20.             struct v2f {
  21.                 float4 pos : SV_POSITION;
  22.                 float3 worldPos : TEXCOORD1;
  23.             };
  24.  
  25.             v2f vert(appdata_base v) {
  26.                 v2f o;
  27.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  28.                 o.worldPos = mul(_Object2World, v.vertex).xyz;
  29.                 return o;
  30.             }
  31.  
  32.             fixed4 frag(v2f i) : COLOR {
  33.                 float dist = distance(_Center, i.worldPos);
  34.  
  35.                 float val = 1 - step(dist, _Radius - 0.1) * 0.5;
  36.                 val = step(_Radius - 1.5, dist) * step(dist, _Radius) * val;
  37.                 return fixed4(val * _Color.r, val * _Color.g,val * _Color.b, 1.0);
  38.             }
  39.  
  40.             ENDCG
  41.         }
  42.     }
  43.     FallBack "Diffuse"
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement