Advertisement
Coguelin

Lightmapped Bumped Matcap Shader

Oct 21st, 2013
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. Shader "FX/MatcapBumpedLM"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _BumpMap ("Bumpmap (RGB)", 2D) = "bump" {}
  7.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
  8.     }
  9.  
  10.     Subshader
  11.     {
  12.         Tags { "RenderType"="Opaque" "BW"="TrueProbes"}
  13.         Fog { Mode Off }
  14.  
  15.         Pass
  16.         {
  17.             Name "BASE"
  18.             Tags { "LightMode" = "ForwardBase" }
  19.  
  20.             CGPROGRAM
  21.             #pragma vertex vert
  22.             #pragma fragment frag
  23.             #pragma fragmentoption ARB_precision_hint_fastest
  24.             #pragma multi_compile LIGHTMAP_ON LIGHTMAP_OFF
  25.             #include "UnityCG.cginc"
  26.  
  27.             uniform sampler2D _MatCap;
  28.            
  29.             uniform sampler2D _MainTex;
  30.             uniform fixed4 _MainTex_ST;
  31.            
  32.             uniform sampler2D _BumpMap;
  33.             uniform fixed4 _BumpMap_ST;
  34.            
  35.             #ifndef LIGHTMAP_OFF
  36.             uniform fixed4 unity_LightmapST;
  37.             uniform sampler2D unity_Lightmap;
  38.             #endif
  39.  
  40.                 struct v2f
  41.                 {
  42.                     fixed4 pos : SV_POSITION;
  43.                     fixed2  uv : TEXCOORD0;
  44.                     fixed2 uv_bump : TEXCOORD1;
  45.                    
  46.                     #ifndef LIGHTMAP_OFF
  47.                     fixed2 uvLM : TEXCOORD2;
  48.                     #endif
  49.                    
  50.                     fixed3 TtoV0 : TEXCOORD4;
  51.                     fixed3 TtoV1 : TEXCOORD5;
  52.                 };
  53.  
  54.                 v2f vert (appdata_full v)
  55.                 {
  56.                     v2f o;
  57.                    
  58.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  59.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  60.                     o.uv_bump = TRANSFORM_TEX(v.texcoord, _BumpMap);
  61.                    
  62.                     #ifndef LIGHTMAP_OFF
  63.                     o.uvLM = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  64.                     #endif
  65.                    
  66.                     TANGENT_SPACE_ROTATION;
  67.                     o.TtoV0 = mul(rotation, UNITY_MATRIX_IT_MV[0].xyz);
  68.                     o.TtoV1 = mul(rotation, UNITY_MATRIX_IT_MV[1].xyz);
  69.  
  70.                     return o;
  71.                 }
  72.  
  73.                 float4 frag (v2f i) : COLOR
  74.                 {
  75.                     fixed4 tex = tex2D(_MainTex, i.uv.xy);
  76.                
  77.                     fixed3 normals = UnpackNormal(tex2D(_BumpMap, i.uv_bump));
  78.  
  79.                     fixed2 capCoord = half2(dot(i.TtoV0, normals), dot(i.TtoV1, normals));
  80.  
  81.                     fixed4 matcapLookup = tex2D(_MatCap, capCoord * 0.5 + 0.5);
  82.                    
  83.                     matcapLookup.a = 1.0;
  84.                    
  85.                     tex *= matcapLookup * 2.0;
  86.                    
  87.                     #ifndef LIGHTMAP_OFF
  88.                     fixed3 lm = DecodeLightmap (tex2D(unity_Lightmap, i.uvLM.xy));
  89.                     tex.xyz *= lm;
  90.                     #endif
  91.                    
  92.                     return tex;
  93.                 }
  94.  
  95.             ENDCG
  96.  
  97.         }
  98.  
  99.     }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement