Http://www.cnblogs.com/zhouxin/p/5168632.html
This article mainly introduces Untiy5 after the GI,PBS, as well as the light source probe, the use of reflection probe and how to play a role in the shader code, GI is how to affect the rendering, mainly divided into three parts, the first to explain the need for PBS material and the corresponding concept, the second is unity in the corresponding GI operation, Third, the corresponding shader code understanding. If there is no special declaration, all operations and code are for Unity5.3.
PBS Materials and concepts
Simply put, PBS has the advantage of having a consistent look under different lighting, easier to implement, and more intuitive parameters.
PBS Material concept: 1.albedo albedo
The albedo map defines the basic color of the diffuse reflection, which does not contain directional light and AO, compared to the original diffuse map, where we should be influenced by the environment's own directed light and AO, in unity we use GI to get the corresponding baking or real-time directional light and AO.
2.smoothness/microsurface detail smoothness of surface detail material
Smoothness: A parameter describing the surface of an object that can be used to define the normal distribution function, so that the rough surface is wide, light specular, smooth and bright specular reflection.
3.metal/reflectivity Metallic/Reflective
Metal and insulators should use different reflection settings, the reflectivity of the conductor 60-90%, the insulator 0-20%, the high reflection light molecule is not easy to reach the interior and scattering, so the high performance of the metal is relatively light.
The following global settings:
For fixed materials, the reflectivity tends to stabilize, so generally, a model of the metal relatively little change, such as mud, water, wood these their reflectivity is not small, only the metal and insulation experience has a relatively large contrast, and the roughness of the model surface should be shown above the smoothness of the figure, This relative change will be larger, such as the water and soil have similar metal (reflectivity), but the smoothness of the difference between the larger, so the difference is obvious.
From Pbr-theory:http://www.marmoset.co/toolbag/learn/pbr-theory
Things in unity, metallic maps, metal properties occupy R channels, smoothness occupies a channel, GB is ignored.
The original color of the object is expressed in albedo, the smoothness is expressed with smoothness, the material properties are represented by metal, wherein unity two PBS standard coloring, the higher the metal, the higher the mirror color ratio, the lower the color of the light, High light can set its own specular reflection.
Ps:pbr-practice Http://www.marmoset.co/toolbag/learn/pbr-practice
BRDF Illumination Model Concept 1 conservation of energy: an object cannot reflect more light than he receives.
Rough materials have more light highlights, and smooth materials have more concentrated, brighter bright spots, can also be understood, the more diffuse reflection, the less specular reflection, more specular reflection, less diffuse reflection.
2 Fresnel Effect: The reflection on the edge is brighter.
More specific can be seen: http://filmicgames.com/archives/557
3 micro-surface Model model:
The normal shading model assumes that the shaded area is a smooth surface with a normal surface, while the surface is considered to be a rough area with countless tiny surfaces that are smaller than the coverage of the incident light, a tiny surface that is smooth specular reflection. The effect of fine surface details on diffusion, the more coarse the surface, the more diffuse or blurred reflected light.
GI Combined BRDF rendering
GI global illumination refers to the global illumination that simulates the light's multiple reflections in the scene, all of which are a potential source of light, any visible model not radiating light, or reflected light, where GI (the rendering of indirect light sources, itself is usually rendered with BRDF) with BRDF generated with direct light, Realistic scenarios in which the models in the environment want to influence each other.
The Sky Box is part of the GI, reflecting the sky box can change the scene all models accept the reflected amount.
GI combined with PBS, as below, the camera lens is the same material in different environments:
In more detail, you can click this link: http://docs.unity3d.com/Manual/shader-StandardShader.html
GI Operation:
Global illumination is characterized by the ability to capture indirect illumination, so after 5, except for the original direct light effect, increase the effect of indirect light, simply speaking, is a light source, and then the model itself as a source, radiation to other models, the effect of layer recursion. Now whether the predicted real-time gi or baking gi is only for static models. It is expected that the intensity and reflection intensity of the real-time light source of the GI and the corresponding baking light source will influence the content of the radiation map and the direction map. It is important to note that the estimated GI is for real-time directional light, while the baking GI is for the baking direction light.
Global lighting
Skybox: Sky box, reference material Skybox/cubemap, if the global light and global reflection probe are selected Skybox mode, then Skybox as a Cubemap, all models of the scene, static and non-static part of the light source from this Cubemap reflection.
Sun:skybox Select a direction light, in this direction light direction of direction, the direction of light such as color and intensity does not affect the global itself, if not set direction light, choose the most intensity of the direction of the light source.
Ambient Source: Global Light, if the sky box is set, but the sky box itself is not set, automatically select the following global color settings, global reflection probe to Ambient source as a light source.
Ambient Intensity: The global light intensity, the higher the brighter, the 0 o'clock, the light source does not work.
Ambient GI: When the estimated GI and baking gi two are selected, this can be selected in real-time or baked.
Reflection source:unity The global reflection probe that is placed by default, the selection Skybox is reflected in the light source color provided in the ambient source, as well as cubemap as a reflection source.
Resolution: Reflection probe resolution should be the resolution of the CubeMap six-sheet texture corresponding to the RTT.
Compression: whether to compress.
Reflection Intensity:reflection Source reflects the intensity of all models, the greater the value, the clearer the Reflection source appears on the corresponding model surface.
Reflection bounces: When multiple Reflection probe are set, the number of times each other's information is reflected, such as a two-face mirror.
GI Settings precomputed Realtime gi
Estimated real-time GI, for real-time static objects between the radiation, so the corresponding radiation map and direction map are low-resolution. The dynamic object can use the illumination probe to obtain the corresponding reflective light source information, and note the distance between the dynamic model and the light probe.
Realtime Resolution: Estimated real-time gi, divides the scene into many lattices, and gets the radiation information of each lattice. The higher the value, the more the calculation will be squared, and the final value will be multiplied by the resolution in the light source parameter in general GI.
CPU Usage: How much CPU computing power is allocated when the game is running when the corresponding GI data is generated.
Baked GI
Bake gi, so that you can get more accurate reflection light information between models, but can not be run when changing the corresponding light source information, such as color, direction, estimated real-time GI no this problem.
Baked Resolution: Generally speaking, is realtime Resolution, because the corresponding radiation map and direction map accuracy is much higher.
Baked Padding: Online says is the distance that is separated in the illumination map, also need to verify.
Compressed: Whether to compress
Ambient occlusion: The higher the value, the greater the light difference from the occlusion area.
Final Gather: Using FG technology to produce baking data, this technology has a long time to grow. Reference http://blog.sina.com.cn/s/blog_46c56d9a0100gqbv.html
Ray Count:final the number of ray-traced rays used by the gather.
Atlas Size: The size of the map in the map, the lower the actual occupation of the more accurate is the smaller, but the more the map produced, you should choose a suitable size.
General GI
Predict whether real-time GI or baking can be generated.
Direction Mode: Radiation map/with directional light/plus mirror, specifically see shader analysis, which is expected to calculate real-time gi and baking gi in this generated corresponding radiation map, direction map, etc., will be mentioned later.
Indirect Intensity: Intensity of indirect light.
Default Parameters: The information required to generate the corresponding map.
Where the global expected to calculate the GI, baking gi, global reflection probe corresponding changes need to be re-baked, if selected automatically, the relevant changes will be automatically baked in the background.
Above these to tell the truth, write this operation no use, oneself to each practice one article, what all clear.
Light Probe:
For GI, whether it is expected to calculate the GI and baking gi, not to the non-static model calculation of indirect reflection, light probe addition, you can make the non-static model of the surrounding static model of the radiation, the main technical principle of using a spherical harmonic illumination technology, note light probe generally do not affect the static model, The effect you see is only due to the contrast of the non-static model of the color variation caused by large.
Related spherical harmonic illumination technical principle can see, I also do not understand, can only say look after a bit of impression is how to go:
Spherical harmonic Illumination (upper)
http://www.yasrt.org/shlighting/
Http://www.cppblog.com/init/archive/2012/09/19/191182.html
A 2D Fourier series of spherical generalization, the light function can be expanded into a superposition of SH-based functions, similar to the Fourier transform can be any function to expand into a sine wave superposition, for the light map is generally used only 2 bands = 4 RGB textures, by the loss of high-frequency details to compress the storage.
Reflection Probe:
Defines a cubemap used to influence the specular reflection of the surrounding model for specular highlight models.
In general, we want a real-time scene of the CubeMap, just at a point, with the camera front and back, around, up and down, each shot, forming 6 faces, combined into a cubemap.
Type: Baking, user, automatic. Among them, baking is the user to control the generation of a current scene cubemap, the user is the user to provide a cubemap, real-time is constantly updating this cubemap to map the latest scene.
When selecting real-time, Refresh Mode:on awake start, each frame, user script control, when each frame, the following selection.
Time slicing: A frame of 6 faces, the back 8 frames per frame to generate a mipmap, altogether 9 frames.
Individual Face:6 face 6 frame, plus the back 8 frames each mipmap, altogether 14 frames.
No time slicing: A frame inside the mipmap and cubemap all generated.
Importance: When multiple reflection transducers affect a model, this parameter affects the specific gravity of the reflective probe.
Intensity: Indirect light intensity, intensity affects specular reflection, specular reflection brighter.
Box Projection: Judging from the coloring code, the original normal of the model should be influenced by the source point and aabb of the current reflection probe.
Size: sizes, in-range models use this.
Probe Origin: Origin.
Cubemap Capture Sttings:
Resolution:cubempa the size of the material.
HDR: High light.
Shadow Distance: Shadow distance, the lower the number, the closer the shadow.
Below is the properties of the RTT corresponding to the camera.
GI Indirect light source algorithm: radiometric algorithm
The radiometric algorithm is to subdivide the scene into very fine, thin patches (such as 1-pixel-large triangles), calculate the light energy they receive and emit separately, and then recursively, until the light data of each patch no longer changes (or to a certain threshold). Therefore, the computation is very large (many times to be counted), and it is difficult to parallel ( Because of recursion), refer to Http://blog.sina.com.cn/s/blog_537cc4d90101iiil.html
In Unity, GI chooses the non-direction mode to generate the irradiance, using a graph that stores the indirect illumination received at each location, assuming that it is only diffused, without specular reflection.
GI directional Lightmap algorithm:
The incident emissivity of the hemispherical surface is sampled by some method, which is saved to be synthesized at run time according to the normal direction of the normal map, and because of the direction information, it can also support the high-light calculation, can refer to: http://www.fseraph.com/?p=193
Unity in the GI Select direction model, will be in the above radiation map to add a picture, used to store the direction of the received light selection specular, baking gi and precomputed gi use a different way, baking gi in the above two map each enlarged one times, the original preservation of direct light effect, The newly added position is used to preserve the effects of indirect light, which is estimated to be a new addition to the GI map, three images to save radiation illumination, light source direction, normal, need to combine real-time directional light source.
Ps:
Explore global Illumination (enlighten) in Unity5 http://unity.jb51.net/meigongsheji/Unitymeihua/18.html
Unity 5.0 new features teaching: http://tieba.baidu.com/p/3690939628
Global lighting Technology in Unity 5 detailed http://www.cocoachina.com/game/20150701/12339.html
UNITY5 official website Document GI three different modes specific differences http://docs.unity3d.com/Manual/LightmappingDirectional.html
Unity GI BRDF Shader
The main references are as follows shader file:
Unitystandardcore.cginc: Forward render base, vertex shader entry vertforwardbase, fragment coloring entry fragforwardbase, this is the main pass of the shader, global directional light, The GI information merge is in this pass.
UnityStandardBRDF.cginc:BRDF of the concrete implementation.
Unitygloballllumination.cginc: Extract GI information, including baking with GI and precomputed gi.
Expected to calculate the GI is directed to the real-time direction of light, and baking gi for the baking direction of light, so when said to calculate the light of the GI, refers to the real-time directional lights, and baking gi light is said to be the direction of baking.
BRDF GI
The entire code is not much, but for all of the above, there is a complete explanation, this code to tell us, those metal, smoothness, GI radiation map, direction map, as well as the light source probe, reflective probe function.
BRDF Illumination Model: The following are issues that are not considered in the existing lighting model:
Light phenomenon, diffuse reflection is not the average divergence in all aspects. ----Micro-surface model (NDF).
Fresnel theorem (Fresnel)----light sources have brighter reflections at the corners.
Energy is conserved, and the reflected light cannot exceed the incident light. ----occlusion factor, the smoother the mirror the more concentrated the brighter
The normal shading model assumes that the shaded area is a smooth surface with a normal surface, while the surface is considered to be a rough area of countless tiny surfaces that are smaller than the coverage of the incident light, which is a smooth specular reflection because the shaded area does not have a normal vector to represent the direction of the surface. The turn surface is represented by a probability distribution function (NDF). In general, they are indicated by the following letters:
D is used to represent the normal distribution.
F for Fresnel effect, the light source has brighter reflections at the corners.
G/v used to denote occlusion between concave and convex surfaces (unity is represented by V)
The following is the handling of unity's relative BRDF
The first explanation is that each engine is different from the BRDF processing, which only describes the implementation of Untiy:
D using GGX and Blinnphong two kinds of normal distribution functions, blinnphong relatively simple, high efficiency.
F uses a simplified Disney Fresnel method to derive Fresnel effects.
G/v using the GGX and Beckmann two techniques, you can see that the smoothness is a key parameter.
For Unity5.3 simplified Disney Fresnel, simple analysis.
Nl: The angle between the normal and the light, the greater the angle, the smaller the value.
Nv: The angle between the normal and the line of sight, the greater the angle, the smaller the value.
Lh: The angle between the light and the line of sight and the normal, where the light and the half line of sight is the average line of light and sight, in short, this line is coincident with the normal, this light emitted by the ray to enter our glasses.
Assuming that the fd90 is unchanged, the greater the angle of NL and NL, the greater the value of nlPow5 and nvPow5, the greater the final result, which is also Fresnel to express, the light source in the corner has a brighter reflective.
In unity, you can see that D and V affect specular reflection, and f affects diffuse, in particular, unity is the only way to handle it.
One can see that the reflectivity (i.e., metal) affects the specular reflection of the GI, which is the reflective probe.
The rest of the sections pick out the instructions below:
In the vertex shader, fill in the Vertexoutputforwardbase information, where AMBIENTORLIGHTMAPUV (HALF4) contains the baking gi,xy to fill the UV coordinates of the corresponding baking GI, if it contains the precomputed gi, ZW fills the UV coordinates for the precomputed gi. If the non-static model does not contain GI information, the light source information provided by the probe is placed in RGB.
Fragment shader, each pixel to get unity GI information on the corresponding pixel, the corresponding, Unity GI attribute light is not the source, but the current pixel is affected by such as the main light source, radiation, mirror to the current pixel influence, each pixel corresponds to a difference Do not see the writing is a light, it as lighting, so that all the understanding is wrong.
If only bake gi, the current pixel unity GI parameter light does not provide information, the diffuse reflection in the indirect contains the lighting of the baking light source. While the estimated light of the current pixel in the GI is itself a global light source, the indirect only contains diffuse information between objects, but not the direct illumination information of the current pixel in the static model, only the real-time light, and the reflection of the static model around it only obtains SH information through the optical probe.
Common structures in FRAGMENTGI:
1 Unitylight:
Contains the light source color, direction, normal and light direction dot product of the current pixel
2 Unityindirect:
Contains diffuse diffuse, specular specular information in the current pixel
3 Unitygi: In particular, the light inside is the unitylight type and does not represent the source, but is used to indicate how much the current pixel is affected by the light.
Gi.light if you bake with GI information, fill the unitylight with the current main light source, and if you have baked with GI information, the fill is empty.
Gi.light2 is called when baking GI is enabled for high light.
GI.LIGHT3 is expected to be called after the GI is enabled for high light.
Unitygi is filled according to the function unityglobalillumination, we can analyze and get the dynamic model, using SH to get the diffuse information. If there is no baking gi, we need a real-time global light source, so gi.light is the global directional light that the pixel is subjected to. The baking gi,gi illumination information is stored in gl.light2, and the GI diffuse reflection directly takes the diffuse in the illumination map. Estimated Gi,gi illumination information is stored in GL.LIGHT3, GI diffuse reflection adds diffuse to the light map. The reflective probe is used to add reflective information to the mirror information in the GI, where occlusion controls the diffuse and specular coefficients of the GI. (n*=occlusion)
Which unity_should_sample_sh the current rendering of the dynamic model, using SH to obtain indirect diffuse information, where unity_should_sample_sh as defined below. #define UNITY_SHOULD_SAMPLE_SH (defined (lightmap_off) && defined (Dynamiclightmap_off))
Estimated GI and baked gi
Baking GI above code analysis, choose Non-direction, only a picture, save direct and indirect illumination all information, choose direction After, will save the direction, select Specular, the above two picture, the length expands one times, save the Mirror information.
Which is expected to calculate the GI, choose Non-direction, only a picture, do not save direct lighting, only save indirect lighting, select direction, save direction, choose Specular, different from baking gi, will add a texture to save the mirror information (from the code to see, May be an organized normal)
Reflective probe:
The unity_speccube0_ global reflection probe Unity_speccube1_ the reflected probe that is affected by the current model.
FRAGMNETGI: Get the global reflection probe with user-defined reflection probe position, AABB,ISHDR.
Unityglobalillumination: The reflection probe in the fragment pixel affects the specular value, and you can see that the SPECCUBE0 and SpecCube1 affect the specular color on the GI indirect light source by depth.
Boxprojectedcubemapdirection: Affects the Worldnormal (reflection after the anti-gaze has entered the normal)
Unity_glossyenvironment: As you can see, the smoothed values affect the LOD values, and the smoother the clearer the more. Unity_sample_texcube value from CubeMap.
Light source probe:
Vertforwardbase:vertexoutputforwardbase AMBIENTORLIGHTMAPUV Set the color, from which you can see that the light source probe actually does not affect the static object, if you see an effect, Just because the color contrast around the non-static model gives you the effect.
Unityglobalillumination: The value of the light probe is assigned to the diffuse reflection on the GI indirect light source.
Ps:
Physical coloring based (i) Physical coloring (ii) based on physical coloring (iii)
Disney this principled BRD
Wiki BRDF
In-depth understanding of standard Shader in Unity5 (iii)
Unity3d based on physical rendering physically-based rendering specular BRDF
2016/2/1: Look at the environmental reflection document in UE4 today, I go, Unity's approach is entirely reference to UE4, through the shader code above, we can fully understand the following link is said.
Environmental reflection in the UE4
Unity5 GI vs. PBS rendering from usage to coloring code