Advertisement
tonynogo

Demo 26 - Force field rim effect and texture

Jul 6th, 2017
9,724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Shield" {
  2.     Properties {
  3.         _MainTex ("Texture", 2D ) = "white" {}
  4.         _Color ("Color", Color) = (1, 1, 1, 1)
  5.         _RimEffect ("Rim effect", Range(0, 1)) = 0
  6.     }
  7.     SubShader {
  8.         Pass {
  9.             Tags { "Queue"="Transparent" "RenderType"="Transparent" }
  10.             Blend One One
  11.             Cull Off
  12.             ZWrite Off
  13.  
  14.             CGPROGRAM
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.  
  18.             #include "UnityCG.cginc"
  19.  
  20.             struct v2f {
  21.                 float4 pos : SV_POSITION;
  22.                 float3 normal : NORMAL;
  23.                 float2 uv : TEXCOORD0;
  24.                 float3 viewDir : TEXCOORD1;
  25.             };
  26.  
  27.             sampler2D _MainTex;
  28.             float4 _MainTex_ST;
  29.  
  30.             v2f vert(appdata_full v) {
  31.                 v2f o;
  32.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  33.                 o.normal = normalize(mul((float3x3)_Object2World, v.normal.xyz));
  34.                 o.viewDir = normalize(_WorldSpaceCameraPos - mul((float3x3)_Object2World, v.vertex.xyz));
  35.                 o.uv = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
  36.                 return o;
  37.             }
  38.  
  39.             fixed4 _Color;
  40.             fixed _RimEffect;
  41.  
  42.             fixed4 frag(v2f i) : COLOR {
  43.                 float t = tex2D(_MainTex, i.uv);
  44.                 float val = 1 - abs(dot(i.viewDir, i.normal)) * _RimEffect;
  45.                 return _Color * _Color.a * val * val * t;
  46.             }
  47.  
  48.             ENDCG
  49.         }
  50.     }
  51.     FallBack "Diffuse"
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement