Advertisement
Coguelin

Lightprobe Alpha Diffuse Matcap Shader

Oct 21st, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. Shader "FX/MatcapDiffuse_Alpha"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
  7.         _Alpha ("Alpha", float) = 0.5
  8.     }
  9.  
  10.     Subshader
  11.     {
  12.         Blend SrcAlpha OneMinusSrcAlpha
  13.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
  14.         Cull Back
  15.         Fog { Mode Off }
  16.  
  17.  
  18.         Pass
  19.         {
  20.             Name "BASE"
  21.             Tags { "LightMode" = "ForwardBase" }
  22.  
  23.             CGPROGRAM
  24.             #pragma vertex vert
  25.             #pragma fragment frag
  26.             #pragma fragmentoption ARB_precision_hint_fastest
  27.             #pragma multi_compile LIGHTMAP_ON LIGHTMAP_OFF
  28.             #include "UnityCG.cginc"
  29.  
  30.             uniform sampler2D _MatCap;
  31.            
  32.             uniform sampler2D _MainTex;
  33.             uniform fixed4 _MainTex_ST;
  34.            
  35.             uniform fixed _Alpha;
  36.  
  37.                 struct v2f
  38.                 {
  39.                     fixed4 pos : SV_POSITION;
  40.                     fixed2  uv : TEXCOORD0;
  41.                    
  42.                     fixed2 cap : TEXCOORD3;
  43.                 };
  44.  
  45.                 v2f vert (appdata_full v)
  46.                 {
  47.                     v2f o;
  48.                    
  49.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  50.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  51.                    
  52.                     fixed2 capCoord;
  53.                     capCoord.x = dot(UNITY_MATRIX_IT_MV[0].xyz, v.normal);
  54.                     capCoord.y = dot(UNITY_MATRIX_IT_MV[1].xyz, v.normal);
  55.                    
  56.                     o.cap = capCoord * 0.5 + 0.5;
  57.  
  58.                     return o;
  59.                 }
  60.  
  61.                 float4 frag (v2f i) : COLOR
  62.                 {
  63.                     fixed4 tex = tex2D(_MainTex, i.uv.xy);
  64.  
  65.                     fixed4 matcapLookup = tex2D(_MatCap, i.cap);
  66.                    
  67.                     // matcapLookup.a = tex.a;
  68.                    
  69.                     tex *= matcapLookup * 2.0;
  70.                    
  71.                     tex.a = _Alpha;
  72.                    
  73.                     return tex;
  74.                 }
  75.  
  76.             ENDCG
  77.  
  78.         }
  79.  
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement