Advanced search tips: use spaces to require multiple terms (AND), | for alternatives (OR), wrap phrases in quotes (="a b"), =term for exact match, 'term to include, !term to exclude, ^term to match prefix, !^term to exclude prefix, .ext$ to match suffix, and !.ext$ to exclude suffix.

functions.wgsl

Import path

Constants

FRAC_PI

#
const FRAC_PI: f32 = 0.3183098862

FRAC_2_PI

#
const FRAC_2_PI: f32 = 0.15915494309

FRAC_3_16_PI

#
const FRAC_3_16_PI: f32 = 0.0596831036594607509

FRAC_4_PI

#
const FRAC_4_PI: f32 = 0.07957747154594767

ROOT_2

#
const ROOT_2: f32 = 1.41421356

MIDPOINT_RATIO

#
const MIDPOINT_RATIO: f32 = 0.3

SUN_ANGULAR_SIZE

#
const SUN_ANGULAR_SIZE: f32 = 0.0174533

Structures

AtmosphereSample

#
struct AtmosphereSample {
rayleigh_scattering: vec3<f32> ,
mie_scattering: f32 ,
extinction: vec3<f32> ,
}

Functions

unit_to_sub_uvs

#
fn unit_to_sub_uvs (
resolution: vec2<f32>
) -> vec2<f32>

sub_uvs_to_unit

#
fn sub_uvs_to_unit (
resolution: vec2<f32>
) -> vec2<f32>

multiscattering_lut_r_mu_to_uv

#
fn multiscattering_lut_r_mu_to_uv ( ) -> vec2<f32>

multiscattering_lut_uv_to_r_mu

#
fn multiscattering_lut_uv_to_r_mu ( ) -> vec2<f32>

sky_view_lut_r_mu_azimuth_to_uv

#
fn sky_view_lut_r_mu_azimuth_to_uv (
azimuth: f32
) -> vec2<f32>

sky_view_lut_uv_to_zenith_azimuth

#
fn sky_view_lut_uv_to_zenith_azimuth ( ) -> vec2<f32>

sample_transmittance_lut

#
fn sample_transmittance_lut ( ) -> vec3<f32>

sample_transmittance_lut_segment

#

FIXME: this function should be in bruneton_functions.wgsl, but because naga_oil doesn’t support cyclic imports it’s stuck here

fn sample_transmittance_lut_segment ( ) -> vec3<f32>

sample_multiscattering_lut

#
fn sample_multiscattering_lut ( ) -> vec3<f32>

sample_sky_view_lut

#
fn sample_sky_view_lut (
ray_dir_as: vec3<f32>
) -> vec3<f32>

ndc_to_camera_dist

#
fn ndc_to_camera_dist ( ) -> f32

sample_aerial_view_lut

#

RGB channels: total inscattered light along the camera ray to the current sample. A channel: average transmittance across all wavelengths to the current sample.

fn sample_aerial_view_lut ( ) -> vec3<f32>

rayleigh

#

evaluates the rayleigh phase function, which describes the likelihood of a rayleigh scattering event scattering light from the light direction towards the view

fn rayleigh (
neg_LdotV: f32
) -> f32

henyey_greenstein

#

evaluates the henyey-greenstein phase function, which describes the likelihood of a mie scattering event scattering light from the light direction towards the view

fn henyey_greenstein (
neg_LdotV: f32
) -> f32

sample_atmosphere

#

Samples atmosphere optical densities at a given radius

fn sample_atmosphere ( ) -> AtmosphereSample

sample_local_inscattering

#

evaluates L_scat, equation 3 in the paper, which gives the total single-order scattering towards the view at a single point

fn sample_local_inscattering (
local_atmosphere: AtmosphereSample
ray_dir: vec3<f32>
local_r: f32
local_up: vec3<f32>
) -> vec3<f32>

sample_sun_radiance

#
fn sample_sun_radiance (
ray_dir_ws: vec3<f32>
) -> vec3<f32>

max_atmosphere_distance

#
fn max_atmosphere_distance ( ) -> f32

view_radius

#

Assuming y=0 is the planet ground, returns the view radius in meters

fn view_radius () -> f32

get_local_up

#

We assume the up vector at the view position is the y axis, since the world is locally flat/level. t = distance along view ray in atmosphere space NOTE: this means that if your world is actually spherical, this will be wrong.

fn get_local_up (
ray_dir: vec3<f32>
) -> vec3<f32>

get_local_r

#

Given a ray starting at radius r, with mu = cos(zenith angle), and a t = distance along the ray, gives the new radius at point t

fn get_local_r ( ) -> f32

uv_to_ndc

#

Convert uv [0.0 .. 1.0] coordinate to ndc space xy [-1.0 .. 1.0]

fn uv_to_ndc ( ) -> vec2<f32>

ndc_to_uv

#

Convert ndc space xy coordinate [-1.0 .. 1.0] to uv [0.0 .. 1.0]

fn ndc_to_uv ( ) -> vec2<f32>

direction_world_to_atmosphere

#

Converts a direction in world space to atmosphere space

fn direction_world_to_atmosphere ( ) -> vec3<f32>

direction_atmosphere_to_world

#

Converts a direction in atmosphere space to world space

fn direction_atmosphere_to_world ( ) -> vec3<f32>

uv_to_ray_direction

#

Modified from skybox.wgsl. For this pass we don’t need to apply a separate sky transform or consider camera viewport. w component is the cosine of the view direction with the view forward vector, to correct step distance at the edges of the viewport

fn uv_to_ray_direction ( ) -> vec4<f32>

zenith_azimuth_to_ray_dir

#
fn zenith_azimuth_to_ray_dir (
zenith: f32
azimuth: f32
) -> vec3<f32>