Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Initial tonemapping options #7594

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
b50ab5e
setup initial tonemapping options
DGriffin91 Feb 10, 2023
12c1d45
exr support, more tonemapping, initial test scene
DGriffin91 Feb 12, 2023
a716ef8
add AgX
DGriffin91 Feb 12, 2023
5284938
improve test scene, make methods selectable
DGriffin91 Feb 12, 2023
7300d3e
improve test scenes
DGriffin91 Feb 12, 2023
e77346a
disable grading, fix exmaple test patterns
DGriffin91 Feb 12, 2023
74a8eaf
update example descriptions, tweak settings
DGriffin91 Feb 12, 2023
cd2234b
add blender filmic
DGriffin91 Feb 13, 2023
68a333e
use include_bytes for luts image
DGriffin91 Feb 13, 2023
0c3bf82
make tonemapping work in main pass and sprites
DGriffin91 Feb 14, 2023
95ad250
use 3d LUTs
DGriffin91 Feb 14, 2023
3c6b223
remove bindings from sprite/mesh2d, make tonemapping work in custom t…
DGriffin91 Feb 14, 2023
b628e9a
remove tonemapping bindings from sprite wgsl
DGriffin91 Feb 14, 2023
bf3a340
add basic color grading controls
DGriffin91 Feb 14, 2023
8edb5c2
fix ci stuff, clean up tonemapping code
DGriffin91 Feb 15, 2023
69b3efa
Merge remote-tracking branch 'origin' into tonemap_options
DGriffin91 Feb 15, 2023
d6cf573
merge in main
DGriffin91 Feb 15, 2023
a63ae5a
improve tonemapping example
DGriffin91 Feb 15, 2023
bdb52c8
update sbdt2
DGriffin91 Feb 15, 2023
7cd3a38
misc nits
DGriffin91 Feb 15, 2023
a3405c1
use exr for sbdt2 for now
DGriffin91 Feb 15, 2023
c6dbd4a
remove pr 7564 task pool stuff
DGriffin91 Feb 15, 2023
4535489
use ktx2 for luts, update naming
DGriffin91 Feb 16, 2023
16904fe
remove exr from default features
DGriffin91 Feb 16, 2023
6630c15
WIP tonemapping example refactor
JMS55 Feb 16, 2023
dad817f
update ACES to base implementation without white parameter
DGriffin91 Feb 16, 2023
bfa26d9
More WIP tonemap example
JMS55 Feb 16, 2023
53c810b
Add reset color grading
JMS55 Feb 16, 2023
7b6e43f
Add back matched color grading
JMS55 Feb 16, 2023
3866632
Rename ACES
JMS55 Feb 16, 2023
3d9bebf
Update crates/bevy_core_pipeline/src/tonemapping/mod.rs
JMS55 Feb 16, 2023
2488305
Merge pull request #1 from JMS55/tonemap_options
DGriffin91 Feb 16, 2023
fd85e9d
Revert "Tonemapping example refactor "
DGriffin91 Feb 16, 2023
291ce1f
Merge pull request #2 from DGriffin91/revert-1-tonemap_options
DGriffin91 Feb 16, 2023
afe9ad5
Fix bug
JMS55 Feb 16, 2023
1dac246
Fix bugfix
JMS55 Feb 16, 2023
f128b53
Add reset to scene default vs regular default
JMS55 Feb 16, 2023
7890cc4
Fix mixmatched keys
JMS55 Feb 16, 2023
314bf50
Save color grading per method
JMS55 Feb 16, 2023
0f14b42
Chnage controls
JMS55 Feb 16, 2023
e07121d
Merge branch 'tonemap_options' into tonemap_options
DGriffin91 Feb 16, 2023
315379b
Merge pull request #4 from JMS55/tonemap_options
DGriffin91 Feb 16, 2023
79b5e19
tweak example
DGriffin91 Feb 16, 2023
de00f72
move around entities
DGriffin91 Feb 16, 2023
60b3281
remove TonemappingMethod, make Dither separate Component
DGriffin91 Feb 16, 2023
2011fca
fix crash on arrow up, bring back hide option
DGriffin91 Feb 16, 2023
964cf81
build-example-pages
DGriffin91 Feb 16, 2023
f7b8a94
fix sprite/mesh2d
DGriffin91 Feb 17, 2023
510fda5
improve hide ui ui
DGriffin91 Feb 17, 2023
51c028c
fix ci/clippy errors
DGriffin91 Feb 17, 2023
77f1c28
Merge remote-tracking branch 'origin/main' into tonemap_options
DGriffin91 Feb 17, 2023
cf27b91
improve texture sample exclusion logic
DGriffin91 Feb 17, 2023
e461f83
fix color sweep shader
DGriffin91 Feb 17, 2023
6ebc9aa
remove old godot aces code
DGriffin91 Feb 17, 2023
959748d
update tony_mc_mapface file and attribution
DGriffin91 Feb 17, 2023
5a46cb0
add info for creating luts
DGriffin91 Feb 18, 2023
feabb2a
use ACES Fitted name everywhere
DGriffin91 Feb 18, 2023
d9780d2
add docstring for debanding dither
DGriffin91 Feb 18, 2023
2b2a1bb
Merge branch 'tonemap_options' of https://github.com/DGriffin91/bevy …
DGriffin91 Feb 18, 2023
6412a32
rename Dither component to DebandDither
DGriffin91 Feb 18, 2023
51695a4
remove rgb_to_srgb_simple
DGriffin91 Feb 18, 2023
5e2846f
use tone_mapping for sprite
DGriffin91 Feb 18, 2023
d8a30ac
use tone_mapping for mesh2d and color material
DGriffin91 Feb 18, 2023
c06fc0b
capitalize Tonemapping in Cargo.toml
DGriffin91 Feb 18, 2023
66cb51b
reuse cube mesh
DGriffin91 Feb 18, 2023
43dad10
ColorGrading definitions
DGriffin91 Feb 18, 2023
2053b6a
Tonemapping descriptions
DGriffin91 Feb 18, 2023
25d0d68
update tonemapping descriptions
DGriffin91 Feb 18, 2023
4cbbe25
fix color sweep x offset and add description
DGriffin91 Feb 18, 2023
8acf28b
description for continuous_hue
DGriffin91 Feb 18, 2023
a26b71d
update SomewhatBoringDisplayTransform description
DGriffin91 Feb 18, 2023
647436a
fix dithering nan issue
DGriffin91 Feb 18, 2023
b3a260d
Reset all with space/enter
DGriffin91 Feb 18, 2023
ff38ae7
automatic links for doc check
DGriffin91 Feb 18, 2023
173d3e9
component definitions
DGriffin91 Feb 18, 2023
a354928
TonemappingLuts doc string
DGriffin91 Feb 18, 2023
d0e891e
PipelineKey spacing
DGriffin91 Feb 18, 2023
c336932
ColorGrading doc string
DGriffin91 Feb 18, 2023
2cef295
fix ifdef spacing
DGriffin91 Feb 18, 2023
86e3e09
revert pi precision
DGriffin91 Feb 18, 2023
2530b0c
tonemapping doc string
DGriffin91 Feb 18, 2023
1507b7d
ImageFormat::Exr -> ImageFormat::OpenExr
DGriffin91 Feb 18, 2023
819e768
use full path for camera doc
DGriffin91 Feb 18, 2023
ec8355f
make including luts a default feature
DGriffin91 Feb 18, 2023
cfd37da
keep detection of tonemapping change on the node
DGriffin91 Feb 19, 2023
2b342e9
Update crates/bevy_core_pipeline/src/tonemapping/mod.rs
DGriffin91 Feb 19, 2023
abf5056
Update crates/bevy_core_pipeline/src/tonemapping/tonemapping_shared.wgsl
DGriffin91 Feb 19, 2023
d50e9be
Apply suggestions from code review
DGriffin91 Feb 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ default = [
"x11",
"filesystem_watcher",
"android_shared_stdcxx",
"tonemapping_luts"
]

# Force dynamic linking, which improves iterative compile times
Expand Down Expand Up @@ -132,6 +133,9 @@ android_shared_stdcxx = ["bevy_internal/android_shared_stdcxx"]
# These trace events are expensive even when off, thus they require compile time opt-in.
detailed_trace = ["bevy_internal/detailed_trace"]

# Include tonemapping LUT KTX2 files.
tonemapping_luts = ["bevy_internal/tonemapping_luts"]

[dependencies]
bevy_dylib = { path = "crates/bevy_dylib", version = "0.9.0", default-features = false, optional = true }
bevy_internal = { path = "crates/bevy_internal", version = "0.9.0", default-features = false }
Expand Down Expand Up @@ -396,7 +400,7 @@ path = "examples/3d/tonemapping.rs"
required-features = ["ktx2", "zstd"]

[package.metadata.example.tonemapping]
name = "tonemapping"
name = "Tonemapping"
description = "Compares tonemapping options"
category = "3D Rendering"
wasm = true
Expand Down
6 changes: 5 additions & 1 deletion assets/shaders/tonemapping_test_patterns.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ struct FragmentInput {
#import bevy_pbr::mesh_vertex_output
};

// Sweep across hues on y axis with value from 0.0 to +15EV across x axis
// quantized into 24 steps for both axis.
fn color_sweep(uv: vec2<f32>) -> vec3<f32> {
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
var uv = uv;
let steps = 24.0;
let uv = uv * (1.0 + 1.0 / steps);
uv.y = uv.y * (1.0 + 1.0 / steps);
let ratio = 2.0;

let h = PI * 2.0 * floor(1.0 + steps * uv.y) / steps;
Expand All @@ -38,6 +41,7 @@ fn hsv_to_srgb(c: vec3<f32>) -> vec3<f32> {
return c.z * mix(K.xxx, clamp(p - K.xxx, vec3(0.0), vec3(1.0)), c.y);
}

// Generates a continuous sRGB sweep.
fn continuous_hue(uv: vec2<f32>) -> vec3<f32> {
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
return hsv_to_srgb(vec3(uv.x, 1.0, 1.0)) * max(0.0, exp2(uv.y * 9.0) - 1.0);
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_core_pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords = ["bevy"]
[features]
trace = []
webgl = []
tonemapping_luts = []

[dependencies]
# bevy
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/core_2d/camera_2d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
clear_color::ClearColorConfig,
tonemapping::{Dither, Tonemapping},
tonemapping::{DebandDither, Tonemapping},
};
use bevy_ecs::prelude::*;
use bevy_reflect::Reflect;
Expand Down Expand Up @@ -30,7 +30,7 @@ pub struct Camera2dBundle {
pub global_transform: GlobalTransform,
pub camera_2d: Camera2d,
pub tonemapping: Tonemapping,
pub dither: Dither,
pub deband_dither: DebandDither,
}

impl Default for Camera2dBundle {
Expand Down Expand Up @@ -72,7 +72,7 @@ impl Camera2dBundle {
camera: Camera::default(),
camera_2d: Camera2d::default(),
tonemapping: Tonemapping::None,
dither: Dither::Disabled,
deband_dither: DebandDither::Disabled,
}
}
}
6 changes: 3 additions & 3 deletions crates/bevy_core_pipeline/src/core_3d/camera_3d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
clear_color::ClearColorConfig,
tonemapping::{Dither, Tonemapping},
tonemapping::{DebandDither, Tonemapping},
};
use bevy_ecs::prelude::*;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
Expand Down Expand Up @@ -62,7 +62,7 @@ pub struct Camera3dBundle {
pub global_transform: GlobalTransform,
pub camera_3d: Camera3d,
pub tonemapping: Tonemapping,
pub dither: Dither,
pub dither: DebandDither,
pub color_grading: ColorGrading,
}

Expand All @@ -79,7 +79,7 @@ impl Default for Camera3dBundle {
global_transform: Default::default(),
camera_3d: Default::default(),
tonemapping: Tonemapping::ReinhardLuminance,
dither: Dither::Enabled,
dither: DebandDither::Enabled,
color_grading: ColorGrading::default(),
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions crates/bevy_core_pipeline/src/tonemapping/luts/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- Process for recreating AgX-default_contrast.ktx2 ---
Download:
https://github.com/MrLixm/AgXc/blob/898198e0490b0551ed81412a0c22e0b72fffb7cd/obs/obs-script/AgX-default_contrast.lut.png
Convert to vertical strip exr with:
https://gist.github.com/DGriffin91/fc8e0cfd55aaa175ac10199403bc19b8
Convert exr to 3D ktx2 with:
https://gist.github.com/DGriffin91/49401c43378b58bce32059291097d4ca

--- Process for recreating tony_mc_mapface.ktx2 ---
Download:
https://github.com/h3r2tic/tony-mc-mapface/blob/909e51c8a74251fd828770248476cb084081e08c/tony_mc_mapface.dds
Convert dds to 3D ktx2 with:
https://gist.github.com/DGriffin91/49401c43378b58bce32059291097d4ca

--- Process for recreating Blender_-11_12.ktx2 ---
Create LUT stimulus with:
https://gist.github.com/DGriffin91/e119bf32b520e219f6e102a6eba4a0cf
Open LUT image in Blender's image editor and make sure color space is set to linear.
Export from Blender as 32bit EXR, override color space to Filmic sRGB.
Import EXR back into blender set color space to sRGB, then export as 32bit EXR override color space to linear.
Convert exr to 3D ktx2 with:
https://gist.github.com/DGriffin91/49401c43378b58bce32059291097d4ca



DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
145 changes: 108 additions & 37 deletions crates/bevy_core_pipeline/src/tonemapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use bevy_ecs::prelude::*;
use bevy_reflect::{FromReflect, Reflect, TypeUuid};
use bevy_render::camera::Camera;
use bevy_render::extract_component::{ExtractComponent, ExtractComponentPlugin};
use bevy_render::extract_resource::{ExtractResource, ExtractResourcePlugin};
use bevy_render::render_asset::RenderAssets;
use bevy_render::renderer::RenderDevice;
use bevy_render::texture::{CompressedImageFormats, Image, ImageType};
use bevy_render::texture::{CompressedImageFormats, Image, ImageSampler, ImageType};
use bevy_render::view::{ViewTarget, ViewUniform};
use bevy_render::{render_resource::*, RenderApp, RenderSet};

Expand All @@ -22,7 +23,8 @@ const TONEMAPPING_SHADER_HANDLE: HandleUntyped =
const TONEMAPPING_SHARED_SHADER_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 2499430578245347910);

#[derive(Resource)]
/// 3D LUT (look up table) textures used for tonemapping
#[derive(Resource, Clone, ExtractResource)]
pub struct TonemappingLuts {
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
blender_filmic: Handle<Image>,
agx: Handle<Image>,
Expand All @@ -46,32 +48,50 @@ impl Plugin for TonemappingPlugin {
Shader::from_wgsl
);

let mut images = app.world.resource_mut::<Assets<Image>>();

let tonemapping_luts = TonemappingLuts {
blender_filmic: images.add(setup_tonemapping_lut_image(
include_bytes!("luts/Blender_-11_12.ktx2"),
ImageType::Extension("ktx2"),
)),
agx: images.add(setup_tonemapping_lut_image(
include_bytes!("luts/AgX-default_contrast.ktx2"),
ImageType::Extension("ktx2"),
)),
tony_mc_mapface: images.add(setup_tonemapping_lut_image(
include_bytes!("luts/TonyMcMapface.ktx2"),
ImageType::Extension("ktx2"),
)),
};
if !app.world.is_resource_added::<TonemappingLuts>() {
let mut images = app.world.resource_mut::<Assets<Image>>();

#[cfg(feature = "tonemapping_luts")]
let tonemapping_luts = {
TonemappingLuts {
blender_filmic: images.add(setup_tonemapping_lut_image(
include_bytes!("luts/Blender_-11_12.ktx2"),
ImageType::Extension("ktx2"),
)),
agx: images.add(setup_tonemapping_lut_image(
include_bytes!("luts/AgX-default_contrast.ktx2"),
ImageType::Extension("ktx2"),
)),
tony_mc_mapface: images.add(setup_tonemapping_lut_image(
include_bytes!("luts/tony_mc_mapface.ktx2"),
ImageType::Extension("ktx2"),
)),
}
};

#[cfg(not(feature = "tonemapping_luts"))]
let tonemapping_luts = {
let placeholder = images.add(lut_placeholder());
TonemappingLuts {
blender_filmic: placeholder.clone(),
agx: placeholder.clone(),
tony_mc_mapface: placeholder,
}
};

app.insert_resource(tonemapping_luts);
}

app.add_plugin(ExtractResourcePlugin::<TonemappingLuts>::default());

app.register_type::<Tonemapping>();
app.register_type::<Dither>();
app.register_type::<DebandDither>();

app.add_plugin(ExtractComponentPlugin::<Tonemapping>::default());
app.add_plugin(ExtractComponentPlugin::<Dither>::default());
app.add_plugin(ExtractComponentPlugin::<DebandDither>::default());

if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.insert_resource(tonemapping_luts)
.init_resource::<TonemappingPipeline>()
.init_resource::<SpecializedRenderPipelines<TonemappingPipeline>>()
.add_system(queue_view_tonemapping_pipelines.in_set(RenderSet::Queue));
Expand All @@ -84,6 +104,7 @@ pub struct TonemappingPipeline {
texture_bind_group: BindGroupLayout,
}

/// Optionally enables a tonemapping shader that attempts to map linear input stimulus into a perceptually uniform image for a given [`Camera`] entity.
#[derive(
Component,
Debug,
Expand All @@ -100,21 +121,45 @@ pub struct TonemappingPipeline {
#[extract_component_filter(With<Camera>)]
#[reflect(Component)]
pub enum Tonemapping {
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
/// Bypass tonemapping.
None,
/// Suffers from lots hue shifting, brights don't desaturate naturally.
/// Bright primaries and secondaries don't desaturate at all.
Reinhard,
/// Old bevy default. Suffers from hue shifting, brights don't desaturate much at all.
/// Current bevy default. Likely to change in the future.
/// Suffers from hue shifting. Brights don't desaturate much at all across the spectrum.
#[default]
ReinhardLuminance,
/// Bad
Aces,
/// Very Good
/// Same base implementation that Godot 4.0 uses for Tonemap ACES.
/// <https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl>
/// Not neutral, has a very specific aesthetic, intentional and dramatic hue shifting.
/// Bright greens and reds turn orange. Bright blues turn magenta.
/// Significantly increased contrast. Brights desaturate across the spectrum.
AcesFitted,
/// By Troy Sobotka
/// <https://github.com/sobotka/AgX>
/// Very neutral. Image is somewhat desaturated when compared to other tonemappers.
/// Little to no hue shifting. Subtle abney shifting.
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
AgX,
/// Also good
/// By Tomasz Stachowiak
/// Has little hue shifting in the darks and mids, but lots in the brights. Brights desaturate across the spectrum.
/// Is sort of between Reinhard and ReinhardLuminance. Conceptually similar to reinhard-jodie.
/// Designed as a compromise if you want e.g. decent skin tones in low light, but can't afford to re-do your
/// VFX to look good without hue shifting.
SomewhatBoringDisplayTransform,
/// Very Good
/// By Tomasz Stachowiak
/// <https://github.com/h3r2tic/tony-mc-mapface>
/// Very neutral. Subtle but intentional hue shifting. Brights desaturate across the spectrum.
/// Comment from author:
/// Tony is a display transform intended for real-time applications such as games.
/// It is intentionally boring, does not increase contrast or saturation, and stays close to the
/// input stimulus where compression isn't necessary.
/// Brightness-equivalent luminance of the input stimulus is compressed. The non-linearity resembles Reinhard.
/// Color hues are preserved during compression, except for a deliberate Bezold–Brücke shift.
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
/// To avoid posterization, selective desaturation is employed, with care to avoid the Abney effect.
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
TonyMcMapface,
/// Also good
#[default]
/// Default Filmic Display Transform from blender.
/// Somewhat neutral. Suffers from hue shifting. Brights desaturate across the spectrum.
DGriffin91 marked this conversation as resolved.
Show resolved Hide resolved
BlenderFilmic,
}

Expand All @@ -125,7 +170,7 @@ impl Tonemapping {
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct TonemappingPipelineKey {
deband_dither: Dither,
deband_dither: DebandDither,
tonemapping: Tonemapping,
}

Expand All @@ -134,7 +179,7 @@ impl SpecializedRenderPipeline for TonemappingPipeline {

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
let mut shader_defs = Vec::new();
if let Dither::Enabled = key.deband_dither {
if let DebandDither::Enabled = key.deband_dither {
shader_defs.push("DEBAND_DITHER".into());
}
match key.tonemapping {
Expand All @@ -143,7 +188,7 @@ impl SpecializedRenderPipeline for TonemappingPipeline {
Tonemapping::ReinhardLuminance => {
shader_defs.push("TONEMAP_METHOD_REINHARD_LUMINANCE".into());
}
Tonemapping::Aces => shader_defs.push("TONEMAP_METHOD_ACES".into()),
Tonemapping::AcesFitted => shader_defs.push("TONEMAP_METHOD_ACES_FITTED".into()),
Tonemapping::AgX => shader_defs.push("TONEMAP_METHOD_AGX".into()),
Tonemapping::SomewhatBoringDisplayTransform => {
shader_defs.push("TONEMAP_METHOD_SOMEWHAT_BORING_DISPLAY_TRANSFORM".into());
Expand Down Expand Up @@ -227,11 +272,11 @@ pub fn queue_view_tonemapping_pipelines(
pipeline_cache: Res<PipelineCache>,
mut pipelines: ResMut<SpecializedRenderPipelines<TonemappingPipeline>>,
upscaling_pipeline: Res<TonemappingPipeline>,
view_targets: Query<(Entity, Option<&Tonemapping>, Option<&Dither>), With<ViewTarget>>,
view_targets: Query<(Entity, Option<&Tonemapping>, Option<&DebandDither>), With<ViewTarget>>,
) {
for (entity, tonemapping, dither) in view_targets.iter() {
let key = TonemappingPipelineKey {
deband_dither: *dither.unwrap_or(&Dither::Disabled),
deband_dither: *dither.unwrap_or(&DebandDither::Disabled),
tonemapping: *tonemapping.unwrap_or(&Tonemapping::None),
};
let pipeline = pipelines.specialize(&pipeline_cache, &upscaling_pipeline, key);
Expand All @@ -241,7 +286,7 @@ pub fn queue_view_tonemapping_pipelines(
.insert(ViewTonemappingPipeline(pipeline));
}
}

/// Enables a debanding shader that applies dithering to mitigate color banding in the final image for a given [`Camera`] entity.
#[derive(
Component,
Debug,
Expand All @@ -257,7 +302,7 @@ pub fn queue_view_tonemapping_pipelines(
)]
#[extract_component_filter(With<Camera>)]
#[reflect(Component)]
pub enum Dither {
pub enum DebandDither {
#[default]
Disabled,
Enabled,
Expand All @@ -274,7 +319,7 @@ pub fn get_lut_bindings<'a>(
Tonemapping::None
| Tonemapping::Reinhard
| Tonemapping::ReinhardLuminance
| Tonemapping::Aces
| Tonemapping::AcesFitted
| Tonemapping::AgX
| Tonemapping::SomewhatBoringDisplayTransform => &tonemapping_luts.agx,
Tonemapping::TonyMcMapface => &tonemapping_luts.tony_mc_mapface,
Expand Down Expand Up @@ -314,6 +359,8 @@ pub fn get_lut_bind_group_layout_entries(bindings: [u32; 2]) -> [BindGroupLayout
]
}

// allow(dead_code) so it doesn't complain when the tonemapping_luts feature is disabled
#[allow(dead_code)]
fn setup_tonemapping_lut_image(bytes: &[u8], image_type: ImageType) -> Image {
let mut image =
Image::from_buffer(bytes, image_type, CompressedImageFormats::NONE, false).unwrap();
Expand All @@ -331,3 +378,27 @@ fn setup_tonemapping_lut_image(bytes: &[u8], image_type: ImageType) -> Image {

image
}

pub fn lut_placeholder() -> Image {
let format = TextureFormat::Rgba8Unorm;
let data = vec![255, 0, 255, 255];
Image {
data,
texture_descriptor: TextureDescriptor {
size: Extent3d {
width: 1,
height: 1,
depth_or_array_layers: 1,
},
format,
dimension: TextureDimension::D3,
label: None,
mip_level_count: 1,
sample_count: 1,
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST,
view_formats: &[],
},
sampler_descriptor: ImageSampler::Default,
texture_view_descriptor: None,
}
}
Loading