Advertisement
Coguelin

Lightprobe Diffuse MatCap Shader

Oct 21st, 2013
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. Shader "FX/MatcapDiffuseLP"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _MatCap ("MatCap (RGB)", 2D) = "white" {}
  7.         _LPScale ("Light Probe Influence", float) = 1
  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 fixed _LPScale;
  33.  
  34.                 struct v2f
  35.                 {
  36.                     fixed4 pos : SV_POSITION;
  37.                     fixed2  uv : TEXCOORD0;
  38.                    
  39.                     fixed3 SHLighting : TEXCOORD2;
  40.                    
  41.                     fixed2 cap : TEXCOORD3;
  42.                 };
  43.  
  44.                 v2f vert (appdata_full v)
  45.                 {
  46.                     v2f o;
  47.                    
  48.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  49.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  50.                    
  51.                     fixed3 worldNormal = mul((fixed3x3)_Object2World, SCALED_NORMAL);
  52.                     fixed3 shl = ShadeSH9(fixed4(worldNormal, 1.0));
  53.                     o.SHLighting = shl * _LPScale;
  54.                    
  55.                     fixed2 capCoord;
  56.                     capCoord.x = dot(UNITY_MATRIX_IT_MV[0].xyz, v.normal);
  57.                     capCoord.y = dot(UNITY_MATRIX_IT_MV[1].xyz, v.normal);
  58.                    
  59.                     o.cap = capCoord * 0.5 + 0.5;
  60.  
  61.                     return o;
  62.                 }
  63.  
  64.                 float4 frag (v2f i) : COLOR
  65.                 {
  66.                     fixed4 tex = tex2D(_MainTex, i.uv.xy);
  67.  
  68.                     fixed4 matcapLookup = tex2D(_MatCap, i.cap);
  69.                    
  70.                     matcapLookup.a = 1.0;
  71.                    
  72.                     tex *= matcapLookup * 2.0;
  73.                    
  74.                     tex.xyz *= i.SHLighting;
  75.                    
  76.                     return tex;
  77.                 }
  78.  
  79.             ENDCG
  80.  
  81.         }
  82.     }
  83.  
  84. FallBack "Mobile/Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement