Advertisement
Coguelin

Lightmapped Diffuse MatCap Shader

Oct 21st, 2013
118
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/MatcapDiffuseLM"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
  7.     }
  8.  
  9.     Subshader
  10.     {
  11.         Tags { "RenderType"="Opaque" "BW"="TrueProbes"}
  12.         Fog { Mode Off }
  13.  
  14.         Pass
  15.         {
  16.             Name "BASE"
  17.             Tags { "LightMode" = "ForwardBase" }
  18.  
  19.             CGPROGRAM
  20.             #pragma vertex vert
  21.             #pragma fragment frag
  22.             #pragma fragmentoption ARB_precision_hint_fastest
  23.             #pragma multi_compile LIGHTMAP_ON LIGHTMAP_OFF
  24.             #include "UnityCG.cginc"
  25.  
  26.             uniform sampler2D _MatCap;
  27.            
  28.             uniform sampler2D _MainTex;
  29.             uniform fixed4 _MainTex_ST;
  30.            
  31.             #ifndef LIGHTMAP_OFF
  32.             uniform fixed4 unity_LightmapST;
  33.             uniform sampler2D unity_Lightmap;
  34.             #endif
  35.  
  36.                 struct v2f
  37.                 {
  38.                     fixed4 pos : SV_POSITION;
  39.                     fixed2  uv : TEXCOORD0;
  40.                    
  41.                     #ifndef LIGHTMAP_OFF
  42.                     fixed2 uvLM : TEXCOORD1;
  43.                     #endif
  44.                    
  45.                     fixed2 cap : TEXCOORD3;
  46.                 };
  47.  
  48.                 v2f vert (appdata_full v)
  49.                 {
  50.                     v2f o;
  51.                    
  52.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  53.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  54.                    
  55.                     #ifndef LIGHTMAP_OFF
  56.                     o.uvLM = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  57.                     #endif
  58.                    
  59.                     fixed2 capCoord;
  60.                     capCoord.x = dot(UNITY_MATRIX_IT_MV[0].xyz, v.normal);
  61.                     capCoord.y = dot(UNITY_MATRIX_IT_MV[1].xyz, v.normal);
  62.                    
  63.                     o.cap = capCoord * 0.5 + 0.5;
  64.  
  65.                     return o;
  66.                 }
  67.  
  68.                 float4 frag (v2f i) : COLOR
  69.                 {
  70.                     fixed4 tex = tex2D(_MainTex, i.uv.xy);
  71.  
  72.                     fixed4 matcapLookup = tex2D(_MatCap, i.cap);
  73.                    
  74.                     matcapLookup.a = 1.0;
  75.                    
  76.                     tex *= matcapLookup * 2.0;
  77.                    
  78.                     #ifndef LIGHTMAP_OFF
  79.                     fixed3 lm = DecodeLightmap (tex2D(unity_Lightmap, i.uvLM.xy));
  80.                     tex.xyz *= lm;
  81.                     #endif
  82.                    
  83.                     return tex;
  84.                 }
  85.  
  86.             ENDCG
  87.  
  88.         }
  89.  
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement