Created
February 7, 2013 05:09
-
-
Save LoganBarnett/4728716 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Shader "Custom/SensorRadius" { | |
| Properties { | |
| _MainTex ("Main Texture", 2D) = "white" {} | |
| _RampTex ("Ramp Txture", 2D) = "white" {} | |
| _ScreenX ("Screen X", Float) = 0 | |
| _ScreenY ("Screen Y", Float) = 0 | |
| _Radius ("Cutoff Radius", Range(0, 1)) = 0.5 | |
| } | |
| SubShader { | |
| Tags { "RenderType"="Transparent" "Queue"="Transparent"} | |
| LOD 200 | |
| Pass { | |
| // Lighting Off | |
| ZWrite On | |
| Blend SrcAlpha OneMinusSrcAlpha | |
| CGPROGRAM | |
| // #pragma surface surf Lambert frag:frag vertex:vert_img | |
| #pragma fragment frag | |
| #pragma vertex vert_img | |
| #include "UnityCG.cginc" | |
| sampler2D _Mask; | |
| sampler2D _MainTex; | |
| sampler2D _RampTex; | |
| uniform float _Radius; | |
| uniform float _ScreenX; | |
| uniform float _ScreenY; | |
| half4 frag(v2f_img i) : COLOR { | |
| half4 color = tex2D(_MainTex, i.uv); | |
| //vector to the middle of the screen | |
| half2 dir = 0.5 - i.uv; | |
| half x = (0.5 - i.uv.x) * _ScreenX / _ScreenY; | |
| dir.x = x; | |
| float dist = saturate(1 - dot(dir, dir)); | |
| // dist = pow(dist, 1 / _Radius)); | |
| //distance to center | |
| // half dist = sqrt(dir.x*dir.x + dir.y*dir.y); | |
| // half dist = sqrt(x * x + dir.y * dir.y); | |
| color.a = 1 - tex2D(_RampTex, float2(dist * _Radius, 0)).r; | |
| // for debugging | |
| // color.r = 1 - tex2D(_RampTex, float2(dist * _Radius, 0)).r; | |
| return color; | |
| } | |
| // struct Input { | |
| // float2 uv_MainTex; | |
| // }; | |
| // | |
| // void surf (Input IN, inout SurfaceOutput o) { | |
| // fixed4 c = tex2D(_MainTex, IN.uv_MainTex); | |
| // o.Albedo = c.rgb; | |
| // o.Alpha = c.a; | |
| // } | |
| ENDCG | |
| } | |
| } | |
| // FallBack "Diffuse" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment