Painting a car's body is a complicated process. body paint is an expensive layered form that often contains a dye layer and an enamel metal foil suspension layer.
Because these paint surfaces are one after another,DisplayA complex optical interaction makes the car look smooth and shiny.
Complete HLSL pixel coloring ToolCodeAs follows:
Struct psinput {float2 TEX: vertex; float3 tangent: texcoord1; float3 binormal: texcoord2; float3 normal: texcoord3; float3 view: texcoord4; float3 sparkletex: texcoord5 ;}; float4 main (psinput I): Color {// obtain the current line chart float3 vnormal = tex2d (normalmap, I. tex); // zoom and offset in the range [-1.0, 1.0]: vnormal = 2.0f * vnormal-1.0f; // obtain the normal with high-frequency disturbance, query a noise chart. Float3 vflakesnormal = tex2d (microflakenmap, I. sparkletex); // do not forget to switch to the [-1.0, 1.0] region: vflakesnormal = 2 * vflakesnormal-1.0; // calculate the following formula // Np1 = (A * NP + B * n) /| A * NP + B * n | where a <B // float3 vnp1 = microflakeperturbationa * vflakesnormal + normalperturbation * vnormal; // calculate the following formula // NP2 = (C * NP + D * n) // | C * NP + D * n | where c = D float3 vnp2 = microflakeperturbati On * (vflakesnormal + vnormal); // You must normalize float3 vview = normalize (View) because you need to multiply the angle from the normal point ); // convert the surface normal to the World Space and calculate the bump map method. Float3x3 mtangenttoworld = transpose (float3x3 (tangent, binormal, normal); float3 vnormalworld = normalize (MUL (mtangenttoworld, vnormal )); // calculate the angle Yu Xuan float fndotv = saturate (dot (vnormalworld, vview); // calculate the reflection vector float3 vreflection = 2 * vnormalworld * fndotv-vview; // We Need A Gloss Value to read the environment graph. In the real demo, the reflection effect is slightly blurred. Float fenvbias = glosslevel; // use a reflection vector to sample the environment map. Float4 envmap = texcubebias (showroommap, float4 (vreflection, fenvbias); // multiply the brightness value to store rgbe envmap in Channel. RGB = envmap. RGB * envmap. a; // multiply by a brightness coefficient envmap. RGB * = brightnessfactor; // converts the normal in the tangent space to the world coordinate. float3 vnp1world = normalize (MUL (mtangenttoworld, vnp1); // returns the Feier coefficient float ffresnel1 = saturate (dot (vnp1world, vview )); // Replace the second normal with the world coordinates in the space of the re-tangent. float3 vnp2world = normalize (MUL (mtangenttoworld, vnp2); // obtain the second feinier coefficient using the same method. float ffresnel2 = saturate (dot (vnp2world, vview); // start to synthesize all layers. // according to formula 3, float colors = ffresnel1; float4 paintcolor = ffresnel1 * paintcolor0 + colors * paintcolormid + colors * Colors * paintcolor2 + POW (ffresnel2, 16) * flakelayercolor; // finally, it is combined with the reflected environment texture to form the final result. float fenvcontribution = 1.0-0.5 * fndotv; float4 finalcolor; finalcolor. A = 1.0; finalcolor. RGB = envmap * fenvcontribution + paintcolor; return finalcolor ;}
conclusion
the algorithm used by this Code , experience is greater than real physical properties, so constant numeric values need to be constantly adjusted.
to achieve a satisfactory result.