Advertisement
Orihaus

AEON - Base Shader

Jan 28th, 2013
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.65 KB | None | 0 0
  1. Shader "Base_Bumped_Texture"
  2. {
  3.     Properties  
  4.     {
  5.         _TexAmount ( "Texture Amount", Range( 0.0, 1.0 ) ) = 0.25
  6.         _TexBoost ( "Texture Boost", Range( 0.0, 2.0 ) ) = 0.0
  7.         _MainMap ( "Main Texture", 2D ) = "main" {}
  8.         _Normalmap ( "Normalmap", 2D ) = "normal" {}
  9.         _Specmap ( "Specmap", 2D ) = "spec" {}
  10.         _AmbientRim ( "Ambient Rim", Range( 0.0, 0.5 ) ) = 0.075
  11.         _FresnelPower ( "Fresnel Power", Range( 0.0, 32.0 ) ) = 8.0
  12.         _FresnelMult ( "Fresnel Multiplier", Range( 0.0, 2.25 ) ) = 0.75
  13.         _FresnelDilute ( "Fresnel Dilute", Range( 0.0, 2.25 ) ) = 0.75
  14.         _PrimaryBlob ( "Primary Blob", Range( 0.0, 1.0 ) ) = 1.0
  15.         _SecondaryBlob ( "Secondary Blob", Range( 0.0, 1.0 ) ) = 0.125
  16.         _BRDFAmount ( "BRDF Amount", Range( 0.0, 1.0 ) ) = 0.125
  17.         _BRDFRoughnessX ( "BRDF Roughness X", Range( 0.0, 2.0 ) ) = 1.0
  18.         _BRDFRoughnessY ( "BRDF Roughness Y", Range( 0.0, 2.0 ) ) = 1.0
  19.         _Gloss ( "Gloss", Range( 0.0, 2.0 ) ) = 1.0
  20.     }
  21.        
  22.     SubShader
  23.     {
  24.         Tags
  25.         {
  26.           "Queue"="Geometry+0"
  27.           "IgnoreProjector"="False"
  28.           "RenderType"="Opaque"
  29.         }
  30.  
  31.         Cull Back
  32.         ZWrite On
  33.         ZTest LEqual
  34.  
  35.         CGPROGRAM
  36.         #pragma target 3.0
  37.         #pragma surface surf SimpleSpecular noambient novertexlights vertex:vert
  38.         //fullforwardshadows approxview
  39.        
  40.         float _Shininess;
  41.         float _Gloss;
  42.         float _AmbientRim;
  43.         float _FresnelPower;
  44.         float _FresnelMult;
  45.         float _FresnelDilute;
  46.         float _PrimaryBlob;
  47.         float _SecondaryBlob;
  48.         float _BRDFAmount;
  49.         float _BRDFRoughnessX;
  50.         float _BRDFRoughnessY;
  51.        
  52.         fixed CalculateSpecular( fixed3 lDir, fixed3 vDir, fixed3 norm, fixed spec, fixed3 tangent )
  53.         {  
  54.             float3 halfVector = normalize( lDir + vDir );
  55.            
  56.             float specDot = saturate( dot( halfVector, norm ) );
  57.             float diffuseDot = saturate( dot( lDir, norm ) );
  58.             float fresnelDot = min( 1.0, dot( vDir, norm ) );
  59.             float dotHTAlphaX = dot( halfVector, tangent ) / _BRDFRoughnessX;
  60.             float dotHBAlphaY = dot( halfVector, cross( norm, tangent ) ) / _BRDFRoughnessY;
  61.            
  62.             float BRDF = sqrt( saturate( diffuseDot / fresnelDot ) )
  63.                   * exp( -2.0 * ( dotHTAlphaX * dotHTAlphaX
  64.                   + dotHBAlphaY * dotHBAlphaY ) / ( 1.0 + specDot ) );
  65.        
  66.             float rimCore = 1.0 - saturate( fresnelDot );
  67.             float rim = rimCore + ( pow( rimCore, _FresnelPower ) * 2.0 );
  68.             rim *= specDot;
  69.             float doubleSpec = ( ( _SecondaryBlob * pow( specDot, _Gloss * 16.0 ) ) + ( pow( specDot, _Gloss * 128.0 ) * _PrimaryBlob ) ) * 2.5;
  70.            
  71.             float SpecularCore = lerp( BRDF * 0.75, doubleSpec, _BRDFAmount );
  72.             return spec * ( ( rim * _AmbientRim ) + ( _FresnelMult * rim + _FresnelDilute ) * SpecularCore );
  73.         }
  74.        
  75.         fixed4 LightingSimpleSpecular( SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten )
  76.         {
  77.             fixed diff = saturate( dot( s.Normal, lightDir ) );
  78.             fixed spec = CalculateSpecular( lightDir, viewDir, s.Normal, s.Specular, s.Albedo );
  79.            
  80.             fixed4 c;
  81.             c.rgb = ( s.Gloss * _LightColor0.rgb * diff + _LightColor0.rgb * spec ) * atten;
  82.            
  83.             return c;
  84.         }
  85.        
  86.         fixed4 LightingSimpleSpecular_DirLightmap( SurfaceOutput s, fixed4 color, fixed4 scale, fixed3 viewDir, bool surfFuncWritesNormal, out fixed3 specColor )
  87.         {
  88.             UNITY_DIRBASIS
  89.             half3 scalePerBasisVector;
  90.            
  91.             half3 lm = DirLightmapDiffuse( unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector );
  92.             half3 lightDir = normalize( scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2 ]);
  93.            
  94.             specColor = lm * CalculateSpecular( lightDir, viewDir, s.Normal, s.Specular, s.Albedo );
  95.            
  96.             return half4( lm * 0.5, 1.0 );
  97.         }
  98.        
  99.         struct Input
  100.         {
  101.             float3 viewDir;
  102.             float3 tangent;
  103.             float2 uv_MainMap;
  104.             float2 uv_Normalmap;
  105.             float2 uv_Specmap;
  106.             float3 worldNormal; INTERNAL_DATA
  107.         };
  108.    
  109.         sampler2D _MainMap;
  110.         sampler2D _Normalmap;
  111.         sampler2D _Specmap;
  112.         float4 _Color;
  113.         fixed _ScaleX;
  114.         fixed _ScaleY;
  115.         fixed _TexAmount;
  116.         fixed _TexBoost;
  117.        
  118.         void vert( inout appdata_full v, out Input o )
  119.         {
  120.             UNITY_INITIALIZE_OUTPUT( Input, o );
  121.             o.tangent = v.tangent;
  122.         }
  123.        
  124.         void surf( Input IN, inout SurfaceOutput o )
  125.         {
  126.             float tex = _TexAmount + ( 1.0 - _TexAmount ) * tex2D( _MainMap, IN.uv_MainMap ).r;
  127.             o.Albedo = IN.tangent; // Smuggle Tangent in Albedo;
  128.  
  129.             o.Normal = UnpackNormal( tex2D( _Normalmap, IN.uv_Normalmap ) );
  130.             o.Gloss = 0.175 * tex; // Smuggle Albedo in Gloss;
  131.             o.Specular = _TexAmount + ( ( 1.0 + _TexBoost ) - _TexAmount ) * tex2D( _Specmap, IN.uv_Specmap ).r;
  132.         }
  133.    
  134.         ENDCG
  135.     }
  136.        
  137.     Fallback "Diffuse"
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement