Skip to content

Instantly share code, notes, and snippets.

@nir1082
Last active August 22, 2017 02:40
Show Gist options
  • Save nir1082/589ac3338f1be37c88aaa69932a7ce12 to your computer and use it in GitHub Desktop.
Save nir1082/589ac3338f1be37c88aaa69932a7ce12 to your computer and use it in GitHub Desktop.
Shader "Custom/GrabPassSphere"
{
Properties
{
_Length ("Length", Range(0,1)) = .5
_Strength ("Strength", Range(0, 1000.)) = 0.01
}
SubShader
{
Lighting Off
Tags { "Queue" = "Transparent" "RenderType"="Opaque" }
GrabPass { "_GrabTexture" }
ColorMask 0
ZWrite On
CGPROGRAM
#pragma surface surf NoLighting vertex:vert alpha:blend novertexlights
half4 LightingNoLighting(SurfaceOutput s, half3 lightDir, half atten)
{
half4 c;
c.rgb = s.Albedo.rgb;
c.a = s.Alpha;
return c;
}
struct Input
{
float3 viewDir;
float4 grabUV;
};
void vert (inout appdata_full v, out Input o)
{
o.viewDir = ObjSpaceViewDir(v.vertex);
o.grabUV = ComputeGrabScreenPos(UnityObjectToClipPos(v.vertex));
}
sampler2D _GrabTexture;
uniform float _Length;
uniform float _Strength;
void surf (Input IN, inout SurfaceOutput o)
{
o.Specular = 0;
o.Emission = 0;
float vertLen = 1.0 - saturate (dot (normalize (IN.viewDir), o.Normal));
float4 fix = ComputeScreenPos (UnityObjectToClipPos (float3(0, 0, 0)));
fixed2 pos = IN.grabUV - fix;
float expLen = exp (-_Strength * pow(vertLen - _Length, 2));
float th = expLen * sin(_Length * 3.141593 * .015) * (8.0 - 8.0 * pow(_Length, 2.0/3.0));
float sinTh = sin(th);
float cosTh = cos(th);
IN.grabUV.x = pos.x * cosTh - pos.y * sinTh + fix.x;
IN.grabUV.y = pos.x * sinTh + pos.y * cosTh + fix.y;
o.Albedo = tex2Dproj (_GrabTexture, IN.grabUV);
o.Alpha = 1.0 - _Length;
}
ENDCG
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment