mirror of
https://github.com/bevyengine/bevy
synced 2024-11-28 23:50:20 +00:00
b1a91a823f
* bevy_pbr2: Add support for most of the StandardMaterial textures Normal maps are not included here as they require tangents in a vertex attribute. * bevy_pbr2: Ensure RenderCommandQueue is ready for PbrShaders init * texture_pipelined: Add a light to the scene so we can see stuff * WIP bevy_pbr2: back to front sorting hack * bevy_pbr2: Uniform control flow for texture sampling in pbr.frag From 'fintelia' on the Bevy Render Rework Round 2 discussion: "My understanding is that GPUs these days never use the "execute both branches and select the result" strategy. Rather, what they do is evaluate the branch condition on all threads of a warp, and jump over it if all of them evaluate to false. If even a single thread needs to execute the if statement body, however, then the remaining threads are paused until that is completed." * bevy_pbr2: Simplify texture and sampler names The StandardMaterial_ prefix is no longer needed * bevy_pbr2: Match default 'AmbientColor' of current bevy_pbr for now * bevy_pbr2: Convert from non-linear to linear sRGB for the color uniform * bevy_pbr2: Add pbr_pipelined example * Fix view vector in pbr frag to work in ortho * bevy_pbr2: Use a 90 degree y fov and light range projection for lights * bevy_pbr2: Add AmbientLight resource * bevy_pbr2: Convert PointLight color to linear sRGB for use in fragment shader * bevy_pbr2: pbr.frag: Rename PointLight.projection to view_projection The uniform contains the view_projection matrix so this was incorrect. * bevy_pbr2: PointLight is an OmniLight as it has a radius * bevy_pbr2: Factoring out duplicated code * bevy_pbr2: Implement RenderAsset for StandardMaterial * Remove unnecessary texture and sampler clones * fix comment formatting * remove redundant Buffer:from * Don't extract meshes when their material textures aren't ready * make missing textures in the queue step an error Co-authored-by: Aevyrie <aevyrie@gmail.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
101 lines
3.2 KiB
Rust
101 lines
3.2 KiB
Rust
use bevy::{
|
|
ecs::prelude::*,
|
|
math::{Quat, Vec2, Vec3},
|
|
pbr2::{PbrBundle, StandardMaterial},
|
|
prelude::{App, AssetServer, Assets, Transform},
|
|
render2::{
|
|
camera::PerspectiveCameraBundle,
|
|
color::Color,
|
|
mesh::{shape, Mesh},
|
|
},
|
|
PipelinedDefaultPlugins,
|
|
};
|
|
|
|
/// This example shows various ways to configure texture materials in 3D
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(PipelinedDefaultPlugins)
|
|
.add_startup_system(setup.system())
|
|
.run();
|
|
}
|
|
|
|
/// sets up a scene with textured entities
|
|
fn setup(
|
|
mut commands: Commands,
|
|
asset_server: Res<AssetServer>,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
) {
|
|
// load a texture and retrieve its aspect ratio
|
|
let texture_handle = asset_server.load("branding/bevy_logo_dark_big.png");
|
|
let aspect = 0.25;
|
|
|
|
// create a new quad mesh. this is what we will apply the texture to
|
|
let quad_width = 8.0;
|
|
let quad_handle = meshes.add(Mesh::from(shape::Quad::new(Vec2::new(
|
|
quad_width,
|
|
quad_width * aspect,
|
|
))));
|
|
|
|
// this material renders the texture normally
|
|
let material_handle = materials.add(StandardMaterial {
|
|
base_color_texture: Some(texture_handle.clone()),
|
|
unlit: true,
|
|
..Default::default()
|
|
});
|
|
|
|
// this material modulates the texture to make it red (and slightly transparent)
|
|
let red_material_handle = materials.add(StandardMaterial {
|
|
base_color: Color::rgba(1.0, 0.0, 0.0, 0.5),
|
|
base_color_texture: Some(texture_handle.clone()),
|
|
unlit: true,
|
|
..Default::default()
|
|
});
|
|
|
|
// and lets make this one blue! (and also slightly transparent)
|
|
let blue_material_handle = materials.add(StandardMaterial {
|
|
base_color: Color::rgba(0.0, 0.0, 1.0, 0.5),
|
|
base_color_texture: Some(texture_handle),
|
|
unlit: true,
|
|
..Default::default()
|
|
});
|
|
|
|
// textured quad - normal
|
|
commands.spawn_bundle(PbrBundle {
|
|
mesh: quad_handle.clone(),
|
|
material: material_handle,
|
|
transform: Transform {
|
|
translation: Vec3::new(0.0, 0.0, 1.5),
|
|
rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
});
|
|
// textured quad - modulated
|
|
commands.spawn_bundle(PbrBundle {
|
|
mesh: quad_handle.clone(),
|
|
material: red_material_handle,
|
|
transform: Transform {
|
|
translation: Vec3::new(0.0, 0.0, 0.0),
|
|
rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
});
|
|
// textured quad - modulated
|
|
commands.spawn_bundle(PbrBundle {
|
|
mesh: quad_handle,
|
|
material: blue_material_handle,
|
|
transform: Transform {
|
|
translation: Vec3::new(0.0, 0.0, -1.5),
|
|
rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
});
|
|
// camera
|
|
commands.spawn_bundle(PerspectiveCameraBundle {
|
|
transform: Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
..Default::default()
|
|
});
|
|
}
|