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

[Merged by Bors] - Rebase of existing PBR work #1554

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
13c552a
semi working pbr.
StarArawn Mar 7, 2021
cc1a4ba
More changes.
StarArawn Mar 4, 2021
8975234
Removed unused vars.
StarArawn Aug 19, 2020
13d1629
example/pbr added, example/msaa restored to a simple box
IngmarBitter Dec 29, 2020
13a9baa
to fix: spheres appear in default color, not the one specified in the…
IngmarBitter Dec 29, 2020
5ef2912
vary key PBR parameters on a grid of spheres to show the effect
IngmarBitter Dec 29, 2020
5a5e1ae
Improve example PBR parameter calculation
mtsr Mar 4, 2021
1a2e022
Remove unused variable and comments
mtsr Mar 4, 2021
0ebeb11
Use from_xyz
mtsr Mar 4, 2021
f8c3c7c
Correct default roughness/metallic
mtsr Mar 4, 2021
96dce66
Add perceptualRoughness->roughness and clamping
mtsr Mar 4, 2021
c9cc858
Remove commented code
mtsr Mar 5, 2021
56dd585
Reorder fields
mtsr Mar 5, 2021
314b64f
whitespace
mtsr Mar 6, 2021
e55ff3e
Use world position
mtsr Mar 6, 2021
3b3e33a
Rework, fix and document
mtsr Mar 6, 2021
dd9f2bc
Rename albedo->base_color, pbr->roughness/metallic
mtsr Mar 7, 2021
f8e744d
Add reflectance material property
mtsr Mar 6, 2021
08afa11
Add .clang-format for GLSL
mtsr Mar 6, 2021
81523f8
Document standard PBR properties
mtsr Mar 7, 2021
177ece9
Add comment to base_color_factor mentioning albedo
mtsr Mar 7, 2021
d1c2e41
Swizzle using .rgb for colors
mtsr Mar 7, 2021
f0a8cbf
Document attenuation and light accumulation
mtsr Mar 7, 2021
f6f15f8
Fix #ifdef STANDARDMATERIAL_BASE_COLOR_TEXTURE
mtsr Mar 7, 2021
0944cd8
Add reinhard_luminance tonemapping
mtsr Mar 7, 2021
2c3e5e5
Fix examples by adding light radius of 20.0
mtsr Mar 7, 2021
b989da5
Fix wireframe example
mtsr Mar 7, 2021
c2c965c
Rename light.radius to light.range
mtsr Mar 7, 2021
ac7a88e
Adjust comments
mtsr Mar 7, 2021
da36141
Remove 1/4PI term
mtsr Mar 7, 2021
2f6ccce
Add most basic ambient term
mtsr Mar 8, 2021
917d1cf
Disable gamma correction
mtsr Mar 8, 2021
a3fb860
Add PBR parameter newtypes/enums for CPU remapping
mtsr Mar 8, 2021
07f2f9f
Use gold in pbr example
mtsr Mar 8, 2021
f720ffc
Revert "Add PBR parameter newtypes/enums for CPU remapping"
mtsr Mar 9, 2021
85a695e
Add comment about not using mix
mtsr Mar 9, 2021
79a4d0a
Fix bad commit
mtsr Mar 9, 2021
c57e56d
Hoist NdotV out of light loop
mtsr Mar 9, 2021
4b358ba
Move light closer in pbr example
mtsr Mar 9, 2021
fdc07ab
Better ambient term
mtsr Mar 9, 2021
aaafa67
Remove unused imports
mtsr Mar 9, 2021
39c6b28
Remove unused import
mtsr Mar 9, 2021
c3d1085
Fix failing test
mtsr Mar 10, 2021
0eb6a1b
Premultiply light color by intensity
mtsr Mar 10, 2021
2dad217
Calculate buffer_size once
mtsr Mar 10, 2021
ca2b45a
Extend default light range, simplifying examples
mtsr Mar 10, 2021
9826371
Added additional comment to roughness default
mtsr Mar 11, 2021
25b14dc
Remove `_factor` from StandardMaterial properties
mtsr Mar 12, 2021
23bd4b3
Remove .clang-format
mtsr Mar 12, 2021
1666f45
Remove `forward` in pipeline naming
mtsr Mar 12, 2021
97d034a
Clear and consistent input/output naming
mtsr Mar 12, 2021
f623307
Add PBR example to example README.md
mtsr Mar 13, 2021
20984af
Remove unused v_Position and clean up
mtsr Mar 13, 2021
9cbb811
Remove comment about 'aspirational' name pbr
mtsr Mar 16, 2021
36d5608
Uncomment `//unused float` in pbr.frag
mtsr Mar 16, 2021
1d4d606
Add camera position and update shaders
cart Mar 19, 2021
5f47748
increase default intensity
cart Mar 19, 2021
243b7dc
rename "pipeline" to "pbr_pipeline"
cart Mar 19, 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
Remove _factor from StandardMaterial properties
  • Loading branch information
mtsr authored and cart committed Mar 19, 2021
commit 25b14dcf375ebac0670599dea0646d91e1974ca7
6 changes: 3 additions & 3 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ fn load_material(material: &Material, load_context: &mut LoadContext) -> Handle<
load_context.set_labeled_asset(
&material_label,
LoadedAsset::new(StandardMaterial {
base_color_factor: Color::rgba(color[0], color[1], color[2], color[3]),
base_color: Color::rgba(color[0], color[1], color[2], color[3]),
base_color_texture: texture_handle,
roughness_factor: pbr.roughness_factor(),
metallic_factor: pbr.metallic_factor(),
roughness: pbr.roughness_factor(),
metallic: pbr.metallic_factor(),
unlit: material.unlit(),
..Default::default()
})
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Plugin for PbrPlugin {
materials.set_untracked(
Handle::<StandardMaterial>::default(),
StandardMaterial {
base_color_factor: Color::PINK,
base_color: Color::PINK,
unlit: true,
..Default::default()
},
Expand Down
20 changes: 13 additions & 7 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ use bevy_render::{color::Color, renderer::RenderResources, shader::ShaderDefs, t
#[uuid = "dace545e-4bc6-4595-a79d-c224fc694975"]
pub struct StandardMaterial {
/// Doubles as diffuse albedo for non-metallic, specular for metallic and a mix for everything in between
pub base_color_factor: Color,
/// 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,
#[shader_def]
pub base_color_texture: Option<Handle<Texture>>,
/// Linear perceptual roughness, clamped to [0.089, 1.0] in the shader
/// Defaults to minimum of 0.089
pub roughness_factor: f32,
/// If used together with a roughness/metallic texture, this is factored into the final base color
/// as `roughness * roughness_texture_value`
pub roughness: f32,
/// From [0.0, 1.0], dielectric to pure metallic
pub metallic_factor: f32,
/// If used together with a roughness/metallic texture, this is factored into the final base color
/// as `metallic * metallic_texture_value`
pub metallic: f32,
/// 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,
mtsr marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,16 +33,16 @@ pub struct StandardMaterial {
impl Default for StandardMaterial {
fn default() -> Self {
StandardMaterial {
base_color_factor: Color::rgb(1.0, 1.0, 1.0),
base_color: Color::rgb(1.0, 1.0, 1.0),
base_color_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_factor: 0.089,
roughness: 0.089,
// Few materials are purely dielectric or metallic
// This is just a default for mostly-dielectric
metallic_factor: 0.01,
metallic: 0.01,
// 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,
Expand All @@ -48,7 +54,7 @@ impl Default for StandardMaterial {
impl From<Color> for StandardMaterial {
fn from(color: Color) -> Self {
StandardMaterial {
base_color_factor: color,
base_color: color,
..Default::default()
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_pbr/src/render_graph/forward_pipeline/forward.frag
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ layout(set = 1, binding = 0) uniform Lights {
Light SceneLights[MAX_LIGHTS];
};

layout(set = 3, binding = 0) uniform StandardMaterial_base_color_factor {
vec4 base_color_factor;
layout(set = 3, binding = 0) uniform StandardMaterial_base_color {
vec4 base_color;
};

#ifdef STANDARDMATERIAL_BASE_COLOR_TEXTURE
Expand All @@ -74,11 +74,11 @@ layout(set = 3,

#ifndef STANDARDMATERIAL_UNLIT

layout(set = 3, binding = 3) uniform StandardMaterial_roughness_factor {
layout(set = 3, binding = 3) uniform StandardMaterial_roughness {
float perceptual_roughness;
};

layout(set = 3, binding = 4) uniform StandardMaterial_metallic_factor {
layout(set = 3, binding = 4) uniform StandardMaterial_metallic {
float metallic;
};

Expand Down Expand Up @@ -248,7 +248,7 @@ vec3 reinhard_extended_luminance(vec3 color, float max_white_l) {
#endif

void main() {
vec4 output_color = base_color_factor;
vec4 output_color = base_color;
#ifdef STANDARDMATERIAL_BASE_COLOR_TEXTURE
output_color *= texture(sampler2D(StandardMaterial_base_color_texture,
StandardMaterial_base_color_texture_sampler),
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn setup(
) {
let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 2.0 }));
let cube_material_handle = materials.add(StandardMaterial {
base_color_factor: Color::rgb(0.8, 0.7, 0.6),
base_color: Color::rgb(0.8, 0.7, 0.6),
..Default::default()
});

Expand Down
6 changes: 3 additions & 3 deletions examples/3d/pbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ fn setup(
subdivisions: 32,
})),
material: materials.add(StandardMaterial {
base_color_factor: Color::hex("ffd891").unwrap(),
base_color: Color::hex("ffd891").unwrap(),
// vary key PBR parameters on a grid of spheres to show the effect
metallic_factor: y01,
roughness_factor: x01,
metallic: y01,
roughness: x01,
..Default::default()
}),
transform: Transform::from_xyz(x as f32, y as f32, 0.0),
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn move_cubes(
for (mut transform, material_handle) in query.iter_mut() {
let material = materials.get_mut(material_handle).unwrap();
transform.translation += Vec3::new(1.0, 0.0, 0.0) * time.delta_seconds();
material.base_color_factor =
material.base_color =
Color::BLUE * Vec3::splat((3.0 * time.seconds_since_startup() as f32).sin());
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ fn setup(
commands.spawn(PbrBundle {
mesh: cube_handle.clone(),
material: materials.add(StandardMaterial {
base_color_factor: Color::rgb(
base_color: Color::rgb(
rng.gen_range(0.0..1.0),
rng.gen_range(0.0..1.0),
rng.gen_range(0.0..1.0),
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ fn setup(

// this material modulates the texture to make it red (and slightly transparent)
let red_material_handle = materials.add(StandardMaterial {
base_color_factor: Color::rgba(1.0, 0.0, 0.0, 0.5),
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_factor: Color::rgba(0.0, 0.0, 1.0, 0.5),
base_color: Color::rgba(0.0, 0.0, 1.0, 0.5),
base_color_texture: Some(texture_handle),
unlit: true,
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/z_sort_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn camera_order_color_system(
if let Ok(material_handle) = material_query.get(visible_entity.entity) {
let material = materials.get_mut(&*material_handle).unwrap();
let value = 1.0 - (visible_entity.order.0.sqrt() - 10.0) / 7.0;
material.base_color_factor = Color::rgb(value, value, value);
material.base_color = Color::rgb(value, value, value);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/asset/asset_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn setup(

// You can also add assets directly to their Assets<T> storage:
let material_handle = materials.add(StandardMaterial {
base_color_factor: Color::rgb(0.8, 0.7, 0.6),
base_color: Color::rgb(0.8, 0.7, 0.6),
..Default::default()
});

Expand Down