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

Scene refactor #49

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ base64 = "0.21"
bitflags = "2"
bytemuck = { version = "1", features = ["derive"] }
choir = { git = "https://github.com/kvark/choir", rev = "2d7c6ffb74a21a34c18c70aeb0b93a61a42eb04f" }
egui = "0.22"
glam = { version = "0.23", features = ["mint"] }
egui = "0.23"
glam = { version = "0.24", features = ["mint"] }
log = "0.4"
mint = "0.5"
# Need 0.12.2 since this is where buffer arrays are supported
naga = { version = "0.12.2", features = ["wgsl-in", "span", "validate"] }
naga = { version = "0.14", features = ["wgsl-in", "span", "validate"] }
profiling = "1"
strum = { version = "0.25", features = ["derive"] }
web-sys = "0.3.60"
Expand Down Expand Up @@ -64,7 +63,9 @@ strum = { workspace = true }
winit = "0.28"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
egui-winit = "0.22"
egui-winit = "0.23"
egui_plot = "0.23"
egui-gizmo = "0.12"
env_logger = "0.10"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
Expand Down
21 changes: 21 additions & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
pub use naga::{StorageAccess, VectorSize};
pub type Transform = mint::RowMatrix3x4<f32>;

pub const IDENTITY_TRANSFORM: Transform = mint::RowMatrix3x4 {
x: mint::Vector4 {
x: 1.0,
y: 0.0,
z: 0.0,
w: 0.0,
},
y: mint::Vector4 {
x: 0.0,
y: 1.0,
z: 0.0,
w: 0.0,
},
z: mint::Vector4 {
x: 0.0,
y: 0.0,
z: 1.0,
w: 0.0,
},
};

#[cfg_attr(
all(not(vulkan), not(gles), any(target_os = "ios", target_os = "macos")),
path = "metal/mod.rs"
Expand Down
4 changes: 2 additions & 2 deletions blade-graphics/src/metal/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl super::Context {
let naga_stage = sf.shader.module.entry_points[ep_index].stage;
let mut module = sf.shader.module.clone();
let mut layouter = naga::proc::Layouter::default();
layouter.update(&module.types, &module.constants).unwrap();
layouter.update(module.to_ctx()).unwrap();

for (handle, var) in module.global_variables.iter_mut() {
if ep_info[handle].is_empty() {
Expand Down Expand Up @@ -301,7 +301,7 @@ impl super::Context {
};

let pipeline_options = msl::PipelineOptions {
allow_point_size: flags.contains(ShaderFlags::ALLOW_POINT_SIZE),
allow_and_force_point_size: flags.contains(ShaderFlags::ALLOW_POINT_SIZE),
};
let (source, info) =
msl::write_string(&module, &sf.shader.info, &naga_options, &pipeline_options).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion blade-graphics/src/vulkan/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl super::Context {
capabilities: None,
bounds_check_policies: naga::proc::BoundsCheckPolicies::default(),
zero_initialize_workgroup_memory: spv::ZeroInitializeWorkgroupMemoryMode::None,
debug_info: None,
}
}

Expand All @@ -77,7 +78,7 @@ impl super::Context {

let mut module = sf.shader.module.clone();
let mut layouter = naga::proc::Layouter::default();
layouter.update(&module.types, &module.constants).unwrap();
layouter.update(module.to_ctx()).unwrap();

for (handle, var) in module.global_variables.iter_mut() {
if ep_info[handle].is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions blade-render/code/debug.inc.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct DebugVariance {
count: u32,
}
struct DebugEntry {
custom_index: u32,
depth: f32,
tex_coords: vec2<f32>,
base_color_texture: u32,
normal_texture: u32,
Expand Down
7 changes: 6 additions & 1 deletion blade-render/code/fill-gbuf.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "debug.inc.wgsl"
#include "debug-param.inc.wgsl"

//TODO: use proper WGSL
const RAY_FLAG_CULL_NO_OPAQUE: u32 = 0x80u;

// Has to match the host!
struct Vertex {
pos: vec3<f32>,
Expand Down Expand Up @@ -64,7 +67,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {

var rq: ray_query;
let ray_dir = get_ray_direction(camera, vec2<i32>(global_id.xy));
rayQueryInitialize(&rq, acc_struct, RayDesc(0x90u, 0xFFu, 0.0, camera.depth, camera.position, ray_dir));
rayQueryInitialize(&rq, acc_struct, RayDesc(RAY_FLAG_CULL_NO_OPAQUE, 0xFFu, 0.0, camera.depth, camera.position, ray_dir));
rayQueryProceed(&rq);
let intersection = rayQueryGetCommittedIntersection(&rq);

Expand Down Expand Up @@ -121,6 +124,8 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {

let hit_position = camera.position + intersection.t * ray_dir;
if (enable_debug) {
debug_buf.entry.custom_index = intersection.instance_custom_index;
debug_buf.entry.depth = intersection.t;
debug_buf.entry.tex_coords = tex_coords;
debug_buf.entry.base_color_texture = entry.base_color_texture;
debug_buf.entry.normal_texture = entry.normal_texture;
Expand Down
6 changes: 5 additions & 1 deletion blade-render/code/ray-trace.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "camera.inc.wgsl"
#include "surface.inc.wgsl"

//TODO: use proper WGSL
const RAY_FLAG_CULL_NO_OPAQUE: u32 = 0x80u;

const PI: f32 = 3.1415926;
const MAX_RESERVOIRS: u32 = 2u;
// See "9.1 pairwise mis for robust reservoir reuse"
Expand Down Expand Up @@ -218,8 +221,9 @@ fn evaluate_brdf(surface: Surface, dir: vec3<f32>) -> f32 {
fn check_ray_occluded(position: vec3<f32>, direction: vec3<f32>, debug_len: f32) -> bool {
let start_t = 0.5; // some offset required to avoid self-shadowing
var rq: ray_query;
let flags = RAY_FLAG_TERMINATE_ON_FIRST_HIT | RAY_FLAG_CULL_NO_OPAQUE;
rayQueryInitialize(&rq, acc_struct,
RayDesc(RAY_FLAG_TERMINATE_ON_FIRST_HIT | 0x80u, 0xFFu, start_t, camera.depth, position, direction)
RayDesc(flags, 0xFFu, start_t, camera.depth, position, direction)
);
rayQueryProceed(&rq);
let intersection = rayQueryGetCommittedIntersection(&rq);
Expand Down
33 changes: 2 additions & 31 deletions blade-render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,15 @@ pub struct Camera {
}

pub struct Object {
pub model: blade_asset::Handle<Model>,
pub transform: blade_graphics::Transform,
pub model: blade_asset::Handle<Model>,
}

impl From<blade_asset::Handle<Model>> for Object {
fn from(model: blade_asset::Handle<Model>) -> Self {
Self {
transform: blade_graphics::IDENTITY_TRANSFORM,
model,
transform: [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
]
.into(),
}
}
}

#[derive(Clone, Debug)]
pub struct PostProcessing {
//TODO: remove this, compute automatically
pub average_luminocity: f32,
pub exposure_key_value: f32,
pub white_level: f32,
}
impl Default for PostProcessing {
fn default() -> Self {
Self {
average_luminocity: 1.0,
exposure_key_value: 1.0,
white_level: 1.0,
}
}
}

#[derive(Default)]
pub struct Scene {
pub objects: Vec<Object>,
pub environment_map: Option<blade_asset::Handle<Texture>>,
pub post_processing: PostProcessing,
}
Loading
Loading