Back home 🏡 WGSL Spec Bevy WGSL Functions

tonemapping_shared.wgsl

Import path

Constants

Name Type Value
LEVEL_MARGIN # f32 0.1
LEVEL_MARGIN_DIV # f32 0.5 / LEVEL_MARGIN
TONY_MC_MAPFACE_LUT_DIMS # f32 48.0

Functions

sample_current_lut

#
fn sample_current_lut(p: vec3<f32>) -> vec3<f32>
Parameter Type
p vec3<f32>
Returns: vec3<f32>

rgb_to_ycbcr

#
fn rgb_to_ycbcr(col: vec3<f32>) -> vec3<f32>
Parameter Type
col vec3<f32>
Returns: vec3<f32>

ycbcr_to_rgb

#
fn ycbcr_to_rgb(col: vec3<f32>) -> vec3<f32>
Parameter Type
col vec3<f32>
Returns: vec3<f32>

tonemap_curve

#
fn tonemap_curve(v: f32) -> f32
Parameter Type
v f32
Returns: f32

tonemap_curve3_

#
fn tonemap_curve3_(v: vec3<f32>) -> vec3<f32>
Parameter Type
v vec3<f32>
Returns: vec3<f32>

somewhat_boring_display_transform

#
fn somewhat_boring_display_transform(col: vec3<f32>) -> vec3<f32>
Parameter Type
col vec3<f32>
Returns: vec3<f32>

sample_tony_mc_mapface_lut

#
fn sample_tony_mc_mapface_lut(stimulus: vec3<f32>) -> vec3<f32>
Parameter Type
stimulus vec3<f32>
Returns: vec3<f32>

RRTAndODTFit

#
The code in this file was originally written by Stephen Hill (@self_shadow), who deserves all
fn RRTAndODTFit(v: vec3<f32>) -> vec3<f32>
Parameter Type
v vec3<f32>
Returns: vec3<f32>

ACESFitted

#
fn ACESFitted(color: vec3<f32>) -> vec3<f32>
Parameter Type
color vec3<f32>
Returns: vec3<f32>

saturation

#
Increase color saturation of the given color data. :param color: expected sRGB primaries input :param saturationAmount: expected 0-1 range with 1=neutral, 0=no saturation. -- ref[2] [4]
fn saturation(color: vec3<f32>, saturationAmount: f32) -> vec3<f32>
Parameter Type
color vec3<f32>
saturationAmount f32
Returns: vec3<f32>

convertOpenDomainToNormalizedLog2_

#
Output log domain encoded data. Similar to OCIO lg2 AllocationTransform. ref[0]
fn convertOpenDomainToNormalizedLog2_(color: vec3<f32>, minimum_ev: f32, maximum_ev: f32) -> vec3<f32>
Parameter Type
color vec3<f32>
minimum_ev f32
maximum_ev f32
Returns: vec3<f32>

convertNormalizedLog2ToOpenDomain

#
Inverse of above
fn convertNormalizedLog2ToOpenDomain(color: vec3<f32>, minimum_ev: f32, maximum_ev: f32) -> vec3<f32>
Parameter Type
color vec3<f32>
minimum_ev f32
maximum_ev f32
Returns: vec3<f32>

applyAgXLog

#
Prepare the data for display encoding. Converted to log domain.
fn applyAgXLog(Image: vec3<f32>) -> vec3<f32>
Parameter Type
Image vec3<f32>
Returns: vec3<f32>

applyLUT3D

#
fn applyLUT3D(Image: vec3<f32>, block_size: f32) -> vec3<f32>
Parameter Type
Image vec3<f32>
block_size f32
Returns: vec3<f32>

sample_blender_filmic_lut

#
fn sample_blender_filmic_lut(stimulus: vec3<f32>) -> vec3<f32>
Parameter Type
stimulus vec3<f32>
Returns: vec3<f32>

tonemapping_reinhard

#
from https://64.github.io/tonemapping/ reinhard on RGB oversaturates colors
fn tonemapping_reinhard(color: vec3<f32>) -> vec3<f32>
Parameter Type
color vec3<f32>
Returns: vec3<f32>

tonemapping_reinhard_extended

#
fn tonemapping_reinhard_extended(color: vec3<f32>, max_white: f32) -> vec3<f32>
Parameter Type
color vec3<f32>
max_white f32
Returns: vec3<f32>

tonemapping_luminance

#
luminance coefficients from Rec. 709. https://en.wikipedia.org/wiki/Rec._709
fn tonemapping_luminance(v: vec3<f32>) -> f32
Parameter Type
v vec3<f32>
Returns: f32

tonemapping_change_luminance

#
fn tonemapping_change_luminance(c_in: vec3<f32>, l_out: f32) -> vec3<f32>
Parameter Type
c_in vec3<f32>
l_out f32
Returns: vec3<f32>

tonemapping_reinhard_luminance

#
fn tonemapping_reinhard_luminance(color: vec3<f32>) -> vec3<f32>
Parameter Type
color vec3<f32>
Returns: vec3<f32>

rgb_to_srgb_simple

#
fn rgb_to_srgb_simple(color: vec3<f32>) -> vec3<f32>
Parameter Type
color vec3<f32>
Returns: vec3<f32>

screen_space_dither

#
Source: Advanced VR Rendering, GDC 2015, Alex Vlachos, Valve, Slide 49 https://media.steampowered.com/apps/valve/2015/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
fn screen_space_dither(frag_coord: vec2<f32>) -> vec3<f32>
Parameter Type
frag_coord vec2<f32>
Returns: vec3<f32>

sectional_color_grading

#
Performs the "sectional" color grading: i.e. the color grading that applies individually to shadows, midtones, and highlights.
fn sectional_color_grading(in: vec3<f32>, color_grading: ptr<function, ColorGrading>) -> vec3<f32>
Parameter Type
in vec3<f32>
color_grading ptr<function, ColorGrading>
Returns: vec3<f32>

tone_mapping

#
fn tone_mapping(in: vec4<f32>, in_color_grading: ColorGrading) -> vec4<f32>
Parameter Type
in vec4<f32>
in_color_grading ColorGrading
Returns: vec4<f32>

approximate_inverse_tone_mapping

#
This is an **incredibly crude** approximation of the inverse of the tone mapping function. We assume here that there's a simple linear relationship between the input and output which is not true at all, but useful to at least preserve the overall luminance of colors when sampling from an already tonemapped image. (e.g. for transmissive materials when HDR is off)
fn approximate_inverse_tone_mapping(in: vec4<f32>, color_grading: ColorGrading) -> vec4<f32>
Parameter Type
in vec4<f32>
color_grading ColorGrading
Returns: vec4<f32>