Path: blob/main/examples/shader_advanced/fullscreen_material.rs
9341 views
//! Demonstrates how to write a custom fullscreen shader1//!2//! This example demonstrates working in 3d. To make the example work in 2d,3//! replace 3d components with their 2d counterparts, and schedule the work4//! to run in the `Core2d` schedule as described in the `FullscreenMaterial`5//! comment in this file.67use bevy::{8core_pipeline::fullscreen_material::{FullscreenMaterial, FullscreenMaterialPlugin},9prelude::*,10render::{extract_component::ExtractComponent, render_resource::ShaderType},11shader::ShaderRef,12};1314fn main() {15App::new()16.add_plugins((17DefaultPlugins,18FullscreenMaterialPlugin::<FullscreenEffect>::default(),19))20.add_systems(Startup, setup)21.run();22}2324fn setup(25mut commands: Commands,26mut meshes: ResMut<Assets<Mesh>>,27mut materials: ResMut<Assets<StandardMaterial>>,28) {29commands.spawn((30Camera3d::default(),31Transform::from_translation(Vec3::new(0.0, 0.0, 5.0)).looking_at(Vec3::default(), Vec3::Y),32FullscreenEffect { intensity: 0.005 },33));3435commands.spawn((36Mesh3d(meshes.add(Cuboid::default())),37MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),38Transform::default(),39));4041commands.spawn(DirectionalLight {42illuminance: 1_000.,43..default()44});45}4647#[derive(Component, ExtractComponent, Clone, Copy, ShaderType, Default)]48struct FullscreenEffect {49intensity: f32,50}5152impl FullscreenMaterial for FullscreenEffect {53fn fragment_shader() -> ShaderRef {54"shaders/fullscreen_effect.wgsl".into()55}5657// The `FullscreenMaterial` uses 3d schedules by default.58// To make this work in 2d, you would need to schedule to59// run in `Core2d` and in a `Core2dSystems` set.60//61// fn schedule() -> impl bevy::ecs::schedule::ScheduleLabel + Clone {62// bevy::core_pipeline::Core2d63// }64// fn run_in() -> impl SystemSet {65// bevy::core_pipeline::Core2dSystems::PostProcess66// }67}686970