Compare commits
3 Commits
9d332655be
...
8072576869
Author | SHA1 | Date |
---|---|---|
Jarrod Doyle | 8072576869 | |
Jarrod Doyle | 04348d96f3 | |
Jarrod Doyle | 0ee15a1c06 |
|
@ -0,0 +1,33 @@
|
|||
var<private> DATA: array<vec4<f32>, 6> = array<vec4<f32>, 6>(
|
||||
vec4<f32>( -1.0, 1.0, 0.0, 1.0 ),
|
||||
vec4<f32>( -1.0, -1.0, 0.0, 0.0 ),
|
||||
vec4<f32>( 1.0, -1.0, 1.0, 0.0 ),
|
||||
vec4<f32>( -1.0, 1.0, 0.0, 1.0 ),
|
||||
vec4<f32>( 1.0, -1.0, 1.0, 0.0 ),
|
||||
vec4<f32>( 1.0, 1.0, 1.0, 1.0 )
|
||||
);
|
||||
|
||||
struct VertexOutput {
|
||||
@builtin(position) clip_position: vec4<f32>,
|
||||
@location(0) tex_coords: vec2<f32>,
|
||||
};
|
||||
|
||||
@vertex
|
||||
fn vertex(
|
||||
@builtin(vertex_index) in_vertex_index: u32,
|
||||
) -> VertexOutput {
|
||||
var out: VertexOutput;
|
||||
out.clip_position = vec4<f32>(DATA[in_vertex_index].xy, 0.0, 1.0);
|
||||
out.tex_coords = DATA[in_vertex_index].zw;
|
||||
return out;
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
var t_diffuse: texture_2d<f32>;
|
||||
@group(0) @binding(1)
|
||||
var s_diffuse: sampler;
|
||||
|
||||
@fragment
|
||||
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
|
||||
}
|
10
src/main.rs
10
src/main.rs
|
@ -1,5 +1,8 @@
|
|||
mod renderer;
|
||||
|
||||
use anyhow::Result;
|
||||
use crawl::winit::event::{Event, WindowEvent};
|
||||
use renderer::VoxelRenderer;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
env_logger::init();
|
||||
|
@ -9,6 +12,8 @@ fn main() -> Result<()> {
|
|||
.with_vsync(false)
|
||||
.build(),
|
||||
)?;
|
||||
let renderer = VoxelRenderer::new(&context)?;
|
||||
let passes: Vec<Box<dyn crawl::Pass>> = vec![Box::new(renderer)];
|
||||
|
||||
event_loop.run(|event, elwt| match event {
|
||||
Event::WindowEvent { window_id, event } if window_id == context.window.id() => {
|
||||
|
@ -17,7 +22,10 @@ fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
if let WindowEvent::RedrawRequested = event {
|
||||
log::info!("Epic");
|
||||
if let Err(err) = context.render(passes.as_slice()) {
|
||||
log::error!("{err:?}");
|
||||
}
|
||||
|
||||
context.window.request_redraw();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
use anyhow::Result;
|
||||
use crawl::wgpu;
|
||||
|
||||
pub struct VoxelRenderer {
|
||||
render_texture: crawl::Texture,
|
||||
render_pipeline: wgpu::RenderPipeline,
|
||||
}
|
||||
|
||||
impl VoxelRenderer {
|
||||
pub fn new(context: &crawl::Context) -> Result<Self> {
|
||||
let shader = context
|
||||
.device
|
||||
.create_shader_module(wgpu::include_wgsl!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/res/quad.wgsl"
|
||||
)));
|
||||
|
||||
let render_texture = crawl::TextureBuilder::new()
|
||||
.with_size(context.size.width, context.size.height, 1)
|
||||
.with_format(wgpu::TextureFormat::Rgba8Unorm)
|
||||
.with_usage(
|
||||
wgpu::TextureUsages::TEXTURE_BINDING
|
||||
| wgpu::TextureUsages::COPY_DST
|
||||
| wgpu::TextureUsages::STORAGE_BINDING,
|
||||
)
|
||||
.with_shader_visibility(wgpu::ShaderStages::FRAGMENT | wgpu::ShaderStages::COMPUTE)
|
||||
.build(context)?;
|
||||
|
||||
let render_pipeline = crawl::RenderPipelineBuilder::new("Raycast Quad", &shader)
|
||||
.with_layout("Draw", &[&render_texture.bind_group_layout], &[])
|
||||
.with_fragment_targets(&[Some(context.surface_config.format.into())])
|
||||
.build(context);
|
||||
|
||||
Ok(Self {
|
||||
render_texture,
|
||||
render_pipeline,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl crawl::Pass for VoxelRenderer {
|
||||
fn execute(&self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView) {
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("Render Pass"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations::default(),
|
||||
})],
|
||||
..Default::default()
|
||||
});
|
||||
render_pass.set_pipeline(&self.render_pipeline);
|
||||
render_pass.set_bind_group(0, &self.render_texture.bind_group, &[]);
|
||||
render_pass.draw(0..6, 0..1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue