Skip to content

Commit

Permalink
pbr metallic spheres test doesn't use bloom
Browse files Browse the repository at this point in the history
  • Loading branch information
schell committed Dec 22, 2023
1 parent 18cbaac commit db34533
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 88 deletions.
90 changes: 2 additions & 88 deletions crates/renderling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ mod test {
// spheres with different metallic roughnesses lit by an environment map.
//
// see https://learnopengl.com/PBR/Lighting
fn gltf_pbr_metallic_roughness_spheres() {
fn pbr_metallic_roughness_spheres() {
let ss = 600;
let mut r =
Renderling::headless(ss, ss).with_background_color(Vec3::splat(0.0).extend(1.0));
Expand Down Expand Up @@ -1088,95 +1088,9 @@ mod test {
let hdr_image = SceneImage::from_hdr_path("../../img/hdr/resting_place.hdr").unwrap();
let skybox = crate::skybox::Skybox::new(&device, &queue, hdr_image, camera);
stage.set_skybox(skybox);
stage.set_has_bloom(true);

let img = r.render_image().unwrap();
img_diff::assert_img_eq("pbr_metallic_roughness_spheres.png", img);
}

#[test]
// Tests the initial implementation of pbr metallic roughness on an array of
// spheres with different metallic roughnesses lit by an environment map.
//
// see https://learnopengl.com/PBR/Lighting
fn legacy_pbr_metallic_roughness_spheres() {
let ss = 600;
let mut r =
Renderling::headless(ss, ss).with_background_color(Vec3::splat(0.0).extend(1.0));

let radius = 0.5;
let mut icosphere = icosahedron::Polyhedron::new_isocahedron(radius, 5);
icosphere.compute_triangle_normals();
let icosahedron::Polyhedron {
positions,
normals,
cells,
..
} = icosphere;
log::info!("icosphere created");

let to_vertex = |ndx: &usize| -> Vertex {
let p: [f32; 3] = positions[*ndx].0.into();
let n: [f32; 3] = normals[*ndx].0.into();
Vertex::default().with_position(p).with_normal(n)
};
let sphere_vertices = cells.iter().flat_map(|icosahedron::Triangle { a, b, c }| {
let p0 = to_vertex(&a);
let p1 = to_vertex(&b);
let p2 = to_vertex(&c);
vec![p0, p1, p2]
});

let ss = ss as f32;
let projection = camera::perspective(ss, ss);
let k = 7;
let diameter = 2.0 * radius;
let spacing = radius * 0.25;
let len = (k - 1) as f32 * (diameter + spacing);
let half = len / 2.0;
let view = camera::look_at(
Vec3::new(half, half, 1.6 * len),
Vec3::new(half, half, 0.0),
Vec3::Y,
);

let mut builder = r
.new_scene()
.with_camera(projection, view)
.with_skybox_image_from_path("../../img/hdr/resting_place.hdr");
let (start, count) = builder.add_meshlet(sphere_vertices);

for i in 0..k {
let roughness = i as f32 / (k - 1) as f32;
let x = (diameter + spacing) * i as f32;
for j in 0..k {
let metallic = j as f32 / (k - 1) as f32;
let y = (diameter + spacing) * j as f32;
let material_id = builder.add_material(PbrMaterial {
albedo_factor: Vec4::new(1.0, 1.0, 1.0, 1.0),
metallic_factor: metallic,
roughness_factor: roughness,
..Default::default()
});
let _entity = builder
.new_entity()
.with_starting_vertex_and_count(start, count)
.with_material(material_id)
.with_position([x, y, 0.0])
.build();
}
}

let scene = builder.build().unwrap();
r.setup_render_graph(RenderGraphConfig {
scene: Some(scene),
with_screen_capture: true,
with_bloom: false,
..Default::default()
});

let img = r.render_image().unwrap();
img_diff::assert_img_eq("pbr_metallic_roughness_spheres.png", img);
img_diff::assert_img_eq("pbr/metallic_roughness_spheres.png", img);
}

#[test]
Expand Down
Binary file added test_img/pbr/metallic_roughness_spheres.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test_img/pbr_metallic_roughness_spheres.png
Binary file not shown.

0 comments on commit db34533

Please sign in to comment.