Compare commits

..

No commits in common. "807257686942b24b0c48a50a62c3d90626fb863a" and "9d332655bef22bfd4612b152eab74c8e8ac0ce63" have entirely different histories.

3 changed files with 1 additions and 98 deletions

View File

@ -1,33 +0,0 @@
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);
}

View File

@ -1,8 +1,5 @@
mod renderer;
use anyhow::Result;
use crawl::winit::event::{Event, WindowEvent};
use renderer::VoxelRenderer;
fn main() -> Result<()> {
env_logger::init();
@ -12,8 +9,6 @@ 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() => {
@ -22,10 +17,7 @@ fn main() -> Result<()> {
}
if let WindowEvent::RedrawRequested = event {
if let Err(err) = context.render(passes.as_slice()) {
log::error!("{err:?}");
}
log::info!("Epic");
context.window.request_redraw();
}
}

View File

@ -1,56 +0,0 @@
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);
}
}