Unity3d shader real-time outdoor light scattering (atmospheric scattering) rendering

Source: Internet
Author: User
Tags cos

scattering needs: absorption, internal scattering, outer scattering
Divided into Rayleigh scattering Rayleigh scattering and Fermi scattering Mie scattering will be explained in detail later

Atmospheric scattering is caused by a variety of causes, particles, dust, water vapor, etc.

Sunlight is weakened and discolored due to scattering increase


Objects also weaken and discolor as the distance increases as the scattering increases.

Atmospheric light scattering changes due to time of day, weather, pollution change

scattering total entireradiometric quantities radiation measurements include:
Radiation Flux Radiant Flux
Radiation Rate Radiance
Irradiation degree irradiance


Radiation flux φ (Radiant flux)
Represents the amount of light emitted through the surface, the intensity of radiation (energy/Time), Unit: Watt

Emissivity L (Radiance)
represents a beam of light, radiant flux/area/stereo angle, Unit: w/(m2* spherical angle)


Degree of irradiance E

Represents the amount of light to a point on the surface , the incident radiation flux/area (watt/m2), and the radiation is concentrated into a hemispherical shape



Absorption area σab (absorption cross section)
Absorption radiation flux φ/e per irradiance, Unit: Area (m2)

Relationship between:
φ= E*σab
Σab =φ/E

Absorption coefficient βab (absorption coefficient)
Represents particle density ρab particle density, unit : Inverse Length (m-1)

Total absorption cross-sectional area:
Aab =σab *ρab * A *ds
A: Total Media area, ds: Media thickness

Probability of absorption:
Pab = aab/a =σab *ρab * ds =βab



Attenuation of light radiation through a fixed density absorbing medium:
L (s) = L0e-βab*s
S: Media thickness distance


External scatteringScattering sections ΣSC scattering cross section
Scattering particle density ΡSC
Scattering coefficient βscβsc =ρsc *σsc
Attenuation due to external reflection of medium in fixed density: L (s) = L0e-βsc*s


Light extinction extinction
The light that absorbs and the loss of the outer scattering is the extinction extinction
Extinction coefficient extinction Coefficientβex =βab +βsc
Total attenuation from extinction l (s) = l0e-βex*s--Fex (s) = E-βex*s


Internal scatteringThe scattering of light in all directions, from the sun, Sky, and earth, we only need to deal with the scattering from the sun.

Scattering phase function f (θ,?)
Most atmospheric particles are spherical or very small f (θ,?) = f (θ)
Use of f (θ):
Internal scattering probability: f (θ) *ωsun in-scatter probability
Internal scattering emissivity: f (θ) *ωsun*lsun = f (θ) * Esun
Θ is the angle between light direction and view direction

Inner scattering in the same path
Emissivity of one event: f (θ) * Esun
At the same scattering distance ds:f (θ) * esun*βsc*ds

Angular scattering
Angular scattering coefficient Angular scattering coefficientβsc (θ) =βsc*f (θ)
Internal scattering by DS distance: esun*βsc (θ) *ds
ΒSC (θ) units: m-1* steradian-1

Increase the emissivity of sunlight through a fixed density scattering medium
Lin (s,θ) = 1/βex * Esun *βsc (θ) * (1-e-βex*s)


extinction and internal scatteringL (s,θ) = L0fex (s) +lin (s,θ)

Contrast GPU Fog rendering
L (s,θ) = L0 (1-f (s)) +cfog*f (s)
Simple weight operation, the effect is not good


Rayleigh scattering Rayleigh scatteringTiny Particles (r<0.05λ)

Phase function:
Fr (θ) = 3/(16 * π) * (1+cos2θ)

Rayleigh scattering is a kind of M-scattering
When light travels through the atmosphere, the blue part of the atmosphere is strongly scattered, but Rayleigh scattering, such as red or yellow, is weak.
Because of the blue light scattering from the sky, the color of sunlight to the ground is yellow. In the sunrise and sunset, the Rayleigh scattering effect is more pronounced due to increased air density and particles near the Earth's surface.
By contrast, droplets compose clouds that are similar in wavelength to visible light and tend to be more prone to m-scattering rather than Rayleigh scattering. Assuming that all visible light wavelengths are roughly the same, the cloud appears to be white or gray.

Mie scattering by M-scatteringsmoke and clouds scatter large particles such as milk, biological tissue and latex paint
In cloudy weather The main is the Fermi scattering (water droplets)

Large particles in the medium of the Fermi scattering, which are spherical particles


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 anisotropic factor anisotropy factor


Wavelength correlation complexity depends on the size of the particle
In reality, air often contains a mixture of various sizes of Mie particles, in general any wavelength correlation tends to mean

Mixed Scatteringin reality, Rayleigh scattering and M-scattering in the air are
Normally, light is absorbed slightly.

Βex =βscrayleigh +βscmie

Summary and implementation
in shader:
Incoming parameters:
Βscrayleigh
Βscmie
Ghg
Constant:
E0sun
Esun Receive extinction extinction effect so not constant


The sun's energy reaches the ground and there will be decay.


Attention:

The initial sunlight at the beginning is white.

Density is not constant


Implement all of the required formulas:


Key part 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/(* PIE) *_be ta_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>

Achieve Results

Rayleigh scattering


Mie scattering

Mixed scattering


Reference:Rendering outdoor light scattering in Real time


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



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unity3d shader real-time outdoor light scattering (atmospheric scattering) rendering

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.