Unity3d based on physical rendering physically-based rendering specular BRDF

Source: Internet
Author: User
Tags diff black ops

physically-based Rendering (PBR) Chinese as a physics-based rendering in real-time rendering
It can bring more realistic effect to the rendered object, and the energy conservation



A little explanation of the meaning of the letter, for the understanding of the later article is helpful,
From right to left
L is the direction of light, H is the half-width vector, L is the middle of V, N is the normal direction, V is the direction of our eyes (the direction the camera is looking), R is the reflection direction
Specular reflection formula of Torrance-sparrow illumination model

D is the normal distribution function (NDF)
F is the reflection function (Fresnel function)
G is the shadow mask function (geometric function), which is not proportional to shadow or mask
The e here is the V above
Specular reflection formula of cook-torrance illumination model

And then we'll just use cook-torrance light to do the experiment.

In general, BRDF is a linear combination of reflection results for multiple properties of the surface (in real-time rendering, only the diffuse and specular are considered to be the only two types)

This is unity's specular.
Does it look special like plastic? or a rough plastic.

And then we're going to talk about the difference between the specular of the D function.
distribution function of BlinnphongCall of Duty:black Ops 2/Calling of Duty: Black Ops 2 used it

Description in http://segmentfault.com/blog/wwt_warp/1190000000436286
MICROFACET Micro plane model is a widely used tool for modeling rough surface, and Blinn,ward,beckmann belongs to Microfacet derivation results. The basic idea is also very simple, is to use a small micro-plane combination to simulate the rough surface of the object. These tiny plane elements can be used as perfect reflections or refracted surfaces. Each microfacet reflects a light in the direction of an incident to a single exit direction, depending on the Microfacet's normal m. When calculating the BRDF, the light source direction L and the sight Direction v are given. This means that in all microfacet on the surface, only the part that reflects L to V is contributing to BRDF. In, we can see that the surface method of these effective microfacet to m just in the middle of L and V, that is H.


 
D is the normal distribution function (NDF), and on most surfaces, the direction of Microfacet is not evenly distributed. The closer the normals of the microfacet to the normal of the macro surface, the smoother it becomes. This distribution is defined by the normal distribution function D (m) of the Microfacet. function d () determines the size, brightness, and shape of the specular highlight. Normal distribution functions generally have parameters similar to "roughness".

F is the reflection function (Fresnel function), which calculates the reflectance ratio on the optics.
Denominator 4 (n?l) (N?V) is a correction factor used to correct the difference in the number of local spaces from Microfacet to the overall surface.
V is the visibility function and the shadow mask is classified as perspective reduction
about G,
http://www.klayge.org/wiki/index.php/%E5%9F%BA%E4%BA%8E%E7%89%A9%E7%90%86% E7%9A%84BRDF
gives the explanation
 
G is the shadow matte function (geometric function), the ratio of shadow or mask
in the upper part, the flat macro surface is green, and the rough microscopic surface is blue. The microfacet of M = h is marked in red. The macro surface is directed to the Green Line in the upper left corner. At the same time, a single red Microfacet is displayed as a separate line. Left means that in the absence of occlusion items, the area of the red Microfacet added up, the result is that the effective area is greater than the total area, so the reflection energy of BRDF is more than the receiving energy erroneously. In the right-red area, the area is less than the total area due to occlusion, and overlapping areas are not counted more than once.
 
α is the strength of the specular, and the strength of the specular is the Schlick method proposed by the

Fresnel determined by glossiness gloss:
 
 
RF0 is the reflection color, also roughness roughness
 
Occlusion Items Use the method proposed by Schlick-smith
 

in energy conservation considerations, diffuse reflection is less specular reflection, and vice versa
So:
 
 

effects are as follows:
 

looks like a polished marble effect.


The main code is as follows:

Insert code:
#define PIE 3.1415926535float4 Frag (v2f i): color{float3 Viewdir = normalize (I.viewdir); Float3 Lightdir = Normalize (I.lig Htdir); Float3 H = normalize (Lightdir + viewdir); Float3 N = normalize (i.normal); float D = (_sp + 2)/8 * POW (dot (N, H), _s P)/4 * pie;float f = _sc + (1-_SC) *pow ((1-dot (H, Lightdir), 5), Float k = 2/sqrt (PIE * (_sp + 2)), float v = 1/(( Dot (n, lightdir) * (1-k) + k) * (dot (n, viewdir) * (1-k) + K); float all = D*f*v;float3 c = tex2d (_maintex, I.uv_maintex); fl OAT3 diff = Dot (lightdir, N);d iff = (1-all) *diff;return float4 (c * (Diff+all), 1)  * _LIGHTCOLOR0;}

_SC to specular color,_sp for specular power

distribution function of Phong
is the D value (NDF)
The cosθ value is the dot product of N and H, as follows, and H is the half-width vector, which is the light direct ray direction and half of the view direct view. α is the specular power for this function

This is the implementation curve of different specular power, the higher the height represents about rough, the lower the representation about the smooth
It's a good result.

The core code is as follows:

Float D = (_sp + 2)/8 * POW (dot (N, H), _sp)/(2*pie);

distribution function of Beckmann

secθ for 1/cosθ;

The curve is as follows

This curve is α value of 0.75, the local presence of 0 of 0, which is different from the Phong, making the uniform division of rough surface feasible

If more than 0.75 will appear above this should not occur, the local occurrence of the minimum value of approximately 0

This is the contrast between Beckmann and Phong (pink for Beckmann, blue for Phong)


The graph on the left is about the rough surface, both of which are about the same, and for the smooth surface of the right side, there are many differences.
The effect is as follows:


The main code is as follows:
                float cost = dot (N, H); float SecT = 1/cost;float d = Pow (E,-((1-pow (Cost, 2)) *pow (SecT, 4)/_ab)) *pow (SecT, 4)/(PI E*pow (_ab, 2));



distribution function of Trowbridge-reitz (GGX)

To implement the equation

The curves are as follows:

The left side is the case where the value of the parameter is low and the right side is a higher value
The left side is a bit like the Beckmann (the higher the rougher), the right side is like Beckmann appear the most rough place

This is a comparison with Phong.


The two are about the same, but the Trowbridge-reitz high place is sharp, the shorter the tail longer
The final comparison with the Phong.

The effect is as follows:



Personal feeling this is the second best way to effect

The core code is as follows:

float cost = dot (N, H), float d = Pow (_SP, 2)/(PIE *pow (1 + ( -1 + POW (_sp, 2)) *pow (cost, 2)), 2);


distribution function of shifted Gamma distribution
Yes, it's that long.
Both Alpha and gamma are externally controllable variables

The effect is as follows:

Personally think the best method of effect, controllable variable, out of the effect of more, but the feeling of calculation is very consumption AH
The code is as follows:
#define E 2.71828float4 Frag (v2f i): color{float3 Viewdir = normalize (I.viewdir); Float3 Lightdir = normalize (I.lightdir);  FLOAT3 H = normalize (Lightdir + viewdir); Float3 N = normalize (i.normal); float cost = dot (H, N); float SecT = 1/cost;float D = (Pow (E,-(_sp*_sp + (1-cost * cost) *sect *sect)/_sp) * POW (_SP,-1 + _tp) *pow (SecT, 4) *pow (_sp*_sp + (1-cost *c  OsT) *sect *sect,-_TP)/(PIE * _gm); float f = _sc + (1-_SC) *pow ((1-dot (H, Lightdir)), 5); float k = 2/sqrt (PIE * (_sp + 2)); float v = 1/((dot (n, lightdir) * (1-k) + k) * (dot (n, viewdir) * (1-k) + K)); float all = D*f*v;float3 c = tex2d (_ma InTex, I.uv_maintex); Float3 diff = Dot (lightdir, N);d iff = (1-all) *diff;return float4 (c * (diff + all), 1) * _lightcolor0 ;}




Finally put on a family photo


Reference:

1. Mathematica Notebook for the SIGGRAPH talk "Background:physics and Math of shading"

2. physicallybased Lighting in Call of Duty:black Ops


-----by wolf96 http://blog.csdn.net/wolf96


Unity3d based on physical rendering physically-based rendering specular BRDF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.