Advertisement
Coguelin

Lightprobe Bumped Matcap Shader

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