Add TAA shaderdef, don't vary noise with time if TAA is disabled

This commit is contained in:
Marco Buono 2023-05-11 00:38:37 -03:00
parent 20b223c556
commit 0d817e0c62
3 changed files with 17 additions and 0 deletions

View file

@ -7,6 +7,7 @@ use bevy_app::{App, Plugin};
use bevy_asset::{AddAsset, AssetEvent, AssetServer, Assets, Handle};
use bevy_core_pipeline::{
core_3d::{AlphaMask3d, Opaque3d, Transmissive3d, Transparent3d},
experimental::taa::TemporalAntiAliasSettings,
prepass::NormalPrepass,
tonemapping::{DebandDither, Tonemapping},
};
@ -396,6 +397,7 @@ pub fn queue_material_meshes<M: Material>(
Option<&DebandDither>,
Option<&EnvironmentMapLight>,
Option<&NormalPrepass>,
Option<&TemporalAntiAliasSettings>,
&mut RenderPhase<Opaque3d>,
&mut RenderPhase<AlphaMask3d>,
&mut RenderPhase<Transmissive3d>,
@ -411,6 +413,7 @@ pub fn queue_material_meshes<M: Material>(
dither,
environment_map,
normal_prepass,
taa_settings,
mut opaque_phase,
mut alpha_mask_phase,
mut transmissive_phase,
@ -429,6 +432,10 @@ pub fn queue_material_meshes<M: Material>(
view_key |= MeshPipelineKey::NORMAL_PREPASS;
}
if taa_settings.is_some() {
view_key |= MeshPipelineKey::TAA;
}
let environment_map_loaded = match environment_map {
Some(environment_map) => environment_map.is_loaded(&images),
None => false,

View file

@ -619,6 +619,7 @@ bitflags::bitflags! {
const ALPHA_MASK = (1 << 6);
const ENVIRONMENT_MAP = (1 << 7);
const DEPTH_CLAMP_ORTHO = (1 << 8);
const TAA = (1 << 9);
const BLEND_RESERVED_BITS = Self::BLEND_MASK_BITS << Self::BLEND_SHIFT_BITS; // ← Bitmask reserving bits for the blend state
const BLEND_OPAQUE = (0 << Self::BLEND_SHIFT_BITS); // ← Values are just sequential within the mask, and can range from 0 to 3
const BLEND_PREMULTIPLIED_ALPHA = (1 << Self::BLEND_SHIFT_BITS); //
@ -833,6 +834,10 @@ impl SpecializedMeshPipeline for MeshPipeline {
shader_defs.push("ENVIRONMENT_MAP".into());
}
if key.contains(MeshPipelineKey::TAA) {
shader_defs.push("TAA".into());
}
let format = if key.contains(MeshPipelineKey::HDR) {
ViewTarget::TEXTURE_FORMAT_HDR
} else {

View file

@ -315,8 +315,13 @@ fn transmissive_light(world_position: vec4<f32>, frag_coord: vec3<f32>, N: vec3<
// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence
fn interleaved_gradient_noise(pixel_coordinates: vec2<f32>) -> f32 {
#ifdef TAA
let frame = f32(globals.frame_count % 64u);
let xy = pixel_coordinates + 5.588238 * frame;
#else
// Don't vary noise per frame if TAA is not enabled
let xy = pixel_coordinates;
#endif
return fract(52.9829189 * fract(0.06711056 * xy.x + 0.00583715 * xy.y));
}