Skip to content

Commit

Permalink
Backport #203 to v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Sep 20, 2021
1 parent 9384abb commit b3e47e8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to cargo's version of [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Per Keep a Changelog there are 6 main categories of changes:

- Added
- Changed
- Deprecated
- Removed
- Fixed
- Security

- [Unreleased](#unreleased)
- [v0.1.1](#v011)
- [v0.1.0](#v010)
Expand All @@ -18,6 +27,13 @@ and this project adheres to cargo's version of [Semantic Versioning](https://sem

## Unreleased

### Added
- rend3: Added an explicit dependency on wgpu-core and wgpu-hal to ensure bug-fixes are included.

### Fixed
- rend3-pbr: fix rendering of cutout objects in shadow passes.
- rend3-pbr: remove redundant material changes in cpu mode.

## v0.1.1

Released 2021-09-13
Expand Down
29 changes: 16 additions & 13 deletions rend3-pbr/src/culling/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ where
start_idx: object.start_idx,
end_idx: object.start_idx + object.count,
vertex_offset: object.vertex_offset,
// TODO: Elide these clones?
material_handle: object.material.get_raw(),
});

Expand All @@ -191,20 +190,24 @@ pub fn run<'rpass>(
) {
let mut state_sample_type = SampleType::Linear;

let mut previous_mat_handle = None;
for (idx, draw) in draws.iter().enumerate() {
let (material_bind_group, sample_type) = materials.cpu_get_bind_group(draw.material_handle);

// As a workaround for OpenGL's combined samplers, we need to manually swap the linear and nearest samplers so that shader code can think it's always using linear.
if state_sample_type != sample_type {
let bg = match sample_type {
SampleType::Nearest => samplers.nearest_linear_bg.as_ref().as_cpu(),
SampleType::Linear => &samplers.linear_nearest_bg,
};
state_sample_type = sample_type;
rpass.set_bind_group(samplers_binding_index, bg, &[]);
}
if previous_mat_handle != Some(draw.material_handle) {
previous_mat_handle = Some(draw.material_handle);
let (material_bind_group, sample_type) = materials.cpu_get_bind_group(draw.material_handle);

// As a workaround for OpenGL's combined samplers, we need to manually swap the linear and nearest samplers so that shader code can think it's always using linear.
if state_sample_type != sample_type {
let bg = match sample_type {
SampleType::Nearest => samplers.nearest_linear_bg.as_ref().as_cpu(),
SampleType::Linear => &samplers.linear_nearest_bg,
};
state_sample_type = sample_type;
rpass.set_bind_group(samplers_binding_index, bg, &[]);
}

rpass.set_bind_group(material_binding_index, material_bind_group, &[]);
rpass.set_bind_group(material_binding_index, material_bind_group, &[]);
}
let idx = idx as u32;
rpass.draw_indexed(draw.start_idx..draw.end_idx, draw.vertex_offset, idx..idx + 1);
}
Expand Down
3 changes: 2 additions & 1 deletion rend3-pbr/src/directional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ impl DirectionalShadowPass {
.begin_scope(TransparencyType::Cutout.to_debug_str(), &mut rpass, args.device);

rpass.set_pipeline(&self.cutout_pipeline);
rpass.set_bind_group(1, &light.opaque_culled_objects.output_bg, &[]);
rpass.set_bind_group(0, &args.samplers.linear_nearest_bg, &[]);
rpass.set_bind_group(1, &light.cutout_culled_objects.output_bg, &[]);

match light.cutout_culled_objects.calls {
ModeData::CPU(ref draws) => culling::cpu::run(&mut rpass, draws, args.samplers, 0, args.materials, 2),
Expand Down
8 changes: 8 additions & 0 deletions rend3-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ impl<T> Clone for RawResourceHandle<T> {
}
}

impl<T> PartialEq for RawResourceHandle<T> {
fn eq(&self, other: &Self) -> bool {
self.idx == other.idx
}
}

impl<T> Eq for RawResourceHandle<T> {}

/// Owning resource handle. Used as part of rend3's interface.
#[derive(Debug, Clone)]
pub struct ResourceHandle<T> {
Expand Down
4 changes: 4 additions & 0 deletions rend3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ smartstring = "0.2"
thiserror = "1"
wgpu = { version = "0.10", features = ["trace", "spirv", "webgl"] }
wgpu-profiler = "0.6.1"

# not direct deps, but force new versions
wgpu-core = "0.10.3"
wgpu-hal = "0.10.7"

0 comments on commit b3e47e8

Please sign in to comment.