From 0957867a0428b620f572e7dcedeebf4105c3372e Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 10 Feb 2023 18:05:38 -0500 Subject: [PATCH 01/12] Add MipBias --- crates/bevy_pbr/src/render/mesh_view_types.wgsl | 3 ++- crates/bevy_pbr/src/render/pbr.wgsl | 8 ++++---- crates/bevy_pbr/src/render/pbr_functions.wgsl | 2 +- crates/bevy_pbr/src/render/pbr_prepass.wgsl | 3 +-- crates/bevy_render/src/camera/camera.rs | 6 ++++++ crates/bevy_render/src/view/mod.rs | 8 +++++--- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/crates/bevy_pbr/src/render/mesh_view_types.wgsl b/crates/bevy_pbr/src/render/mesh_view_types.wgsl index c732cabc9453c..631bc8fa946e5 100644 --- a/crates/bevy_pbr/src/render/mesh_view_types.wgsl +++ b/crates/bevy_pbr/src/render/mesh_view_types.wgsl @@ -10,6 +10,7 @@ struct View { world_position: vec3, // viewport(x_origin, y_origin, width, height) viewport: vec4, + mip_bias: f32, }; struct PointLight { @@ -33,7 +34,7 @@ struct DirectionalCascade { texel_size: f32, far_bound: f32, } - + struct DirectionalLight { cascades: array, color: vec4, diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index 43e19fd7c32c5..8c0cfe8a58102 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -24,7 +24,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { #endif #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT) != 0u) { - output_color = output_color * textureSample(base_color_texture, base_color_sampler, in.uv); + output_color = output_color * textureSampleBias(base_color_texture, base_color_sampler, in.uv, view.mip_bias); } #endif @@ -43,7 +43,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { var emissive: vec4 = material.emissive; #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_EMISSIVE_TEXTURE_BIT) != 0u) { - emissive = vec4(emissive.rgb * textureSample(emissive_texture, emissive_sampler, in.uv).rgb, 1.0); + emissive = vec4(emissive.rgb * textureSampleBias(emissive_texture, emissive_sampler, in.uv, view.mip_bias).rgb, 1.0); } #endif pbr_input.material.emissive = emissive; @@ -52,7 +52,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { var perceptual_roughness: f32 = material.perceptual_roughness; #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT) != 0u) { - let metallic_roughness = textureSample(metallic_roughness_texture, metallic_roughness_sampler, in.uv); + let metallic_roughness = textureSampleBias(metallic_roughness_texture, metallic_roughness_sampler, in.uv, view.mip_bias); // Sampling from GLTF standard channels for now metallic = metallic * metallic_roughness.b; perceptual_roughness = perceptual_roughness * metallic_roughness.g; @@ -64,7 +64,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { var occlusion: f32 = 1.0; #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT) != 0u) { - occlusion = textureSample(occlusion_texture, occlusion_sampler, in.uv).r; + occlusion = textureSampleBias(occlusion_texture, occlusion_sampler, in.uv, view.mip_bias).r; } #endif pbr_input.frag_coord = in.frag_coord; diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index edeb194185413..6cc975eaa241b 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -78,7 +78,7 @@ fn apply_normal_mapping( #ifdef VERTEX_UVS #ifdef STANDARDMATERIAL_NORMAL_MAP // Nt is the tangent-space normal. - var Nt = textureSample(normal_map_texture, normal_map_sampler, uv).rgb; + var Nt = textureSampleBias(normal_map_texture, normal_map_sampler, uv, view.mip_bias).rgb; if (standard_material_flags & STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP) != 0u { // Only use the xy components and derive z for 2-component normal maps. Nt = vec3(Nt.rg * 2.0 - 1.0, 0.0); diff --git a/crates/bevy_pbr/src/render/pbr_prepass.wgsl b/crates/bevy_pbr/src/render/pbr_prepass.wgsl index 54584ef682666..c196e1a89b175 100644 --- a/crates/bevy_pbr/src/render/pbr_prepass.wgsl +++ b/crates/bevy_pbr/src/render/pbr_prepass.wgsl @@ -23,7 +23,7 @@ fn prepass_alpha_discard(in: FragmentInput) { #ifdef VERTEX_UVS if (material.flags & STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT) != 0u { - output_color = output_color * textureSample(base_color_texture, base_color_sampler, in.uv); + output_color = output_color * textureSampleBias(base_color_texture, base_color_sampler, in.uv, view.mip_bias); } #endif // VERTEX_UVS @@ -74,4 +74,3 @@ fn fragment(in: FragmentInput) { } #endif // NORMAL_PREPASS - diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 9434e5e80aaae..90d18d108622f 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -573,3 +573,9 @@ pub fn extract_cameras( } } } + +/// Mip bias to apply when sampling from material textures. +/// +/// Often used in conjunction with antialiasing post-process effects. +#[derive(Component)] +pub struct MipBias(pub f32); diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 5d278223c9e0e..7c8e1203108ac 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -5,7 +5,7 @@ pub use visibility::*; pub use window::*; use crate::{ - camera::ExtractedCamera, + camera::{ExtractedCamera, MipBias}, extract_resource::{ExtractResource, ExtractResourcePlugin}, prelude::Image, render_asset::RenderAssets, @@ -120,6 +120,7 @@ pub struct ViewUniform { world_position: Vec3, // viewport(x_origin, y_origin, width, height) viewport: Vec4, + mip_bias: f32, } #[derive(Resource, Default)] @@ -261,10 +262,10 @@ fn prepare_view_uniforms( render_device: Res, render_queue: Res, mut view_uniforms: ResMut, - views: Query<(Entity, &ExtractedView)>, + views: Query<(Entity, &ExtractedView, Option<&MipBias>)>, ) { view_uniforms.uniforms.clear(); - for (entity, camera) in &views { + for (entity, camera, mip_bias) in &views { let projection = camera.projection; let inverse_projection = projection.inverse(); let view = camera.transform.compute_matrix(); @@ -281,6 +282,7 @@ fn prepare_view_uniforms( inverse_projection, world_position: camera.transform.translation(), viewport: camera.viewport.as_vec4(), + mip_bias: mip_bias.unwrap_or(&MipBias(0.0)).0, }), }; From 5381ae26f34df252d78748a4840ea2d3702dfea4 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 10 Feb 2023 18:05:48 -0500 Subject: [PATCH 02/12] Add -0.25 mip bias to FXAA --- crates/bevy_core_pipeline/src/fxaa/mod.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/bevy_core_pipeline/src/fxaa/mod.rs b/crates/bevy_core_pipeline/src/fxaa/mod.rs index 8263de32f66af..f1975e5653329 100644 --- a/crates/bevy_core_pipeline/src/fxaa/mod.rs +++ b/crates/bevy_core_pipeline/src/fxaa/mod.rs @@ -2,9 +2,10 @@ use crate::{core_2d, core_3d, fullscreen_vertex_shader::fullscreen_shader_vertex use bevy_app::prelude::*; use bevy_asset::{load_internal_asset, HandleUntyped}; use bevy_derive::Deref; -use bevy_ecs::prelude::*; +use bevy_ecs::{prelude::*, query::QueryItem}; use bevy_reflect::TypeUuid; use bevy_render::{ + camera::MipBias, extract_component::{ExtractComponent, ExtractComponentPlugin}, prelude::Camera, render_graph::RenderGraph, @@ -40,8 +41,7 @@ impl Sensitivity { } } -#[derive(Component, Clone, ExtractComponent)] -#[extract_component_filter(With)] +#[derive(Component, Clone)] pub struct Fxaa { /// Enable render passes for FXAA. pub enabled: bool, @@ -58,6 +58,16 @@ pub struct Fxaa { pub edge_threshold_min: Sensitivity, } +impl ExtractComponent for Fxaa { + type Query = &'static Self; + type Filter = With; + type Out = (Self, MipBias); + + fn extract_component(item: QueryItem<'_, Self::Query>) -> Option { + Some((item.clone(), MipBias(-0.25))) + } +} + impl Default for Fxaa { fn default() -> Self { Fxaa { From a336a2aee25a5387b18c1bca3a664fccbd469800 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 10 Feb 2023 18:10:14 -0500 Subject: [PATCH 03/12] Improve docs --- crates/bevy_render/src/camera/camera.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 90d18d108622f..b50461e7c47f1 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -574,8 +574,8 @@ pub fn extract_cameras( } } -/// Mip bias to apply when sampling from material textures. +/// Camera component specifiying a mip bias to apply when sampling from material textures. /// -/// Often used in conjunction with antialiasing post-process effects. +/// Often used in conjunction with antialiasing post-process effects to reduce textures blurriness. #[derive(Component)] pub struct MipBias(pub f32); From 7d6279c692712a4cd1aa87f7241dc97e0151c1c2 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 3 Apr 2023 23:59:50 -0400 Subject: [PATCH 04/12] Remove fxaa, add taa mip bias --- crates/bevy_core_pipeline/src/fxaa/mod.rs | 10 ---------- crates/bevy_core_pipeline/src/taa/mod.rs | 6 ++++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/bevy_core_pipeline/src/fxaa/mod.rs b/crates/bevy_core_pipeline/src/fxaa/mod.rs index 3485af6f5b3ee..221ac91fc4c22 100644 --- a/crates/bevy_core_pipeline/src/fxaa/mod.rs +++ b/crates/bevy_core_pipeline/src/fxaa/mod.rs @@ -63,16 +63,6 @@ pub struct Fxaa { pub edge_threshold_min: Sensitivity, } -impl ExtractComponent for Fxaa { - type Query = &'static Self; - type Filter = With; - type Out = (Self, MipBias); - - fn extract_component(item: QueryItem<'_, Self::Query>) -> Option { - Some((item.clone(), MipBias(-0.25))) - } -} - impl Default for Fxaa { fn default() -> Self { Fxaa { diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index 6b2e8730c435c..46558ca143465 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -17,7 +17,7 @@ use bevy_ecs::{ use bevy_math::vec2; use bevy_reflect::{Reflect, TypeUuid}; use bevy_render::{ - camera::{ExtractedCamera, TemporalJitter}, + camera::{ExtractedCamera, MipBias, TemporalJitter}, prelude::{Camera, Projection}, render_graph::{Node, NodeRunError, RenderGraphApp, RenderGraphContext}, render_resource::{ @@ -437,7 +437,9 @@ fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut Date: Tue, 4 Apr 2023 00:03:01 -0400 Subject: [PATCH 05/12] Misc fix --- crates/bevy_core_pipeline/src/fxaa/mod.rs | 1 - crates/bevy_render/src/view/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/bevy_core_pipeline/src/fxaa/mod.rs b/crates/bevy_core_pipeline/src/fxaa/mod.rs index 221ac91fc4c22..4342e61983b0a 100644 --- a/crates/bevy_core_pipeline/src/fxaa/mod.rs +++ b/crates/bevy_core_pipeline/src/fxaa/mod.rs @@ -7,7 +7,6 @@ use bevy_reflect::{ std_traits::ReflectDefault, FromReflect, Reflect, ReflectFromReflect, TypeUuid, }; use bevy_render::{ - camera::MipBias, extract_component::{ExtractComponent, ExtractComponentPlugin}, prelude::Camera, render_graph::RenderGraphApp, diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 9ae538f5ba88e..7784af28b9f31 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -323,7 +323,7 @@ pub fn prepare_view_uniforms( ) { view_uniforms.uniforms.clear(); - for (entity, camera, temporal_jitter) in &views { + for (entity, camera, temporal_jitter, mip_bias) in &views { let viewport = camera.viewport.as_vec4(); let unjittered_projection = camera.projection; let mut projection = unjittered_projection; From f62cd854519f6bc0ec3ed6ee65ba661d2742c398 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 1 May 2023 15:24:53 -0400 Subject: [PATCH 06/12] Update crates/bevy_pbr/src/render/pbr.wgsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_pbr/src/render/pbr.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index 9b8f377e4fcdb..e8cf7cdade4af 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -91,7 +91,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { var occlusion: f32 = 1.0; #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT) != 0u) { - occlusion = textureSampleBias(occlusion_texture, occlusion_sampler, in.uv, view.mip_bias).r; + occlusion = textureSampleBias(occlusion_texture, occlusion_sampler, uv, view.mip_bias).r; } #endif pbr_input.frag_coord = in.frag_coord; From 3174c2457460a05ceb3b4d92a2fd5c114ce80b73 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 1 May 2023 15:24:59 -0400 Subject: [PATCH 07/12] Update crates/bevy_pbr/src/render/pbr.wgsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_pbr/src/render/pbr.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index e8cf7cdade4af..43c9947dd7fca 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -51,7 +51,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { #endif #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT) != 0u) { - output_color = output_color * textureSampleBias(base_color_texture, base_color_sampler, in.uv, view.mip_bias); + output_color = output_color * textureSampleBias(base_color_texture, base_color_sampler, uv, view.mip_bias); } #endif From 822d5517cd5f3bae41f1ef4b11aa8aac3a8355b1 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 1 May 2023 15:25:07 -0400 Subject: [PATCH 08/12] Update crates/bevy_pbr/src/render/pbr.wgsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_pbr/src/render/pbr.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index 43c9947dd7fca..359b64c9f1a35 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -70,7 +70,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { var emissive: vec4 = material.emissive; #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_EMISSIVE_TEXTURE_BIT) != 0u) { - emissive = vec4(emissive.rgb * textureSampleBias(emissive_texture, emissive_sampler, in.uv, view.mip_bias).rgb, 1.0); + emissive = vec4(emissive.rgb * textureSampleBias(emissive_texture, emissive_sampler, uv, view.mip_bias).rgb, 1.0); } #endif pbr_input.material.emissive = emissive; From 404d346cc7f17fd7d3174b275e629ad048382dc5 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 1 May 2023 15:25:15 -0400 Subject: [PATCH 09/12] Update crates/bevy_pbr/src/render/pbr.wgsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: François --- crates/bevy_pbr/src/render/pbr.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index 359b64c9f1a35..9e5f0dcd27616 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -79,7 +79,7 @@ fn fragment(in: FragmentInput) -> @location(0) vec4 { var perceptual_roughness: f32 = material.perceptual_roughness; #ifdef VERTEX_UVS if ((material.flags & STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT) != 0u) { - let metallic_roughness = textureSampleBias(metallic_roughness_texture, metallic_roughness_sampler, in.uv, view.mip_bias); + let metallic_roughness = textureSampleBias(metallic_roughness_texture, metallic_roughness_sampler, uv, view.mip_bias); // Sampling from GLTF standard channels for now metallic = metallic * metallic_roughness.b; perceptual_roughness = perceptual_roughness * metallic_roughness.g; From 28439665646b4ca3ec870df985ee0141ddd7cd1f Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Sun, 18 Jun 2023 12:55:01 -0700 Subject: [PATCH 10/12] Fix typo --- crates/bevy_render/src/camera/camera.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index f82342fba9f16..fa520f2fda0a5 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -746,7 +746,7 @@ impl TemporalJitter { } } -/// Camera component specifiying a mip bias to apply when sampling from material textures. +/// Camera component specifying a mip bias to apply when sampling from material textures. /// /// Often used in conjunction with antialiasing post-process effects to reduce textures blurriness. #[derive(Component)] From 30b1a12bcd3d862d52ccfcd23cad0e6dc59472a1 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 18 Jun 2023 20:28:18 -0400 Subject: [PATCH 11/12] Change TAA mip bias API --- crates/bevy_core_pipeline/src/taa/mod.rs | 37 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index aefd20ce8f4fb..e2adca474bcc2 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -10,7 +10,7 @@ use bevy_core::FrameCount; use bevy_ecs::{ prelude::{Bundle, Component, Entity}, query::{QueryItem, With}, - schedule::IntoSystemConfigs, + schedule::{apply_deferred, IntoSystemConfigs}, system::{Commands, Query, Res, ResMut, Resource}, world::{FromWorld, World}, }; @@ -65,7 +65,8 @@ impl Plugin for TemporalAntiAliasPlugin { .add_systems( Render, ( - prepare_taa_jitter + (prepare_taa_jitter_and_mip_bias, apply_deferred) + .chain() .before(prepare_view_uniforms) .in_set(RenderSet::Prepare), prepare_taa_history_textures.in_set(RenderSet::Prepare), @@ -149,11 +150,16 @@ pub struct TemporalAntiAliasSettings { /// After setting this to true, it will automatically be toggled /// back to false after one frame. pub reset: bool, + /// Mipmap bias added to texture maps in addition to [`MipBias`]. + pub additional_mip_bias: f32, } impl Default for TemporalAntiAliasSettings { fn default() -> Self { - Self { reset: true } + Self { + reset: true, + additional_mip_bias: -1.0, + } } } @@ -429,17 +435,21 @@ fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut, - mut query: Query<&mut TemporalJitter, With>, + mut query: Query<( + Entity, + &mut TemporalJitter, + Option<&mut MipBias>, + &TemporalAntiAliasSettings, + )>, + mut commands: Commands, ) { // Halton sequence (2, 3) - 0.5, skipping i = 0 let halton_sequence = [ @@ -455,8 +465,17 @@ fn prepare_taa_jitter( let offset = halton_sequence[frame_count.0 as usize % halton_sequence.len()]; - for mut jitter in &mut query { + for (entity, mut jitter, mip_bias, taa_settings) in &mut query { jitter.offset = offset; + + match mip_bias { + Some(mut mip_bias) => mip_bias.0 += taa_settings.additional_mip_bias, + None => { + commands + .entity(entity) + .insert(MipBias(taa_settings.additional_mip_bias)); + } + } } } From 9ea1a5803841e75833bdb7498e01a10853b43f2e Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 22 Jun 2023 16:32:37 -0400 Subject: [PATCH 12/12] Change mip bias handling --- crates/bevy_core_pipeline/src/taa/mod.rs | 30 ++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index e2adca474bcc2..7f3ef0740a70e 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -140,6 +140,8 @@ pub struct TemporalAntiAliasBundle { /// are added using a third party library, the library must either: /// 1. Write particle motion vectors to the motion vectors prepass texture /// 2. Render particles after TAA +/// +/// If no [`MipBias`] component is attached to the camera, TAA will add a MipBias(-1.0) component. #[derive(Component, Reflect, Clone)] pub struct TemporalAntiAliasSettings { /// Set to true to delete the saved temporal history (past frames). @@ -150,16 +152,11 @@ pub struct TemporalAntiAliasSettings { /// After setting this to true, it will automatically be toggled /// back to false after one frame. pub reset: bool, - /// Mipmap bias added to texture maps in addition to [`MipBias`]. - pub additional_mip_bias: f32, } impl Default for TemporalAntiAliasSettings { fn default() -> Self { - Self { - reset: true, - additional_mip_bias: -1.0, - } + Self { reset: true } } } @@ -443,12 +440,10 @@ fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut, - mut query: Query<( - Entity, - &mut TemporalJitter, - Option<&mut MipBias>, - &TemporalAntiAliasSettings, - )>, + mut query: Query< + (Entity, &mut TemporalJitter, Option<&MipBias>), + With, + >, mut commands: Commands, ) { // Halton sequence (2, 3) - 0.5, skipping i = 0 @@ -465,16 +460,11 @@ fn prepare_taa_jitter_and_mip_bias( let offset = halton_sequence[frame_count.0 as usize % halton_sequence.len()]; - for (entity, mut jitter, mip_bias, taa_settings) in &mut query { + for (entity, mut jitter, mip_bias) in &mut query { jitter.offset = offset; - match mip_bias { - Some(mut mip_bias) => mip_bias.0 += taa_settings.additional_mip_bias, - None => { - commands - .entity(entity) - .insert(MipBias(taa_settings.additional_mip_bias)); - } + if mip_bias.is_none() { + commands.entity(entity).insert(MipBias(-1.0)); } } }