Path: blob/main/crates/bevy_pbr/src/prepass/prepass_bindings.rs
6600 views
use bevy_core_pipeline::prepass::ViewPrepassTextures;1use bevy_render::render_resource::{2binding_types::{3texture_2d, texture_2d_multisampled, texture_depth_2d, texture_depth_2d_multisampled,4},5BindGroupLayoutEntryBuilder, TextureAspect, TextureSampleType, TextureView,6TextureViewDescriptor,7};8use bevy_utils::default;910use crate::MeshPipelineViewLayoutKey;1112pub fn get_bind_group_layout_entries(13layout_key: MeshPipelineViewLayoutKey,14) -> [Option<BindGroupLayoutEntryBuilder>; 4] {15let mut entries: [Option<BindGroupLayoutEntryBuilder>; 4] = [None; 4];1617let multisampled = layout_key.contains(MeshPipelineViewLayoutKey::MULTISAMPLED);1819if layout_key.contains(MeshPipelineViewLayoutKey::DEPTH_PREPASS) {20// Depth texture21entries[0] = if multisampled {22Some(texture_depth_2d_multisampled())23} else {24Some(texture_depth_2d())25};26}2728if layout_key.contains(MeshPipelineViewLayoutKey::NORMAL_PREPASS) {29// Normal texture30entries[1] = if multisampled {31Some(texture_2d_multisampled(TextureSampleType::Float {32filterable: false,33}))34} else {35Some(texture_2d(TextureSampleType::Float { filterable: false }))36};37}3839if layout_key.contains(MeshPipelineViewLayoutKey::MOTION_VECTOR_PREPASS) {40// Motion Vectors texture41entries[2] = if multisampled {42Some(texture_2d_multisampled(TextureSampleType::Float {43filterable: false,44}))45} else {46Some(texture_2d(TextureSampleType::Float { filterable: false }))47};48}4950if layout_key.contains(MeshPipelineViewLayoutKey::DEFERRED_PREPASS) {51// Deferred texture52entries[3] = Some(texture_2d(TextureSampleType::Uint));53}5455entries56}5758pub fn get_bindings(prepass_textures: Option<&ViewPrepassTextures>) -> [Option<TextureView>; 4] {59let depth_desc = TextureViewDescriptor {60label: Some("prepass_depth"),61aspect: TextureAspect::DepthOnly,62..default()63};64let depth_view = prepass_textures65.and_then(|x| x.depth.as_ref())66.map(|texture| texture.texture.texture.create_view(&depth_desc));6768[69depth_view,70prepass_textures.and_then(|pt| pt.normal_view().cloned()),71prepass_textures.and_then(|pt| pt.motion_vectors_view().cloned()),72prepass_textures.and_then(|pt| pt.deferred_view().cloned()),73]74}757677