Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Base_Texture"
- {
- Properties
- {
- _DiffuseAmount ( "Diffuse Amount", Range( 0.0, 1.0 ) ) = 0.25
- _TexAmount ( "Texture Amount", Range( 0.0, 1.0 ) ) = 0.25
- _SpecAmount ( "Specular Amount", Range( 0.0, 16.0 ) ) = 1.0
- _SpecTexAmount ( "Spec Texture Amount", Range( 0.0, 1.0 ) ) = 0.25
- _Normalmap ( "Normalmap", 2D ) = "normal" {}
- _Specmap ( "Specmap", 2D ) = "spec" {}
- _Gloss ( "Gloss", Range( 0.001, 1.0 ) ) = 1.0
- _SRNI ( "Specular Reflectance at Normal Incidence", Range( 0.0, 1.0 ) ) = 0.075
- }
- SubShader
- {
- Tags
- {
- "Queue"="Geometry+0"
- "IgnoreProjector"="False"
- "RenderType"="Opaque"
- }
- Cull Back
- ZWrite On
- ZTest LEqual
- CGPROGRAM
- #pragma target 3.0
- #pragma surface surf SimpleSpecular novertexlights fullforwardshadows
- float _Gloss;
- fixed _SpecAmount;
- float _SRNI;
- float CalculateGGX( float alpha, float cosThetaM )
- {
- float roughness = alpha * alpha;
- roughness *= roughness;
- float CosSquared = cosThetaM * cosThetaM;
- float TanSquared = ( 1.0 - CosSquared ) + 1.0;
- float GGX = ( CosSquared * ( roughness - 1.0 ) ) + 1.0;
- GGX = 0.31831 * GGX * GGX;
- return roughness / GGX;
- }
- float CalculateGeometric( float3 norm, float3 vec, float3 vDir, float roughness )
- {
- float n_dot_v = saturate( dot( norm, vec ) );
- return n_dot_v / ( dot( norm, vDir ) * ( 1.0 - roughness ) + roughness );
- }
- float CalculateGeometricAtten( float3 norm, float3 lDir, float3 vDir, float3 hDir, float roughness )
- {
- float roughnessRemap = roughness + 1.0;
- roughnessRemap *= roughnessRemap;
- roughnessRemap *= 0.125;
- float atten = CalculateGeometric( norm, vDir, vDir, roughnessRemap ) * CalculateGeometric( norm, lDir, vDir, roughnessRemap );
- return atten;
- }
- float CalculateSpecular( fixed3 lDir, fixed3 vDir, fixed3 norm, float lightSize, float gloss )
- {
- fixed n_dot_l = dot( norm, lDir );
- fixed n_dot_v = dot( norm, vDir );
- float3 halfVector = normalize( lDir + vDir );
- float specDot = dot( halfVector, norm );
- float fresnel = pow( 1.0 - saturate( dot( halfVector, vDir ) ), 5.0 );
- fresnel = _SRNI + ( 1.0 - _SRNI ) * fresnel;
- float geoAtten = CalculateGeometricAtten( norm, lDir, vDir, halfVector, gloss );
- float distribution = CalculateGGX( gloss, saturate( specDot ) );
- float BRDF = ( distribution * geoAtten * fresnel ) / ( 4.0 * n_dot_l * n_dot_v );
- return BRDF;
- }
- fixed4 LightingSimpleSpecular( SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten )
- {
- fixed spec = CalculateSpecular( lightDir, viewDir, s.Normal, 1.0, s.Gloss ) * 0.01 * _SpecAmount;
- fixed diff = dot( s.Normal, lightDir ) * s.Albedo;
- diff = lerp( diff, 0.0, spec );
- fixed4 c;
- c.rgb = diff * _LightColor0.rgb;
- c.rgb += _LightColor0.rgb * spec;
- c.rgb *= atten;
- c.a = s.Alpha;
- return c;
- }
- struct Input
- {
- float2 uv_Normalmap;
- float2 uv_Specmap;
- float3 viewDir;
- };
- sampler2D _Normalmap;
- sampler2D _Specmap;
- fixed _SpecTexAmount;
- fixed _TexAmount;
- fixed _DiffuseAmount;
- void surf( Input IN, inout SurfaceOutput o )
- {
- o.Normal = UnpackNormal( tex2D( _Normalmap, IN.uv_Normalmap ) );
- float spec = tex2D( _Specmap, IN.uv_Specmap ).r;
- o.Gloss = lerp( spec * 2.0, 0.5, _SpecTexAmount ) * _Gloss;
- o.Albedo = _DiffuseAmount * lerp( spec, 1.0, _TexAmount );
- }
- ENDCG
- }
- Fallback "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment