Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy_gltf2 #27

Open
wants to merge 108 commits into
base: pipelined-rendering
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
c074777
pipelined rendering proof of concept
cart Apr 11, 2021
6600dde
Added compute to the new pipelined renderer.
StarArawn May 30, 2021
13d613b
Share code between passes for setting bind groups.
StarArawn May 31, 2021
4b26031
Reverted combining of set_bind_group between different passes.
StarArawn May 31, 2021
18a4fcf
SubGraphs, Views, Shadows, and more
cart Jun 2, 2021
53a442f
Fix ExclusiveSystemCoerced so it updates system with new archetypes
cart Jun 17, 2021
334a857
StandardMaterial flat values (#3)
superdump Jun 18, 2021
f7b61a3
bevy_pbr2: Add support for most of the StandardMaterial textures
superdump Jun 19, 2021
a7d743f
bevy_pbr2: Ensure RenderCommandQueue is ready for PbrShaders init
superdump Jun 19, 2021
78e7603
texture_pipelined: Add a light to the scene so we can see stuff
superdump Jun 19, 2021
984b9ad
WIP bevy_pbr2: back to front sorting hack
superdump Jun 19, 2021
d2f11bd
bevy_pbr2: Uniform control flow for texture sampling in pbr.frag
superdump Jun 20, 2021
af71877
bevy_pbr2: Simplify texture and sampler names
superdump Jun 20, 2021
4c32a3a
bevy_pbr2: Match default 'AmbientColor' of current bevy_pbr for now
superdump Jun 20, 2021
b5aae65
bevy_pbr2: Convert from non-linear to linear sRGB for the color uniform
superdump Jun 20, 2021
57617b2
bevy_pbr2: Add pbr_pipelined example
superdump Jun 20, 2021
64385dc
Fix view vector in pbr frag to work in ortho
aevyrie Jun 21, 2021
f40c3b9
bevy_pbr2: Use a 90 degree y fov and light range projection for lights
superdump Jun 21, 2021
d41f69a
bevy_pbr2: Add AmbientLight resource
superdump Jun 21, 2021
3965713
bevy_pbr2: Convert PointLight color to linear sRGB for use in fragmen…
superdump Jun 21, 2021
5d1dfb1
bevy_pbr2: pbr.frag: Rename PointLight.projection to view_projection
superdump Jun 21, 2021
dd758b9
bevy_pbr2: PointLight is an OmniLight as it has a radius
superdump Jun 21, 2021
78dcc39
bevy_pbr2: Factoring out duplicated code
superdump Jun 21, 2021
530a938
bevy_pbr2: Add support for DirectionalLight
superdump Jun 21, 2021
6fe9950
bevy_pbr2: Add support for directional light shadows
superdump Jun 22, 2021
57e7ef8
bevy_pbr2: Add a configurable shadow bias min/max to avoid self-shado…
superdump Jun 22, 2021
d7af224
bevy_pbr2: Fix use of both omni and directional lights
superdump Jun 23, 2021
f76ea05
bevy_pbr2: Move directional light's view back to the origin
superdump Jun 23, 2021
fd5b0f3
3d_scene_pipelined: Move the cube to sit on the plane
superdump Jun 23, 2021
8fbdf64
3d_scene_pipelined: Remove material properties that prevent receiving…
superdump Jun 23, 2021
3a9a23e
3d_scene_pipelined: Add more lights and animate the directional light
superdump Jun 23, 2021
008b494
bevy_gltf2: Copy bevy_gltf and get it working with the pipelined-rend…
superdump Jun 23, 2021
fbe8456
bevy_render now uses wgpu directly
cart Jun 21, 2021
2cc0c56
fix tracing and add graph spans
cart Jun 25, 2021
64f99b2
RenderAssetPlugin
cart Jun 25, 2021
b20a500
Merge branch 'pipelined-rendering' into standard-material-textures
superdump Jun 25, 2021
50f01a3
bevy_pbr2: Implement RenderAsset for StandardMaterial
superdump Jun 25, 2021
14829c6
Merge branch 'standard-material-textures' into directional-light-and-…
superdump Jun 25, 2021
48ca304
Merge branch 'directional-light-and-shadow' into pipelined-gltf
superdump Jun 25, 2021
eef62d3
Port Mesh to RenderAsset, add Slab and FrameSlabMap garbage collectio…
cart Jun 26, 2021
a0eb342
Merge branch 'pipelined-rendering' into standard-material-textures
superdump Jun 27, 2021
7cbb00d
Merge branch 'standard-material-textures' into directional-light-and-…
superdump Jun 27, 2021
337dc28
Merge branch 'directional-light-and-shadow' into pipelined-gltf
superdump Jun 27, 2021
b3e2fab
bevy_pbr2: Add support for most of the StandardMaterial textures (#4)
superdump Jun 27, 2021
9f6ef59
Merge branch 'pipelined-rendering' into directional-light-and-shadow
superdump Jun 28, 2021
ff19263
Merge branch 'directional-light-and-shadow' into pipelined-gltf
superdump Jun 28, 2021
cf7e24c
Add `log` crate compatibility to bevy_log
cart Jun 28, 2021
b6d9277
Begin WGSL port (sprites work, pbr lights are broken)
cart Jun 28, 2021
0633e65
Force main thread for prepare_windows system
TheRawMeatball Jun 29, 2021
f8d96d1
bevy_pbr2: Fix light uniforms
superdump Jun 29, 2021
fba4011
bevy_pbr2: Fix the position outputs from the vertex stage
superdump Jun 29, 2021
0fecd3d
Merge branch 'pipelined-rendering' into directional-light-and-shadow
superdump Jun 29, 2021
3a19a63
Merge branch 'thread-fix' into directional-light-and-shadow
superdump Jun 29, 2021
10819b0
Merge branch 'wgsl-pbr-fixes' into directional-light-and-shadow
superdump Jun 29, 2021
1635de4
Force main thread for prepare_windows system (#11)
TheRawMeatball Jun 29, 2021
03cf087
wgsl PBR fixes (#12)
superdump Jun 29, 2021
df6074d
Merge branch 'pipelined-rendering' into directional-light-and-shadow
superdump Jun 30, 2021
f510672
bevy_pbr2: Use the infinite reverse right-handed perspective projection
superdump Jun 30, 2021
ff33307
crevice: Add std{140,430}_padded_size_static
superdump Jul 1, 2021
0530368
bevy_render2/bevy_pbr2: Use std140_padded_size_static
superdump Jul 1, 2021
6226865
Merge branch 'crevice-padded-size' into directional-light-and-shadow
superdump Jul 1, 2021
7ed3832
bevy_pbr2: Port directional lights and shadows to wgsl
superdump Jul 1, 2021
f454e39
bevy_render2/bevy_pbr2: Update to wgpu 0.9 / naga 0.5 (#19)
superdump Jul 1, 2021
5de75a5
Fixed issue where transform buffer wasn't creating new bindings on re…
StarArawn Jul 1, 2021
bbb69ea
Allows resizing of windows (#8)
bilsen Jul 1, 2021
c0b6d05
bevy_pbr2: pbr.wgsl: Fix the orthographic projection check (#17)
superdump Jul 1, 2021
c16a030
Do not queue sprites/meshes if there are no views (#13)
superdump Jul 1, 2021
30e4b8d
Omnilight shadow map wgsl (#15)
mtsr Jul 1, 2021
d0c3185
omni light -> point light
cart Jul 1, 2021
9a79b79
fix clippy
cart Jul 2, 2021
f24b51a
Merge branch 'pipelined-rendering' into perspective-infinite-reverse-rh
superdump Jul 2, 2021
3b40e25
bevy_pbr2: Fix projection calculation simplification for infinite rev…
superdump Jul 2, 2021
e06cc8e
bevy_pbr2: Fix use of orthographic projection in 3D PBR
superdump Jul 2, 2021
515cda8
bevy_pbr2: Tweak hard-coded shadow bias for no acne
superdump Jul 2, 2021
8aa843a
bevy_pbr2: Add orthographic_pipelined example and tweak bias for shadows
superdump Jul 2, 2021
bbb9a81
Merge branch 'pipelined-rendering' into directional-light-and-shadow
superdump Jul 2, 2021
baf966c
3d_scene_pipelined: tweak shadow biases for this scene
superdump Jul 2, 2021
b59fa7f
3d_scene_pipelined: Use boxes for walls to avoid light leakage
superdump Jul 2, 2021
14965e7
3d_scene_pipelined: Remove duplicate camera
superdump Jul 2, 2021
4e01e37
Add something resembling the cornell box
superdump Jul 2, 2021
37efe64
cornell_box_pipelined: Improve the ceiling light a little
superdump Jul 2, 2021
6dc993b
Merge branch 'directional-light-and-shadow' into pipelined-gltf
superdump Jul 2, 2021
b68992e
load_gltf_pipelined: Directional light updates
superdump Jul 2, 2021
811ed3e
Small Fixes (#20)
james7132 Jul 7, 2021
98428bb
Revert "Merge branch 'crevice-padded-size' into directional-light-and…
superdump Jul 7, 2021
348adb9
bevy_pbr2: Fix GpuLights min_binding_size
superdump Jul 7, 2021
168058a
Merge branch 'directional-light-and-shadow' into perspective-infinite…
superdump Jul 7, 2021
6f01303
bevy_pbr2: Improve DirectionalLight ::default() ergonomics
superdump Jul 7, 2021
77bd454
bevy_pbr2: Add a shadow normal bias
superdump Jul 7, 2021
bd13dce
Directional light and shadow (#6)
superdump Jul 8, 2021
7b8cda4
add glsl support
cart Jul 8, 2021
305ff4c
fmt + clippy
cart Jul 8, 2021
3dfffe6
Merge branch 'pipelined-rendering' into perspective-infinite-reverse-rh
superdump Jul 8, 2021
7612ac0
3d_scene_pipelined: Make the directional light angle shallower to pro…
superdump Jul 8, 2021
c8d991c
bevy_pbr2: Simplify shadow biases by moving them to linear depth
superdump Jul 8, 2021
b920f91
bevy_pbr2: Remove additional * NdotL in the point light normal bias
superdump Jul 8, 2021
c006707
Merge branch 'pipelined-rendering' into pipelined-gltf
superdump Jul 8, 2021
b9dcf2f
Merge branch 'perspective-infinite-reverse-rh' into pipelined-gltf
superdump Jul 8, 2021
c297929
switch sprites back to wgsl shader
cart Jul 9, 2021
fb804e0
Fixed issue with how texture arrays were uploaded with write_texture.…
StarArawn Jul 14, 2021
b340e2d
expose subgraph iterator (#25)
jakobhellermann Jul 14, 2021
3560715
Better depth biases (#23)
superdump Jul 16, 2021
6604d47
Scale normal bias by texel size (#26)
superdump Jul 19, 2021
c86c932
Merge branch 'pipelined-rendering' into pipelined-gltf
superdump Jul 20, 2021
aa2ac11
load_gltf_pipelined: Fixes for pipelined-rendering updates
superdump Jul 20, 2021
3d7d88d
examples: Factor out flying camera controller
superdump Jul 20, 2021
31f90fb
Revert perspective inverse changes
superdump Jul 20, 2021
51d9467
Revert "examples: Factor out flying camera controller"
superdump Jul 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bevy_pbr2: Add support for most of the StandardMaterial textures
Normal maps are not included here as they require tangents in a vertex attribute.
superdump committed Jun 19, 2021
commit f7b61a3155ab7fdbc894951cac13b8cbf10658ba
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -177,6 +177,10 @@ path = "examples/3d/spawner.rs"
name = "texture"
path = "examples/3d/texture.rs"

[[example]]
name = "texture_pipelined"
path = "examples/3d/texture_pipelined.rs"

[[example]]
name = "update_gltf_scene"
path = "examples/3d/update_gltf_scene.rs"
10 changes: 5 additions & 5 deletions examples/3d/3d_scene_pipelined.rs
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ fn setup(
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
material: materials.add(StandardMaterial {
color: Color::INDIGO,
roughness: 1.0,
base_color: Color::INDIGO,
perceptual_roughness: 1.0,
..Default::default()
}),
..Default::default()
@@ -49,8 +49,8 @@ fn setup(
.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(StandardMaterial {
color: Color::PINK,
roughness: 0.0,
base_color: Color::PINK,
perceptual_roughness: 0.0,
metallic: 1.0,
reflectance: 1.0,
..Default::default()
@@ -67,7 +67,7 @@ fn setup(
..Default::default()
})),
material: materials.add(StandardMaterial {
color: Color::LIME_GREEN,
base_color: Color::LIME_GREEN,
..Default::default()
}),
transform: Transform::from_xyz(1.5, 1.0, 1.5),
98 changes: 98 additions & 0 deletions examples/3d/texture_pipelined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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()),
..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()),
..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),
..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()
});
}
1 change: 1 addition & 0 deletions pipelined/bevy_pbr2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ bevy_transform = { path = "../../crates/bevy_transform", version = "0.5.0" }
bevy_utils = { path = "../../crates/bevy_utils", version = "0.5.0" }

# other
bitflags = "1.2"
# direct dependency required for derive macro
bytemuck = { version = "1", features = ["derive"] }
crevice = { path = "../../crates/crevice" }
71 changes: 54 additions & 17 deletions pipelined/bevy_pbr2/src/material.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use bevy_render2::{
render_command::RenderCommandQueue,
render_resource::{BufferId, BufferInfo, BufferUsage},
renderer::{RenderResourceContext, RenderResources},
texture::Texture,
};
use bevy_utils::HashSet;
use crevice::std140::{AsStd140, Std140};
@@ -18,25 +19,45 @@ pub struct StandardMaterialGpuData {
pub buffer: BufferId,
}

bitflags::bitflags! {
#[repr(transparent)]
pub struct StandardMaterialFlags: u32 {
const DOUBLE_SIDED = 1;
const NONE = 0;
const UNINITIALIZED = 0xFFFF;
}
}

/// A material with "standard" properties used in PBR lighting
/// Standard property values with pictures here https://google.github.io/filament/Material%20Properties.pdf
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "7494888b-c082-457b-aacf-517228cc0c22"]
pub struct StandardMaterial {
/// Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything
/// in between.
pub color: Color,
/// in between If used together with a base_color_texture, this is factored into the final
/// base color as `base_color * base_color_texture_value`
pub base_color: Color,
pub base_color_texture: Option<Handle<Texture>>,
// Use a color for user friendliness even though we technically don't use the alpha channel
// Might be used in the future for exposure correction in HDR
pub emissive: Color,
pub emissive_texture: Option<Handle<Texture>>,
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader
/// Defaults to minimum of 0.089
pub roughness: f32,
/// If used together with a roughness/metallic texture, this is factored into the final base
/// color as `roughness * roughness_texture_value`
pub perceptual_roughness: f32,
/// From [0.0, 1.0], dielectric to pure metallic
/// If used together with a roughness/metallic texture, this is factored into the final base
/// color as `metallic * metallic_texture_value`
pub metallic: f32,
pub metallic_roughness_texture: Option<Handle<Texture>>,
/// Specular intensity for non-metals on a linear scale of [0.0, 1.0]
/// defaults to 0.5 which is mapped to 4% reflectance in the shader
pub reflectance: f32,
// Use a color for user friendliness even though we technically don't use the alpha channel
// Might be used in the future for exposure correction in HDR
pub emissive: Color,
pub occlusion_texture: Option<Handle<Texture>>,
/// Flags to configure shader options
pub flags: StandardMaterialFlags,
pub gpu_data: Option<StandardMaterialGpuData>,
}

@@ -49,20 +70,25 @@ impl StandardMaterial {
impl Default for StandardMaterial {
fn default() -> Self {
StandardMaterial {
color: Color::rgb(1.0, 1.0, 1.0),
base_color: Color::rgb(1.0, 1.0, 1.0),
base_color_texture: None,
emissive: Color::BLACK,
emissive_texture: None,
// This is the minimum the roughness is clamped to in shader code
// See https://google.github.io/filament/Filament.html#materialsystem/parameterization/
// It's the minimum floating point value that won't be rounded down to 0 in the
// calculations used. Although technically for 32-bit floats, 0.045 could be
// used.
roughness: 0.089,
perceptual_roughness: 0.089,
// Few materials are purely dielectric or metallic
// This is just a default for mostly-dielectric
metallic: 0.01,
metallic_roughness_texture: None,
// Minimum real-world reflectance is 2%, most materials between 2-5%
// Expressed in a linear scale and equivalent to 4% reflectance see https://google.github.io/filament/Material%20Properties.pdf
reflectance: 0.5,
emissive: Color::BLACK,
occlusion_texture: None,
flags: StandardMaterialFlags::NONE,
gpu_data: None,
}
}
@@ -71,7 +97,16 @@ impl Default for StandardMaterial {
impl From<Color> for StandardMaterial {
fn from(color: Color) -> Self {
StandardMaterial {
color,
base_color: color,
..Default::default()
}
}
}

impl From<Handle<Texture>> for StandardMaterial {
fn from(texture: Handle<Texture>) -> Self {
StandardMaterial {
base_color_texture: Some(texture),
..Default::default()
}
}
@@ -81,7 +116,10 @@ impl From<Color> for StandardMaterial {
pub struct StandardMaterialUniformData {
/// Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything
/// in between.
pub color: Vec4,
pub base_color: Vec4,
// Use a color for user friendliness even though we technically don't use the alpha channel
// Might be used in the future for exposure correction in HDR
pub emissive: Vec4,
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader
/// Defaults to minimum of 0.089
pub roughness: f32,
@@ -90,9 +128,7 @@ pub struct StandardMaterialUniformData {
/// Specular intensity for non-metals on a linear scale of [0.0, 1.0]
/// defaults to 0.5 which is mapped to 4% reflectance in the shader
pub reflectance: f32,
// Use a color for user friendliness even though we technically don't use the alpha channel
// Might be used in the future for exposure correction in HDR
pub emissive: Vec4,
pub flags: u32,
}

pub struct StandardMaterialPlugin;
@@ -143,11 +179,12 @@ pub fn standard_material_resource_system(
}

let value = StandardMaterialUniformData {
color: material.color.into(),
roughness: material.roughness,
base_color: material.base_color.into(),
emissive: material.emissive.into(),
roughness: material.perceptual_roughness,
metallic: material.metallic,
reflectance: material.reflectance,
emissive: material.emissive.into(),
flags: material.flags.bits,
};
let value_std140 = value.as_std140();

Loading