feat: add PBR demo with metallic/roughness sphere grid
7x7 grid of spheres demonstrating PBR material variation: metallic increases along X axis, roughness along Y axis. Uses dynamic UBO pattern for both camera and material uniforms. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
75
Cargo.lock
generated
75
Cargo.lock
generated
@@ -157,6 +157,23 @@ dependencies = [
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "asset_demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"env_logger",
|
||||
"log",
|
||||
"pollster",
|
||||
"voltex_asset",
|
||||
"voltex_ecs",
|
||||
"voltex_math",
|
||||
"voltex_platform",
|
||||
"voltex_renderer",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.2"
|
||||
@@ -684,6 +701,22 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||
|
||||
[[package]]
|
||||
name = "hierarchy_demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"env_logger",
|
||||
"log",
|
||||
"pollster",
|
||||
"voltex_ecs",
|
||||
"voltex_math",
|
||||
"voltex_platform",
|
||||
"voltex_renderer",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
@@ -895,6 +928,22 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "many_cubes"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"env_logger",
|
||||
"log",
|
||||
"pollster",
|
||||
"voltex_ecs",
|
||||
"voltex_math",
|
||||
"voltex_platform",
|
||||
"voltex_renderer",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
@@ -1309,6 +1358,21 @@ version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "pbr_demo"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"env_logger",
|
||||
"log",
|
||||
"pollster",
|
||||
"voltex_math",
|
||||
"voltex_platform",
|
||||
"voltex_renderer",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.2"
|
||||
@@ -1913,6 +1977,17 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "voltex_asset"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "voltex_ecs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"voltex_math",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "voltex_math"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -11,6 +11,7 @@ members = [
|
||||
"examples/many_cubes",
|
||||
"examples/hierarchy_demo",
|
||||
"examples/asset_demo",
|
||||
"examples/pbr_demo",
|
||||
]
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
15
examples/pbr_demo/Cargo.toml
Normal file
15
examples/pbr_demo/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "pbr_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
voltex_math.workspace = true
|
||||
voltex_platform.workspace = true
|
||||
voltex_renderer.workspace = true
|
||||
wgpu.workspace = true
|
||||
winit.workspace = true
|
||||
bytemuck.workspace = true
|
||||
pollster.workspace = true
|
||||
env_logger.workspace = true
|
||||
log.workspace = true
|
||||
484
examples/pbr_demo/src/main.rs
Normal file
484
examples/pbr_demo/src/main.rs
Normal file
@@ -0,0 +1,484 @@
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::WindowEvent,
|
||||
event_loop::{ActiveEventLoop, EventLoop},
|
||||
keyboard::{KeyCode, PhysicalKey},
|
||||
window::WindowId,
|
||||
};
|
||||
use voltex_math::{Vec3, Mat4};
|
||||
use voltex_platform::{VoltexWindow, WindowConfig, InputState, GameTimer};
|
||||
use voltex_renderer::{
|
||||
GpuContext, Camera, FpsController, CameraUniform, LightUniform,
|
||||
Mesh, GpuTexture, MaterialUniform, generate_sphere, create_pbr_pipeline,
|
||||
};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
const GRID_SIZE: usize = 7;
|
||||
const NUM_SPHERES: usize = GRID_SIZE * GRID_SIZE;
|
||||
const SPACING: f32 = 1.2;
|
||||
|
||||
struct PbrDemoApp {
|
||||
state: Option<AppState>,
|
||||
}
|
||||
|
||||
struct AppState {
|
||||
window: VoltexWindow,
|
||||
gpu: GpuContext,
|
||||
pipeline: wgpu::RenderPipeline,
|
||||
mesh: Mesh,
|
||||
camera: Camera,
|
||||
fps_controller: FpsController,
|
||||
camera_buffer: wgpu::Buffer,
|
||||
light_buffer: wgpu::Buffer,
|
||||
material_buffer: wgpu::Buffer,
|
||||
camera_light_bind_group: wgpu::BindGroup,
|
||||
_texture: GpuTexture,
|
||||
material_bind_group: wgpu::BindGroup,
|
||||
input: InputState,
|
||||
timer: GameTimer,
|
||||
cam_aligned_size: u32,
|
||||
mat_aligned_size: u32,
|
||||
}
|
||||
|
||||
fn camera_light_bind_group_layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: Some("Camera+Light Bind Group Layout"),
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStages::VERTEX | wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: true,
|
||||
min_binding_size: wgpu::BufferSize::new(
|
||||
std::mem::size_of::<CameraUniform>() as u64,
|
||||
),
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
fn align_up(size: u32, alignment: u32) -> u32 {
|
||||
((size + alignment - 1) / alignment) * alignment
|
||||
}
|
||||
|
||||
impl ApplicationHandler for PbrDemoApp {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let config = WindowConfig {
|
||||
title: "Voltex - PBR Demo".to_string(),
|
||||
width: 1280,
|
||||
height: 720,
|
||||
..Default::default()
|
||||
};
|
||||
let window = VoltexWindow::new(event_loop, &config);
|
||||
let gpu = GpuContext::new(window.handle.clone());
|
||||
|
||||
// Dynamic uniform buffer alignment
|
||||
let alignment = gpu.device.limits().min_uniform_buffer_offset_alignment;
|
||||
let cam_aligned_size = align_up(std::mem::size_of::<CameraUniform>() as u32, alignment);
|
||||
let mat_aligned_size = align_up(std::mem::size_of::<MaterialUniform>() as u32, alignment);
|
||||
|
||||
// Generate sphere mesh
|
||||
let (vertices, indices) = generate_sphere(0.4, 32, 16);
|
||||
let mesh = Mesh::new(&gpu.device, &vertices, &indices);
|
||||
|
||||
// Camera at (0, 0, 12) looking toward -Z (toward origin where the grid is)
|
||||
let aspect = gpu.config.width as f32 / gpu.config.height as f32;
|
||||
let camera = Camera::new(Vec3::new(0.0, 0.0, 12.0), aspect);
|
||||
let fps_controller = FpsController::new();
|
||||
|
||||
// Light: direction [-1, -1, -1], color white, ambient 0.1
|
||||
let light_uniform = LightUniform {
|
||||
direction: [-1.0, -1.0, -1.0],
|
||||
_padding1: 0.0,
|
||||
color: [1.0, 1.0, 1.0],
|
||||
ambient_strength: 0.1,
|
||||
};
|
||||
|
||||
// Camera dynamic uniform buffer (one CameraUniform per sphere)
|
||||
let camera_buffer = gpu.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Camera Dynamic Uniform Buffer"),
|
||||
size: (cam_aligned_size as usize * NUM_SPHERES) as u64,
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let light_buffer = gpu.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Light Uniform Buffer"),
|
||||
contents: bytemuck::cast_slice(&[light_uniform]),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
|
||||
// Material dynamic uniform buffer (one MaterialUniform per sphere)
|
||||
let material_buffer = gpu.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Material Dynamic Uniform Buffer"),
|
||||
size: (mat_aligned_size as usize * NUM_SPHERES) as u64,
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
// Bind group layouts
|
||||
let cl_layout = camera_light_bind_group_layout(&gpu.device);
|
||||
let tex_layout = GpuTexture::bind_group_layout(&gpu.device);
|
||||
let mat_layout = MaterialUniform::bind_group_layout(&gpu.device);
|
||||
|
||||
// Camera+Light bind group
|
||||
let camera_light_bind_group = gpu.device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("Camera+Light Bind Group"),
|
||||
layout: &cl_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
|
||||
buffer: &camera_buffer,
|
||||
offset: 0,
|
||||
size: wgpu::BufferSize::new(
|
||||
std::mem::size_of::<CameraUniform>() as u64,
|
||||
),
|
||||
}),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: light_buffer.as_entire_binding(),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Texture bind group (white 1x1)
|
||||
let texture = GpuTexture::white_1x1(&gpu.device, &gpu.queue, &tex_layout);
|
||||
|
||||
// Material bind group
|
||||
let material_bind_group = gpu.device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("Material Bind Group"),
|
||||
layout: &mat_layout,
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
|
||||
buffer: &material_buffer,
|
||||
offset: 0,
|
||||
size: wgpu::BufferSize::new(
|
||||
std::mem::size_of::<MaterialUniform>() as u64,
|
||||
),
|
||||
}),
|
||||
}],
|
||||
});
|
||||
|
||||
// PBR pipeline
|
||||
let pipeline = create_pbr_pipeline(
|
||||
&gpu.device,
|
||||
gpu.surface_format,
|
||||
&cl_layout,
|
||||
&tex_layout,
|
||||
&mat_layout,
|
||||
);
|
||||
|
||||
self.state = Some(AppState {
|
||||
window,
|
||||
gpu,
|
||||
pipeline,
|
||||
mesh,
|
||||
camera,
|
||||
fps_controller,
|
||||
camera_buffer,
|
||||
light_buffer,
|
||||
material_buffer,
|
||||
camera_light_bind_group,
|
||||
_texture: texture,
|
||||
material_bind_group,
|
||||
input: InputState::new(),
|
||||
timer: GameTimer::new(60),
|
||||
cam_aligned_size,
|
||||
mat_aligned_size,
|
||||
});
|
||||
}
|
||||
|
||||
fn window_event(
|
||||
&mut self,
|
||||
event_loop: &ActiveEventLoop,
|
||||
_window_id: WindowId,
|
||||
event: WindowEvent,
|
||||
) {
|
||||
let state = match &mut self.state {
|
||||
Some(s) => s,
|
||||
None => return,
|
||||
};
|
||||
|
||||
match event {
|
||||
WindowEvent::CloseRequested => event_loop.exit(),
|
||||
|
||||
WindowEvent::KeyboardInput {
|
||||
event:
|
||||
winit::event::KeyEvent {
|
||||
physical_key: PhysicalKey::Code(key_code),
|
||||
state: key_state,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => {
|
||||
let pressed = key_state == winit::event::ElementState::Pressed;
|
||||
state.input.process_key(key_code, pressed);
|
||||
if key_code == KeyCode::Escape && pressed {
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
|
||||
WindowEvent::Resized(size) => {
|
||||
state.gpu.resize(size.width, size.height);
|
||||
if size.width > 0 && size.height > 0 {
|
||||
state.camera.aspect = size.width as f32 / size.height as f32;
|
||||
}
|
||||
}
|
||||
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
state.input.process_mouse_move(position.x, position.y);
|
||||
}
|
||||
|
||||
WindowEvent::MouseInput {
|
||||
state: btn_state,
|
||||
button,
|
||||
..
|
||||
} => {
|
||||
let pressed = btn_state == winit::event::ElementState::Pressed;
|
||||
state.input.process_mouse_button(button, pressed);
|
||||
}
|
||||
|
||||
WindowEvent::MouseWheel { delta, .. } => {
|
||||
let y = match delta {
|
||||
winit::event::MouseScrollDelta::LineDelta(_, y) => y,
|
||||
winit::event::MouseScrollDelta::PixelDelta(pos) => pos.y as f32,
|
||||
};
|
||||
state.input.process_scroll(y);
|
||||
}
|
||||
|
||||
WindowEvent::RedrawRequested => {
|
||||
state.timer.tick();
|
||||
let dt = state.timer.frame_dt();
|
||||
|
||||
// Camera input
|
||||
if state
|
||||
.input
|
||||
.is_mouse_button_pressed(winit::event::MouseButton::Right)
|
||||
{
|
||||
let (dx, dy) = state.input.mouse_delta();
|
||||
state
|
||||
.fps_controller
|
||||
.process_mouse(&mut state.camera, dx, dy);
|
||||
}
|
||||
let mut forward = 0.0f32;
|
||||
let mut right = 0.0f32;
|
||||
let mut up = 0.0f32;
|
||||
if state.input.is_key_pressed(KeyCode::KeyW) {
|
||||
forward += 1.0;
|
||||
}
|
||||
if state.input.is_key_pressed(KeyCode::KeyS) {
|
||||
forward -= 1.0;
|
||||
}
|
||||
if state.input.is_key_pressed(KeyCode::KeyD) {
|
||||
right += 1.0;
|
||||
}
|
||||
if state.input.is_key_pressed(KeyCode::KeyA) {
|
||||
right -= 1.0;
|
||||
}
|
||||
if state.input.is_key_pressed(KeyCode::Space) {
|
||||
up += 1.0;
|
||||
}
|
||||
if state.input.is_key_pressed(KeyCode::ShiftLeft) {
|
||||
up -= 1.0;
|
||||
}
|
||||
state
|
||||
.fps_controller
|
||||
.process_movement(&mut state.camera, forward, right, up, dt);
|
||||
state.input.begin_frame();
|
||||
|
||||
// Compute view-projection
|
||||
let view_proj = state.camera.view_projection();
|
||||
let cam_pos = [
|
||||
state.camera.position.x,
|
||||
state.camera.position.y,
|
||||
state.camera.position.z,
|
||||
];
|
||||
|
||||
let cam_aligned = state.cam_aligned_size as usize;
|
||||
let mat_aligned = state.mat_aligned_size as usize;
|
||||
|
||||
// Build staging data for camera and material uniforms
|
||||
let cam_total = NUM_SPHERES * cam_aligned;
|
||||
let mat_total = NUM_SPHERES * mat_aligned;
|
||||
let mut cam_staging = vec![0u8; cam_total];
|
||||
let mut mat_staging = vec![0u8; mat_total];
|
||||
|
||||
let half_grid = (GRID_SIZE as f32 - 1.0) * SPACING * 0.5;
|
||||
|
||||
for row in 0..GRID_SIZE {
|
||||
for col in 0..GRID_SIZE {
|
||||
let i = row * GRID_SIZE + col;
|
||||
|
||||
let x = col as f32 * SPACING - half_grid;
|
||||
let y = row as f32 * SPACING - half_grid;
|
||||
|
||||
// Camera uniform: view_proj + model (translation) + camera_pos
|
||||
let model = Mat4::translation(x, y, 0.0);
|
||||
let cam_uniform = CameraUniform {
|
||||
view_proj: view_proj.cols,
|
||||
model: model.cols,
|
||||
camera_pos: cam_pos,
|
||||
_padding: 0.0,
|
||||
};
|
||||
let bytes = bytemuck::bytes_of(&cam_uniform);
|
||||
let offset = i * cam_aligned;
|
||||
cam_staging[offset..offset + bytes.len()].copy_from_slice(bytes);
|
||||
|
||||
// Material uniform: metallic varies with col, roughness with row
|
||||
let metallic = col as f32 / (GRID_SIZE as f32 - 1.0);
|
||||
let roughness =
|
||||
0.05 + row as f32 * (0.95 / (GRID_SIZE as f32 - 1.0));
|
||||
let mat_uniform = MaterialUniform::with_params(
|
||||
[0.8, 0.2, 0.2, 1.0],
|
||||
metallic,
|
||||
roughness,
|
||||
);
|
||||
let bytes = bytemuck::bytes_of(&mat_uniform);
|
||||
let offset = i * mat_aligned;
|
||||
mat_staging[offset..offset + bytes.len()].copy_from_slice(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
state
|
||||
.gpu
|
||||
.queue
|
||||
.write_buffer(&state.camera_buffer, 0, &cam_staging);
|
||||
state
|
||||
.gpu
|
||||
.queue
|
||||
.write_buffer(&state.material_buffer, 0, &mat_staging);
|
||||
|
||||
// Write light uniform
|
||||
let light_uniform = LightUniform {
|
||||
direction: [-1.0, -1.0, -1.0],
|
||||
_padding1: 0.0,
|
||||
color: [1.0, 1.0, 1.0],
|
||||
ambient_strength: 0.1,
|
||||
};
|
||||
state.gpu.queue.write_buffer(
|
||||
&state.light_buffer,
|
||||
0,
|
||||
bytemuck::cast_slice(&[light_uniform]),
|
||||
);
|
||||
|
||||
// Render
|
||||
let output = match state.gpu.surface.get_current_texture() {
|
||||
Ok(t) => t,
|
||||
Err(wgpu::SurfaceError::Lost) => {
|
||||
let (w, h) = state.window.inner_size();
|
||||
state.gpu.resize(w, h);
|
||||
return;
|
||||
}
|
||||
Err(wgpu::SurfaceError::OutOfMemory) => {
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
let view =
|
||||
output
|
||||
.texture
|
||||
.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let mut encoder = state.gpu.device.create_command_encoder(
|
||||
&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("Render Encoder"),
|
||||
},
|
||||
);
|
||||
|
||||
{
|
||||
let mut render_pass =
|
||||
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("PBR Render Pass"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &view,
|
||||
resolve_target: None,
|
||||
depth_slice: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.1,
|
||||
b: 0.15,
|
||||
a: 1.0,
|
||||
}),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: Some(
|
||||
wgpu::RenderPassDepthStencilAttachment {
|
||||
view: &state.gpu.depth_view,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: wgpu::StoreOp::Store,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
},
|
||||
),
|
||||
occlusion_query_set: None,
|
||||
timestamp_writes: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
|
||||
render_pass.set_pipeline(&state.pipeline);
|
||||
render_pass.set_bind_group(1, &state._texture.bind_group, &[]);
|
||||
render_pass.set_vertex_buffer(0, state.mesh.vertex_buffer.slice(..));
|
||||
render_pass.set_index_buffer(
|
||||
state.mesh.index_buffer.slice(..),
|
||||
wgpu::IndexFormat::Uint32,
|
||||
);
|
||||
|
||||
// Draw each sphere with dynamic offsets for camera and material
|
||||
for i in 0..NUM_SPHERES {
|
||||
let cam_offset = (i as u32) * state.cam_aligned_size;
|
||||
let mat_offset = (i as u32) * state.mat_aligned_size;
|
||||
render_pass.set_bind_group(
|
||||
0,
|
||||
&state.camera_light_bind_group,
|
||||
&[cam_offset],
|
||||
);
|
||||
render_pass.set_bind_group(
|
||||
2,
|
||||
&state.material_bind_group,
|
||||
&[mat_offset],
|
||||
);
|
||||
render_pass.draw_indexed(0..state.mesh.num_indices, 0, 0..1);
|
||||
}
|
||||
}
|
||||
|
||||
state.gpu.queue.submit(std::iter::once(encoder.finish()));
|
||||
output.present();
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
||||
if let Some(state) = &self.state {
|
||||
state.window.request_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
let mut app = PbrDemoApp { state: None };
|
||||
event_loop.run_app(&mut app).unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user