본문으로 바로가기

Unity Tri-plannar3BlendvertexColor

category Technical Report/Unity Shader 2017. 2. 27. 14:34
반응형


Shader "Triplanar3BlendVertexColor" {
 


 Properties {

      [Header(Not use model UV mapping)]
     [Space]
     _bright("Brightness value", Range(0,3)) = 1
     _TintColor ("TintColor", Color) = (1,1,1,1) 
         
     [Header(Y direction mapping)]
     _Y1Scale("Tiling", float) = 1
     [NoScaleOffset]_MainTex ("Terrain Base Texture", 2D) = "white" {}

      [Header(XZ direction mapping)]
     _XScale("Tiling", float) = 1
     [NoScaleOffset]_MainTex1 ("XZ Texture", 2D) = "white" {}

     _Blend("XZ Blend Range", Range(1,2)) = 1.2
    
     [Space(20)]
     [Header(Vertex Color)]
     _Y2Scale("R Tiling", float) = 1
     _Factor1("R Intensity", Range(0,1.0)) = 1         
     [NoScaleOffset]_MainTex2 ("Vertex R Texture", 2D) = "white" {}     
       
    
 }
 
 SubShader
 {
   
 
     Tags{ "RenderType" = "Opaque" }

     LOD 200

     CGPROGRAM       
     #pragma surface surf Unlit interpolateview halfasview noambient noforwardadd nodirlightmap noforwardadd nodynlightmap noshadow novertexlights
    
     fixed4 LightingUnlit(SurfaceOutput s, half3 lightDir, half atten) {

     return fixed4(s.Albedo,1);
 }
 
     sampler2D _MainTex1;
     sampler2D _MainTex;
     sampler2D _MainTex2;
  
   
     fixed _XScale;
     fixed _Y1Scale;
     fixed _Y2Scale;
 
       fixed _Factor1;      
   
     fixed4 _TintColor;

     fixed _Blend, _bright;
   
     struct Input {
   
         float3 worldPos;
         float3 worldNormal;
        
         fixed4 color:Color; 
      
     };
       
     void surf (Input IN, inout SurfaceOutput o) {
      
           float3 projNormal = saturate(pow(IN.worldNormal * _Blend, 2));     
         
          //caculate x,y,z direction mapping    

          
          fixed3 x = tex2D(_MainTex1, float2(IN.worldPos.zy * _XScale  * 0.01)) * abs(IN.worldNormal.x);              
          fixed3 z = tex2D(_MainTex1, float2(IN.worldPos.xy * _XScale  * 0.01)) * abs(IN.worldNormal.z);
          fixed3 y = tex2D(_MainTex,  float2(IN.worldPos.zx * _Y1Scale * 0.01)) * abs(IN.worldNormal.y);
                                                
          //blend vertex color channel


          fixed3 y1 = lerp (y,  tex2D(_MainTex2, float2(IN.worldPos.zx * _Y2Scale * 0.01)) * abs(IN.worldNormal.y), IN.color.r *  _Factor1);


           //if scale value decide depend on object world scale.
                   
          o.Albedo = (z + x) * 0.8;
        
          o.Albedo = lerp(o.Albedo, y1, projNormal.y) * _TintColor * _bright;
       
    
     }
   
     ENDCG
 }

 
 }

반응형