Advertisement
Coguelin

Lightprobe Double-sided Bumped Matcap Shader

Oct 21st, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.82 KB | None | 0 0
  1. Shader "FX/2bleSidedMatcapBumpedLP"
  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.             Cull Back
  20.             Tags { "LightMode" = "ForwardBase" }
  21.  
  22.             CGPROGRAM
  23.             #pragma vertex vert
  24.             #pragma fragment frag
  25.             #pragma fragmentoption ARB_precision_hint_fastest
  26.             #pragma multi_compile LIGHTMAP_ON LIGHTMAP_OFF
  27.             #include "UnityCG.cginc"
  28.  
  29.             uniform sampler2D _MatCap;
  30.            
  31.             uniform sampler2D _MainTex;
  32.             uniform fixed4 _MainTex_ST;
  33.            
  34.             uniform sampler2D _BumpMap;
  35.             uniform fixed4 _BumpMap_ST;
  36.            
  37.             uniform fixed _LPScale;
  38.  
  39.                 struct v2f
  40.                 {
  41.                     fixed4 pos : SV_POSITION;
  42.                     fixed2  uv : TEXCOORD0;
  43.                     fixed2 uv_bump : TEXCOORD1;
  44.                    
  45.                     fixed3 SHLighting : TEXCOORD3;
  46.                    
  47.                     fixed3 TtoV0 : TEXCOORD4;
  48.                     fixed3 TtoV1 : TEXCOORD5;
  49.                 };
  50.  
  51.                 v2f vert (appdata_full v)
  52.                 {
  53.                     v2f o;
  54.                    
  55.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  56.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  57.                     o.uv_bump = TRANSFORM_TEX(v.texcoord, _BumpMap);
  58.                    
  59.                     fixed3 worldNormal = mul((fixed3x3)_Object2World, SCALED_NORMAL);
  60.                     fixed3 shl = ShadeSH9(fixed4(worldNormal, 1.0));
  61.                     o.SHLighting = shl * _LPScale;
  62.                    
  63.                     TANGENT_SPACE_ROTATION;
  64.                     o.TtoV0 = mul(rotation, UNITY_MATRIX_IT_MV[0].xyz);
  65.                     o.TtoV1 = mul(rotation, UNITY_MATRIX_IT_MV[1].xyz);
  66.  
  67.                     return o;
  68.                 }
  69.  
  70.                 float4 frag (v2f i) : COLOR
  71.                 {
  72.                     fixed4 tex = tex2D(_MainTex, i.uv.xy);
  73.                
  74.                     fixed3 normals = UnpackNormal(tex2D(_BumpMap, i.uv_bump));
  75.  
  76.                     fixed2 capCoord = half2(dot(i.TtoV0, normals), dot(i.TtoV1, normals));
  77.  
  78.                     fixed4 matcapLookup = tex2D(_MatCap, capCoord * 0.5 + 0.5);
  79.                    
  80.                     matcapLookup.a = 1.0;
  81.                    
  82.                     tex *= matcapLookup * 2.0;
  83.                    
  84.                     tex.xyz *= i.SHLighting;
  85.                    
  86.                     return tex;
  87.                 }
  88.  
  89.             ENDCG
  90.  
  91.         }
  92.        
  93.         Pass
  94.         {
  95.             Name "BACK"
  96.             Cull Front
  97.             Tags { "LightMode" = "ForwardBase" }
  98.  
  99.             CGPROGRAM
  100.             #pragma vertex vert
  101.             #pragma fragment frag
  102.             #pragma fragmentoption ARB_precision_hint_fastest
  103.             #pragma multi_compile LIGHTMAP_ON LIGHTMAP_OFF
  104.             #include "UnityCG.cginc"
  105.  
  106.             uniform sampler2D _MainTex;
  107.             uniform fixed4 _MainTex_ST;
  108.  
  109.                 struct v2f
  110.                 {
  111.                     fixed4 pos : SV_POSITION;
  112.                     fixed2  uv : TEXCOORD0;
  113.                 };
  114.  
  115.                 v2f vert (appdata_full v)
  116.                 {
  117.                     v2f o;
  118.                    
  119.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  120.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  121.                    
  122.                     v.normal = -v.normal;
  123.  
  124.                     return o;
  125.                 }
  126.  
  127.                 float4 frag (v2f i) : COLOR
  128.                 {
  129.                     fixed4 tex = tex2D(_MainTex, i.uv.xy);
  130.                    
  131.                     return tex;
  132.                 }
  133.  
  134.             ENDCG
  135.  
  136.         }
  137.  
  138.     }
  139.    
  140. FallBack "FX/MatcapDiffuseLP"
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement