stylized 1-bit rendering
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use crate::mesh::InstanceRaw;
|
||||
use crate::render::DrawCall;
|
||||
use crate::world::World;
|
||||
use bytemuck::cast_slice;
|
||||
use glam::Mat4;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
pub fn render_system(world: &World) -> Vec<DrawCall>
|
||||
{
|
||||
@@ -11,12 +15,38 @@ pub fn render_system(world: &World) -> Vec<DrawCall>
|
||||
let transform = world.transforms.get(entity)?;
|
||||
let mesh_component = world.meshes.get(entity)?;
|
||||
|
||||
let model_matrix = transform.to_matrix();
|
||||
|
||||
let (instance_buffer, num_instances) = if let Some(ref buffer) =
|
||||
mesh_component.instance_buffer
|
||||
{
|
||||
(Some(buffer.clone()), mesh_component.num_instances)
|
||||
}
|
||||
else
|
||||
{
|
||||
let instance_data = InstanceRaw {
|
||||
model: model_matrix.to_cols_array_2d(),
|
||||
};
|
||||
|
||||
let buffer = crate::render::with_device(|device| {
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Instance Buffer"),
|
||||
contents: cast_slice(&[instance_data]),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
})
|
||||
});
|
||||
|
||||
(Some(buffer), 1)
|
||||
};
|
||||
|
||||
Some(DrawCall {
|
||||
vertex_buffer: mesh_component.mesh.vertex_buffer.clone(),
|
||||
index_buffer: mesh_component.mesh.index_buffer.clone(),
|
||||
num_indices: mesh_component.mesh.num_indices,
|
||||
model: transform.to_matrix(),
|
||||
model: model_matrix,
|
||||
pipeline: mesh_component.pipeline,
|
||||
instance_buffer,
|
||||
num_instances,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
|
||||
Reference in New Issue
Block a user