Unity3d shader: Real-Time outdoor light scattering (atmospheric scattering) Rendering, unity3dshader

Source: Internet
Author: User

Unity3d shader: Real-Time outdoor light scattering (atmospheric scattering) Rendering, unity3dshader
Scattering needs: absorption, internal scattering, and external Scattering
It can be divided into Ruili Scattering, rayscattering and Mie Scattering, which will be explained in detail later.

Scattering in the atmosphere is produced by various reasons, such as particles, dust, and water vapor.

Sunlight degrades and changes color due to increased scattering.
 

The object will also fade and change color as the distance increases and the scattering increases.
 
Atmospheric light scattering changes due to changes in time, weather, and pollution during the day.

Radiometric Quantities radiation measurement includes:
Radiant Flux
Radiance
Radiation Irradiance


Radiant Flux)
Represents the amount of light passed through the surface, the radiation intensity (ENERGY/time), unit: Watt

Radiance)
Represents the light volume of a bunch of light, the radiation flux/area/three-dimensional angle, unit: watt/(m² * spherical angle)


Radiation E

Represents the amount of light to a point on the surface. The incident radiation flux/area (W/m²) forms a hemisphere in the radiation set.



Cross-sectional area σ AB (Absorption cross section)
The absorption radiant flux of each radiation intensity (PHI/E). Unit: Area (Mbit/s)
 
Relationship:
Phi = E * σ AB
σ AB = PHI/E

Absorption coefficient β AB (Absorption coefficient)
Representing the Particle density P AB Particle density, unit: m-1)

Total absorption cross-sectional area:
Aab = σ AB * P AB * A * ds
A: total media area, ds: Media Thickness

Probability of absorption:
Pab = Aab/A = σ AB * P AB * ds = beta AB

 

Attenuation of Light Radiation passing through a fixed density absorption medium:
L (s) = L0e-β AB * s
S: media thickness distance
 

Scattering cross section σ SC Scattering
Scattering Particle density P SC
Scattering coefficient β SC = P SC * σ SC
Attenuation Caused by external reflection in fixed density media: L (s) = L0e-β SC * s
 

Extinction
The light loss caused by absorption and external scattering is the Extinction.
Extinction coefficient β ex = beta AB + BETA SC
Total attenuation produced by extinction L (s) = L0e-β ex * s --> Fex (s) = e-β ex * s


Scattering of light from all directions in the angle of view from the sun, the sky, and the earth. We only need to process the scattering from the sun.

Scattering phase function f (θ, cosine)
Most atmospheric particles are spherical or very small f (θ, θ) = f (θ)
F (θ) Purpose:
Inner scattering probability: f (θ) * ω sun In-scatter probability
Inner scattering radiation rate: f (θ) * ω sun * Lsun = f (θ) * Esun
θ is the angle between light and view
 
Scattering in the same path
Radiation rate of an event: f (θ) * Esun
In the same scattering distance ds: f (θ) * Esun * β SC * ds

Angle Scattering
Angular scattering coefficient β SC (θ) = β SC * f (θ)
Scattering by ds distance: Esun * β SC (θ) * ds
Units of β SC (θ): m-1 * steradian-1

Increase the radiation rate of sunlight passing through fixed-density scattering Media
Lin (s, θ) = 1/β ex * Esun * β SC (θ) * (1-e-β ex * s)
 

Extinction and inner scattering L (s, θ) = L0Fex (s) + Lin (s, θ)

Comparison of GPU fog Rendering
L (s, θ) = L0 (1-f (s) + Cfog * f (s)
Simple weight calculation, poor performance


Ruili Scattering, rayscattering, particle size (r <0.05 λ)

Phase function:
Fr (θ) = 3/(16 * π) * (1 + cos ² θ)
 
Fourier scattering is a type of M-scattering.
When the light passes through the atmosphere, the blue part of the gas in the atmosphere is strongly scattered, but the long red or yellow wave of the red is very weak.
The blue light from the sky is scattered, and the colors from the sun to the ground are yellow. In sunrise and sunset, due to the increase in air density and the particles near the earth's surface, the scattering effect is more obvious.
In contrast, the wavelength of water droplets in clouds is similar to that in visible light, and it is more likely to be m scattering rather than Ar scattering. Assuming that the wavelength distribution of all visible light is roughly the same, the cloud looks white or gray.

Mi's Scattering Mie Scattering smoke and cloud Scattering of large particles such as milk, biological tissue and latex paint
In multi-cloud weather, the main factor is M's scattering (water drops)

The particle size in the medium where M scattering occurs is a spherical particle.


We use the Henyey-Greenstein function to approximate the phase function:
FHG (θ) = (1-g) 2/(4 * π * (1 + g2-2g * cos (θ) 3/2
G is the anisotropy factor


The complexity of wavelength correlation depends on the particle size.
In reality, the air often contains a mixture of all kinds of micron particles, and in general, any wavelength correlation tends to mean

In the mixed scattering reality, both the Repear scattering and the meter scattering in the air have
Generally, light absorption is mild.

β ex = β scray+ β scMie

 

Summary and implementation
In the shader:
Input parameters:
β sclei
β scMie
GHG
Constant:
E0sun
Esun receives the influence of the extinction, so it is not a constant.


When sunlight is transmitted to the ground, there will be attenuation.

 


Note:

The original sunlight at the starting point is white.

Density is not a constant


All Formulas Required for implementation:


Key implementation code:

<span style="font-size:14px;">float s = (GetDepth(i.uv_MainTex)-0.8)*5;float Fex = pow(e, -(_Beta_R + _Beta_M)* s);float beta_r = 3 / (16 * PIE)*_Beta_R*(1 + cos_theta* cos_theta);float beta_m = 1 / (4 * PIE) * _Beta_M * (1 - _G)*(1 - _G) / pow((1 + _G * _G - 2 * _G*cos_theta), 3 / 2);float3 Lin = (beta_r + beta_m) / (_Beta_R + _Beta_M)* _Sun * (1 - pow(e, -(_Beta_R + _Beta_M)* s));float3 L = _Sun * Fex + color.rgb *Lin;</span>

Implementation result

Ruili Scattering


Meters Scattering

Hybrid Scattering


Reference: Rendering Outdoor Light Scattering in Real Time

 

 

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

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.