Advertisement
Coguelin

Lightprobe Double-sided Diffuse Matcap Shader

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