Advertisement
dnnkeeper

Unity Hologram Shader

May 2nd, 2014
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. Shader "FX/HologramTest" {
  2. Properties {
  3.     _Color ("Static Color", Color) = (0.5,0.5,0.5,0.5)
  4.     _MainTex ("Static Texture", 2D) = "white" {}
  5.     _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
  6. }
  7.  
  8. Category {
  9.     Tags { "Queue"="Overlay" "IgnoreProjector"="True" "RenderType"="Transparent" }
  10.     Blend SrcAlpha One
  11.     AlphaTest Greater .01
  12.     ColorMask RGB
  13.     Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
  14.     BindChannels {
  15.         Bind "Color", color
  16.         Bind "Vertex", vertex
  17.         Bind "TexCoord", texcoord
  18.     }
  19.    
  20.     // ---- Fragment program cards
  21.     SubShader {
  22.         Pass {
  23.        
  24.             CGPROGRAM
  25.             #pragma vertex vert
  26.             #pragma fragment frag
  27.             #pragma fragmentoption ARB_precision_hint_fastest
  28.             #pragma multi_compile_particles
  29.  
  30.             #include "UnityCG.cginc"
  31.  
  32.             sampler2D _MainTex;
  33.             fixed4 _Color;
  34.            
  35.             struct appdata_t {
  36.                 float4 vertex : POSITION;
  37.                 fixed4 color : COLOR;
  38.                 float2 texcoord : TEXCOORD0;
  39.             };
  40.  
  41.             struct v2f {
  42.                 float4 vertex : POSITION;
  43.                 fixed4 color : COLOR;
  44.                 float2 texcoord : TEXCOORD0;
  45.                 #ifdef SOFTPARTICLES_ON
  46.                 float4 projPos : TEXCOORD1;
  47.                 #endif
  48.             };
  49.            
  50.             float4 _MainTex_ST;
  51.  
  52.             v2f vert (appdata_t v)
  53.             {
  54.                 v2f o;
  55.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  56.                 #ifdef SOFTPARTICLES_ON
  57.                 o.projPos = ComputeScreenPos (o.vertex);
  58.                 COMPUTE_EYEDEPTH(o.projPos.z);
  59.                 #endif
  60.                 o.color = v.color;
  61.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  62.                 return o;
  63.             }
  64.  
  65.             sampler2D _CameraDepthTexture;
  66.             float _InvFade;
  67.            
  68.             fixed4 frag (v2f i) : COLOR
  69.             {
  70.                 #ifdef SOFTPARTICLES_ON
  71.                 float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
  72.                 float partZ = i.projPos.z;
  73.                 float fade = saturate (_InvFade * (sceneZ-partZ));
  74.                 i.color.a *= fade;
  75.                 #endif
  76.                
  77.                 return 2.0f * i.color * _Color * tex2D(_MainTex, i.texcoord);
  78.             }
  79.             ENDCG
  80.         }
  81.     }  
  82.    
  83.     // ---- Dual texture cards
  84.     SubShader {
  85.         Pass {
  86.             SetTexture [_MainTex] {
  87.                 constantColor [_Color]
  88.                 combine constant * primary
  89.             }
  90.             SetTexture [_MainTex] {
  91.                 combine texture * previous DOUBLE
  92.             }
  93.         }
  94.     }
  95.    
  96.     // ---- Single texture cards (does not do color tint)
  97.     SubShader {
  98.         Pass {
  99.             SetTexture [_MainTex] {
  100.                 combine texture * primary
  101.             }
  102.         }
  103.     }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement