Unity3d shader Subsurface Scattering and unity3dsubsurface

Source: Internet
Author: User

Unity3d shader Subsurface Scattering and unity3dsubsurface
Subsurface scattering is a very common effect and can be used in many materials.
Such as skin, milk, cream cheese, tomato sauce, potatoes, etc.
 


The original intention was to create a milk shader, but then I simply studied sss.
This is the secondary surface scattering effect on vray.

 

This is the sub-surface scattering effect achieved in unity:


 





 
BRDF on the left (bidirectional reflection distribution) and BSSRDF on the right (bidirectional subsurface scattering reflection distribution)



 
The parameters are as follows:
S: BSSRDF result
Rd: the diffuse reflection of BSSRDF
Fr: freell reflection
Ft: freell transparency, transmission ratio
Fdr: the reflectivity of freell diffuse reflection
E: radiation direction
Given in Wiki: radiant fluence is the radiant energy powered ed by a surface per unit area, or equivalently the irradiance of a surface integrated over time of irradiation
Phi: irradiation energy per unit surface
Sigma A: Absorption Rate
Sigma S: scattering rate
Sigma T: Dissipation Rate
Sigma t': reduces the Dissipation Rate
Sigma TR: Effective Dissipation Rate
D: diffuse reflection constant
Alpha: Reflectivity
P: Phase Function
Eta: correlation index of reflection
G: Average cos value of the scattering angle
Q: source distribution value
Q0: 0th source distributions
Q1: 1st source distributions


Diffuse Reflection Approximation
The diffuse reflection approximation is based on the observation that the light source is highly dispersed and the light source distribution and the phase function are displayed to the opposite sex. Each scattering blur the distribution of light. As the number of scattering times increases, the distribution of light is more even.
This irradiation is similar to the radiation energy and radiation direction of a unit surface.

 



Phase functions of Henyey-Greenstein are used:
 
The constant is determined by the irradiation energy and irradiation direction on the surface of the unit.
An infinitely small light enters a media, and the incident energy decreases exponentially as it enters the depth of s.
Reduced strength:

 

<span style="font-size:14px;">float Lri(float3 w_P, float phi_x, float p_L_Dist, float D){float _Sigma_t = _Sigma_A + _Sigma_S;float L = 1 / (4 * PIE) * phi_x + 3 / (4 * PIE) * dot(w_P, -D*_Nabla * phi_x);float Lri = L * pow(E, -_Sigma_t* p_L_Dist);return Lri;}</span>



The first scattering reduces the intensity and is processed as a volume source.

for (int i = 0; i < 30; i++){w_P = normalize(float3(N.x + rand(fixed2(i*0.05, i*0.05)), N.y + rand(fixed2(-i*0.05, i*0.05)), N.z + rand(fixed2(i*0.05, -i*0.05))));//float3 w_P = normalize(float3(lightDir.x + rand(i.uv_MainTex + fixed2(i*0.01, i*0.01)), lightDir.y + rand(i.uv_MainTex + fixed2(-i*0.01, i*0.01)), lightDir.z + rand(i.uv_MainTex + fixed2(i*0.01, -i*0.01))));Q += phase(dot(lightDir, w_P))*Lri(w_P, phi_x, p_L_Dist, D);Q *= _Sigma_S;Q1 += Q*w_P;}

30 random light scattering directions

This equation is useful for observing the Propagation Behavior of light in a volume.
 
This equation is related to the radiation scalar or flux.
 
 
0th and first source distribution formulas
 
 
Sigma parameters are mutually exclusive,
The light changes to the opposite sex, and the backward scattering relationship changes the net pass. There is no difference between forward scattering and non-scattering.
Here D = 1/(3 * sigma_T '); is a diffuse reflection constant
Finally, we get the diffuse reflection formula.
 
 

The formula for deriving the diffuse reflection part is as follows:

 
30 random light scattering directions are added to the set point, and the effect is not bad.
The reflection part of the diffuse reflection is then the reflection part of the diffuse reflection.
The freell reflection formula indicates the reflection of the fresh diffuse reflection in the conducting medium:
 
The nature of the media itself varies with reflectors. Eta is the correlation index of this nature.
 
This is the reflectivity measured accurately. We can use this formula to avoid computing consumption.

Formula:

 
Dr = | x-xr | distance between the current vertex and the light source
Dv = | x-xv | distance between the current point and the eye (CAMERA)
if (_WorldSpaceLightPos0.w != 0){p_L_Dist = distance(_WorldSpaceLightPos0, i.worldPos);}float v_C_Dist = distance(_WorldSpaceCameraPos, i.worldPos)*0.3;


φis the light source strength
Finally, our reflection formula is

 

<span style="font-size:14px;">float3 ref = -D * (dot(N, _Nabla*phi_x_S)) / (diff*_LumPow_D);</span>


Add the specular of Physically-Based Rendering at the end.


Parameter Adjustment about parameter adjustment, the parameter is very difficult to tune, pdf and self-made parameters do not match, you can only tune it yourself
 

 

Final effect:










Refer:

1. A Practical Model for Subsurface Light Transport

2. A Measurement-Based Skin Re processing ectance Model for Face Rendering and Editing



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


Related Article

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.