In this article, we will create a lighting model for vehicle painting. The first is to prepare the scene, new Shader & Material.
The process is relatively simple, just look at the finished code:
Shader"91ygame/caroutlight"{Properties {_maintint ("Diffuse Tint", Color) = (1,1,1,1) _maintex ("Base (RGB)", 2D) =" White"{}_specularcolor ("Specular Color", Color) = (1,1,1,1) _specpower ("Specular Power", Range (0.1, -))=3_relfcube ("Reflection Cube", Cube) =""{}_brdftex ("BRDF Texture", 2D) =""{}_diffusepower ("Diffuse Power", Range (0.1,Ten))=0.5_falloffpower ("Falloff Spread", Range (0.1,Ten))=3_reflamount ("Reflection Amount", Range (0.1,1))=0.5_reflpower ("Reflection Power", Range (0.1,3))=2.0}subshader {Tags {"Rendertype"="Opaque"}lod $Cgprogram#pragmaSurface Surf Carpaintsampler2d _maintex;sampler2d _brdftex;float4 _maintint;float4 _specularcolor;fixed_specpower;fixed_diffusepower;fixed_falloffpower;fixed_reflamount;fixed_reflpower;samplercube _relfcube;structInput {float2 uv_maintex;float3 worldrefl;floatViewdir;}; Inline fixed4 lightingcarpaint (surfaceoutput s,fixed3 lightdir,half3 Viewdir,fixedatten) {half3 h= Normalize (lightdir+viewdir);fixeddiff = Max (0, Dot (s.normal,lightdir)); floatAHDN =1-Dot (h,normalize (s.normal)); AHDN= POW (Clamp (AHDN,0,1), _diffusepower); Half4 BRDF= Tex2d (_brdftex,float2 (diff,1-AHDN)); floatNH = MAX (0, Dot (s.normal,h));floatSpec =POW (nh,s.specular*_specpower) *S.gloss, Fixed4 C;c.rgb= (S.albedo*_lightcolor0.rbg*brdf.rgb + _lightcolor0.rgb*_specularcolor.rgb*spec) * (atten*2); C.A= s.alpha+_lightcolor0.a*_specularcolor.a*spec*Atten;returnC;} voidSurf (Input in, InOut surfaceoutput o) {half4 c=tex2d (_maintex, In.uv_maintex);fixedFalloff = Saturate (1-Dot (normalize (in.viewdir), o.normal)); Falloff=Pow (falloff,_falloffpower); O.albedo= c.rgb*_maintint;o. Emission= Pow ((Texcube (_RELFCUBE,IN.WORLDREFL). Rgb*falloff), _reflpower) *_reflamount;o. Albedo= c.rgb*_maintint;o. Specular=C.r;o. Gloss=1; O. Alpha=C.A;} ENDCG} FallBack"Diffuse"}
When you are finished, return to the editor to see the effect:
In the implementation of the above, using some of the techniques mentioned earlier, we used BRDF to create two kinds of gradient color paint.
It is simple to calculate a Fresnel coefficient, and a descending element to determine the reflective strength of the vehicle's surface.
all of these light intensities are determined by Properties in the module UI value is determined. This maximizes the convenience of the art staff.
Unity3d Shaderlab vehicle Painting lighting model combat