Skip to content

Commit d78e0c5

Browse files
author
Christophe Dehais
committed
Fix samples
1 parent 9a77b13 commit d78e0c5

10 files changed

Lines changed: 33 additions & 31 deletions

File tree

crates/bevy_pbr/src/ssr/ssr.wgsl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct BrdfSample {
6161

6262
fn sample_specular_brdf(wo: vec3<f32>, roughness: f32, F0: vec3<f32>, urand: vec2<f32>, N: vec3<f32>) -> BrdfSample {
6363
var brdf_sample: BrdfSample;
64-
64+
6565
// Use VNDF sampling for the half-vector.
6666
let wi = lighting::sample_visible_ggx(urand, roughness, N, wo);
6767
let H = normalize(wo + wi);
@@ -186,7 +186,10 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
186186
let tangent_to_world = orthonormalize(N);
187187

188188
let roughness = lighting::perceptualRoughnessToRoughness(perceptual_roughness);
189-
let F0 = pbr_functions::calculate_F0(pbr_input.material.base_color.rgb, pbr_input.material.metallic, pbr_input.material.reflectance);
189+
190+
let F0_dielectric = pbr_functions::calculate_F0_dielectric(pbr_input.material.ior, pbr_input.material.specular_tint);
191+
let F0_metallic = pbr_input.material.base_color.rgb;
192+
let F0 = mix(F0_dielectric, F0_metallic, pbr_input.material.metallic);
190193

191194
// Get some random numbers. If the spatio-temporal blue noise (STBN) texture
192195
// is available (i.e. not the 1x1 placeholder), we use it. Otherwise, we
@@ -220,7 +223,7 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
220223
// Sample the BRDF.
221224
let N_tangent = vec3(0.0, 0.0, 1.0);
222225
let V_tangent = V * tangent_to_world;
223-
226+
224227
let brdf_sample = sample_specular_brdf(V_tangent, roughness, F0, urand, N_tangent);
225228
let R_stochastic = tangent_to_world * brdf_sample.wi;
226229
let brdf_sample_value_over_pdf = brdf_sample.value_over_pdf;
@@ -238,7 +241,8 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
238241
// Unpack values required for environment mapping.
239242
let base_color = pbr_input.material.base_color.rgb;
240243
let metallic = pbr_input.material.metallic;
241-
let reflectance = pbr_input.material.reflectance;
244+
let ior = pbr_input.material.ior;
245+
let specular_tint = pbr_input.material.specular_tint;
242246
let specular_transmission = pbr_input.material.specular_transmission;
243247
let diffuse_transmission = pbr_input.material.diffuse_transmission;
244248

@@ -263,7 +267,7 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
263267
);
264268
let NdotV = max(dot(N, V), 0.0001);
265269
let F_ab = lighting::F_AB(perceptual_roughness, NdotV);
266-
let F0_dielectric = pbr_functions::calculate_F0_dielectric(reflectance);
270+
let F0_dielectric = pbr_functions::calculate_F0_dielectric(ior, specular_tint);
267271

268272
// Don't add stochastic noise to hits that sample the prefiltered env map.
269273
// The prefiltered env map already accounts for roughness.

examples/3d/fog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn setup_pyramid_scene(
7878
Mesh3d(meshes.add(Sphere::default())),
7979
MeshMaterial3d(materials.add(StandardMaterial {
8080
base_color: Srgba::hex("126212CC").unwrap().into(),
81-
reflectance: 1.0,
81+
ior: 2.33,
8282
perceptual_roughness: 0.0,
8383
metallic: 0.5,
8484
alpha_mode: AlphaMode::Blend,

examples/3d/motion_blur.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn spawn_barriers(
180180
let capsule = meshes.add(Capsule3d::default());
181181
let matl = materials.add(StandardMaterial {
182182
base_color: Color::srgb_u8(255, 87, 51),
183-
reflectance: 1.0,
183+
specular_tint: Color::linear_rgb(4.0, 4.0, 4.0),
184184
..default()
185185
});
186186
let mut spawn_with_offset = |offset: f32| {

examples/3d/parallax_mapping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn setup(
242242
// standard material derived from dark green, but
243243
// with roughness and reflectance set.
244244
perceptual_roughness: 0.45,
245-
reflectance: 0.18,
245+
specular_tint: Color::linear_rgb(0.77, 0.77, 0.77),
246246
..Color::srgb_u8(0, 80, 0).into()
247247
})),
248248
Transform::from_xyz(0.0, -1.0, 0.0),

examples/3d/render_to_texture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn setup(
4040
let cube_handle = meshes.add(Cuboid::new(4.0, 4.0, 4.0));
4141
let cube_material_handle = materials.add(StandardMaterial {
4242
base_color: Color::srgb(0.8, 0.7, 0.6),
43-
reflectance: 0.02,
43+
specular: 0.04,
4444
unlit: false,
4545
..default()
4646
});
@@ -86,7 +86,7 @@ fn setup(
8686
// This material has the texture that has been rendered.
8787
let material_handle = materials.add(StandardMaterial {
8888
base_color_texture: Some(image_handle),
89-
reflectance: 0.02,
89+
specular: 0.04,
9090
unlit: false,
9191
..default()
9292
});

examples/3d/specular_tint.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn setup(
107107
// We want only reflected specular light here, so we set the base
108108
// color as black.
109109
base_color: Color::BLACK,
110-
reflectance: 1.0,
110+
specular: 2.0,
111111
specular_tint: Color::hsva(app_status.hue, 1.0, 1.0, 1.0),
112112
// The object must not be metallic, or else the reflectance is
113113
// ignored per the Filament spec:
@@ -199,13 +199,11 @@ fn toggle_specular_map(
199199
// Adjust the tint type.
200200
match app_status.tint_type {
201201
TintType::Solid => {
202-
material.reflectance = 1.0;
202+
// material.reflectance = 1.0;
203+
material.specular_tint = Color::linear_rgb(2.0, 2.0, 2.0);
203204
material.specular_tint_texture = None;
204205
}
205206
TintType::Map => {
206-
// Set reflectance to 2.0 to spread out the map's reflectance
207-
// range from the default [0.0, 0.5] to [0.0, 1.0].
208-
material.reflectance = 2.0;
209207
// As the tint map is multiplied by the tint color, we set the
210208
// latter to white so that only the map has an effect.
211209
material.specular_tint = WHITE.into();

examples/3d/ssao.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn setup(
3939
let material = materials.add(StandardMaterial {
4040
base_color: Color::srgb(0.5, 0.5, 0.5),
4141
perceptual_roughness: 1.0,
42-
reflectance: 0.0,
42+
specular_tint: Color::linear_rgb(0.0, 0.0, 0.0),
4343
..default()
4444
});
4545
commands.spawn((
@@ -62,7 +62,7 @@ fn setup(
6262
MeshMaterial3d(materials.add(StandardMaterial {
6363
base_color: Color::srgb(0.4, 0.4, 0.4),
6464
perceptual_roughness: 1.0,
65-
reflectance: 0.0,
65+
specular_tint: Color::linear_rgb(0.0, 0.0, 0.0),
6666
..default()
6767
})),
6868
SphereMarker,

examples/3d/transmission.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! | `A` / `S` | Decrease / Increase Thickness |
1212
//! | `Z` / `X` | Decrease / Increase IOR |
1313
//! | `E` / `R` | Decrease / Increase Perceptual Roughness |
14-
//! | `U` / `I` | Decrease / Increase Reflectance |
14+
//! | `U` / `I` | Decrease / Increase Specular strength |
1515
//! | Arrow Keys | Control Camera |
1616
//! | `C` | Randomize Colors |
1717
//! | `H` | Toggle HDR + Bloom |
@@ -226,14 +226,14 @@ fn setup(
226226
// Chessboard Plane
227227
let black_material = materials.add(StandardMaterial {
228228
base_color: Color::BLACK,
229-
reflectance: 0.3,
229+
specular: 0.85,
230230
perceptual_roughness: 0.8,
231231
..default()
232232
});
233233

234234
let white_material = materials.add(StandardMaterial {
235235
base_color: Color::WHITE,
236-
reflectance: 0.3,
236+
specular: 0.85,
237237
perceptual_roughness: 0.8,
238238
..default()
239239
});
@@ -264,7 +264,7 @@ fn setup(
264264
base_color: Color::WHITE,
265265
diffuse_transmission: 0.6,
266266
perceptual_roughness: 0.8,
267-
reflectance: 1.0,
267+
specular_tint: Color::linear_rgb(4.0, 4.0, 4.0),
268268
double_sided: true,
269269
cull_mode: None,
270270
..default()
@@ -351,7 +351,7 @@ struct ExampleState {
351351
thickness: f32,
352352
ior: f32,
353353
perceptual_roughness: f32,
354-
reflectance: f32,
354+
specular: f32,
355355
auto_camera: bool,
356356
}
357357

@@ -366,7 +366,7 @@ impl Default for ExampleState {
366366
thickness: 1.8,
367367
ior: 1.5,
368368
perceptual_roughness: 0.12,
369-
reflectance: 0.5,
369+
specular: 1.0,
370370
auto_camera: true,
371371
}
372372
}
@@ -417,9 +417,9 @@ fn example_control_system(
417417
}
418418

419419
if input.pressed(KeyCode::KeyI) {
420-
state.reflectance = (state.reflectance + time.delta_secs()).min(1.0);
420+
state.specular = (state.specular + time.delta_secs()).min(1.0);
421421
} else if input.pressed(KeyCode::KeyU) {
422-
state.reflectance = (state.reflectance - time.delta_secs()).max(0.0);
422+
state.specular = (state.specular - time.delta_secs()).max(0.0);
423423
}
424424

425425
if input.pressed(KeyCode::KeyR) {
@@ -437,7 +437,7 @@ fn example_control_system(
437437
material.thickness = state.thickness;
438438
material.ior = state.ior;
439439
material.perceptual_roughness = state.perceptual_roughness;
440-
material.reflectance = state.reflectance;
440+
material.specular = state.specular;
441441
}
442442

443443
if controls.diffuse_transmission {
@@ -550,7 +550,7 @@ fn example_control_system(
550550
" A / S Thickness: {:.2}\n",
551551
" Z / X IOR: {:.2}\n",
552552
" E / R Perceptual Roughness: {:.2}\n",
553-
" U / I Reflectance: {:.2}\n",
553+
" U / I Specular: {:.2}\n",
554554
" Arrow Keys Control Camera\n",
555555
" C Randomize Colors\n",
556556
" H HDR + Bloom: {}\n",
@@ -564,7 +564,7 @@ fn example_control_system(
564564
state.thickness,
565565
state.ior,
566566
state.perceptual_roughness,
567-
state.reflectance,
567+
state.specular,
568568
if hdr { "ON " } else { "OFF" },
569569
if cfg!(any(feature = "webgpu", not(target_arch = "wasm32"))) {
570570
if depth_prepass.is_some() {

examples/ui/render_ui_to_texture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn setup(
120120
// This material has the texture that has been rendered.
121121
let material_handle = materials.add(StandardMaterial {
122122
base_color_texture: Some(image_handle),
123-
reflectance: 0.02,
123+
specular: 0.04,
124124
unlit: false,
125125
..default()
126126
});

tests/3d/test_invalid_skinned_mesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn setup_environment(
8383
Mesh3d(mesh_assets.add(Plane3d::default().mesh().size(100.0, 100.0).normal(Dir3::Z))),
8484
MeshMaterial3d(material_assets.add(StandardMaterial {
8585
base_color: Color::srgb(0.05, 0.05, 0.15),
86-
reflectance: 0.2,
86+
specular: 0.4,
8787
..default()
8888
})),
8989
));
@@ -149,7 +149,7 @@ fn setup_meshes(
149149

150150
let background_material_handle = material_assets.add(StandardMaterial {
151151
base_color: Color::srgb(0.05, 0.15, 0.05),
152-
reflectance: 0.2,
152+
specular: 0.4,
153153
..default()
154154
});
155155

0 commit comments

Comments
 (0)