migrated to 0.13

0.13
Ben Hansen 2 years ago
parent 0fa9eb1e6f
commit a2a1d69133

938
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -14,5 +14,5 @@ members = [
]
exclude = [
"code/showcase/imgui-demo",
# "code/showcase/pong",
"code/showcase/pong",
]

@ -1,6 +1,6 @@
export RES_PATH=learn-wgpu
# (trap 'killall background' INT;
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/pong code/showcase/pong
# wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/pong code/showcase/pong
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial1_window code/beginner/tutorial1-window
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial2_surface code/beginner/tutorial2-surface
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial3_pipeline code/beginner/tutorial3-pipeline

@ -16,13 +16,13 @@ cfg-if = "1"
winit = "0.26"
env_logger = "0.9"
log = "0.4"
wgpu = "0.12"
wgpu = "0.13"
pollster = "0.2"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2.76"
wasm-bindgen-futures = "0.4.30"
web-sys = { version = "0.3.53", features = [

@ -12,13 +12,13 @@ cfg-if = "1"
winit = "0.26"
env_logger = "0.9"
log = "0.4"
wgpu = "0.12"
wgpu = "0.13"
pollster = "0.2"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -56,7 +56,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -118,14 +118,14 @@ impl State {
{
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(self.clear_color),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});
}

@ -55,7 +55,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -102,7 +102,7 @@ impl State {
{
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -114,7 +114,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});
}

@ -12,13 +12,13 @@ cfg-if = "1"
winit = "0.26"
env_logger = "0.9"
log = "0.4"
wgpu = "0.12"
wgpu = "0.13"
pollster = "0.2"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -54,14 +54,14 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -84,14 +84,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -117,7 +117,7 @@ impl State {
multiview: None,
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Challenge Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("challenge.wgsl").into()),
});
@ -134,11 +134,11 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState::REPLACE),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -218,7 +218,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -230,7 +230,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -1,13 +1,13 @@
// Vertex shader
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] position: vec2<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) position: vec2<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
[[builtin(vertex_index)]] in_vertex_index: u32,
@builtin(vertex_index) in_vertex_index: u32,
) -> VertexOutput {
var out: VertexOutput;
let x = f32(1 - i32(in_vertex_index)) * 0.5;
@ -19,7 +19,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.position, 0.5, 1.0);
}

@ -56,14 +56,14 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -86,14 +86,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -160,7 +160,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -172,7 +172,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -1,12 +1,12 @@
// Vertex shader
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
@builtin(position) clip_position: vec4<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
[[builtin(vertex_index)]] in_vertex_index: u32,
@builtin(vertex_index) in_vertex_index: u32,
) -> VertexOutput {
var out: VertexOutput;
let x = f32(1 - i32(in_vertex_index)) * 0.5;
@ -17,7 +17,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.3, 0.2, 0.1, 1.0);
}

@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
cfg-if = "1"
winit = "0.26"
wgpu = "0.12"
wgpu = "0.13"
env_logger = "0.9"
log = "0.4"
pollster = "0.2"
@ -21,7 +21,7 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -117,14 +117,14 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -147,14 +147,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -286,7 +286,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -298,7 +298,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -113,14 +113,14 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
};
surface.configure(&device, &config);
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -143,14 +143,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -232,7 +232,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -244,7 +244,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -1,16 +1,16 @@
// Vertex shader
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] color: vec3<f32>;
@location(0) position: vec3<f32>,
@location(1) color: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -22,7 +22,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}

@ -14,7 +14,7 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
env_logger = "0.9"
log = "0.4"
pollster = "0.2"
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
[dependencies.image]
@ -25,7 +25,7 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -118,7 +118,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -187,7 +187,7 @@ impl State {
label: Some("cartoon_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -210,14 +210,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -317,7 +317,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -329,7 +329,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -118,7 +118,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -167,7 +167,7 @@ impl State {
label: Some("diffuse_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -190,14 +190,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -281,7 +281,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -293,7 +293,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -1,16 +1,16 @@
// Vertex shader
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -22,12 +22,12 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

@ -15,7 +15,7 @@ cgmath = "0.18"
env_logger = "0.9"
log = "0.4"
pollster = "0.2"
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
[dependencies.image]
@ -26,7 +26,7 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -268,7 +268,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -362,7 +362,7 @@ impl State {
label: Some("camera_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -385,14 +385,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -493,7 +493,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -505,7 +505,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -268,7 +268,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -361,7 +361,7 @@ impl State {
label: Some("camera_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -384,14 +384,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -489,7 +489,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -501,7 +501,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -1,22 +1,22 @@
// Vertex shader
struct CameraUniform {
view_proj: mat4x4<f32>;
view_proj: mat4x4<f32>,
};
[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> camera: CameraUniform;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -28,12 +28,12 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

@ -15,7 +15,7 @@ cgmath = "0.18"
env_logger = "0.9"
log = "0.4"
pollster = "0.2"
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
[dependencies.image]
@ -26,7 +26,7 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -322,7 +322,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -447,7 +447,7 @@ impl State {
label: Some("camera_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -470,14 +470,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -593,7 +593,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -605,7 +605,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -329,7 +329,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -454,7 +454,7 @@ impl State {
label: Some("camera_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -477,14 +477,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -585,7 +585,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -597,7 +597,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

@ -1,28 +1,28 @@
// Vertex shader
struct Camera {
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -41,12 +41,12 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

@ -15,7 +15,7 @@ cgmath = "0.18"
env_logger = "0.9"
pollster = "0.2"
log = "0.4"
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
[dependencies.image]
@ -26,7 +26,7 @@ features = ["png", "jpeg"]
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -351,7 +351,7 @@ impl DepthPass {
push_constant_ranges: &[],
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shadow Display Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("challenge.wgsl").into()),
});
@ -367,14 +367,14 @@ impl DepthPass {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -432,14 +432,14 @@ impl DepthPass {
fn render(&self, view: &wgpu::TextureView, encoder: &mut wgpu::CommandEncoder) {
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Depth Visual Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
}],
})],
depth_stencil_attachment: None,
});
render_pass.set_pipeline(&self.render_pipeline);
@ -510,7 +510,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -635,7 +635,7 @@ impl State {
label: Some("camera_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -658,14 +658,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -779,7 +779,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -791,7 +791,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_pass.texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,16 +1,16 @@
// Vertex shader
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -22,13 +22,13 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_shadow: texture_depth_2d;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_shadow: sampler_comparison;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let near = 0.1;
let far = 100.0;
let depth = textureSampleCompare(t_shadow, s_shadow, in.tex_coords, in.clip_position.w);

@ -339,7 +339,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -464,7 +464,7 @@ impl State {
label: Some("camera_bind_group"),
});
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -490,14 +490,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -606,7 +606,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -618,7 +618,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,28 +1,28 @@
// Vertex shader
struct Camera {
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
var<uniform> camera: Camera;
struct CameraUniform {
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: CameraUniform;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -41,12 +41,12 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

@ -16,7 +16,7 @@ env_logger = "0.9"
pollster = "0.2"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
[dependencies.image]
@ -28,7 +28,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -282,7 +282,7 @@ impl State {
log::warn!("Surface");
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -395,7 +395,7 @@ impl State {
&texture_bind_group_layout,
).await.unwrap();
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("shader.wgsl"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -421,14 +421,14 @@ impl State {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: config.format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -519,7 +519,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -531,7 +531,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,28 +1,28 @@
// Vertex shader
struct Camera {
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -41,12 +41,12 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}

@ -16,7 +16,7 @@ env_logger = "0.9"
pollster = "0.2"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.12"}
wgpu = { version = "0.13"}
winit = "0.26"
[dependencies.image]
@ -28,7 +28,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -286,7 +286,7 @@ fn create_render_pipeline(
vertex_layouts: &[wgpu::VertexBufferLayout],
shader: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(&shader);
let shader = device.create_shader_module(shader);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Render Pipeline"),
@ -299,14 +299,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -374,7 +374,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -649,7 +649,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -661,7 +661,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,29 +1,29 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
@location(0) position: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -36,7 +36,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}

@ -1,42 +1,42 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(2), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
@location(2) normal: vec3<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
[[location(9)]] normal_matrix_0: vec3<f32>;
[[location(10)]] normal_matrix_1: vec3<f32>;
[[location(11)]] normal_matrix_2: vec3<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
@location(9) normal_matrix_0: vec3<f32>,
@location(10) normal_matrix_1: vec3<f32>,
@location(11) normal_matrix_2: vec3<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] world_normal: vec3<f32>;
[[location(2)]] world_position: vec3<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
@location(1) world_normal: vec3<f32>,
@location(2) world_position: vec3<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -63,13 +63,13 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
// We don't need (or want) much ambient light, so 0.1 is fine

@ -16,7 +16,7 @@ env_logger = "0.9"
pollster = "0.2"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.12"}
wgpu = { version = "0.13"}
winit = "0.26"
[dependencies.image]
@ -28,7 +28,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -286,7 +286,7 @@ fn create_render_pipeline(
vertex_layouts: &[wgpu::VertexBufferLayout],
shader: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(&shader);
let shader = device.create_shader_module(shader);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Render Pipeline"),
@ -299,14 +299,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -374,7 +374,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -700,7 +700,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -712,7 +712,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,29 +1,29 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
@location(0) position: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -36,7 +36,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}

@ -1,45 +1,45 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(2), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>;
[[location(3)]] tangent: vec3<f32>;
[[location(4)]] bitangent: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
@location(2) normal: vec3<f32>,
@location(3) tangent: vec3<f32>,
@location(4) bitangent: vec3<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
[[location(9)]] normal_matrix_0: vec3<f32>;
[[location(10)]] normal_matrix_1: vec3<f32>;
[[location(11)]] normal_matrix_2: vec3<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
@location(9) normal_matrix_0: vec3<f32>,
@location(10) normal_matrix_1: vec3<f32>,
@location(11) normal_matrix_2: vec3<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] tangent_position: vec3<f32>;
[[location(2)]] tangent_light_position: vec3<f32>;
[[location(3)]] tangent_view_position: vec3<f32>;
};
[[stage(vertex)]]
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
@location(1) tangent_position: vec3<f32>,
@location(2) tangent_light_position: vec3<f32>,
@location(3) tangent_view_position: vec3<f32>,
}
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -79,17 +79,17 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[group(0), binding(2)]]
@group(0)@binding(2)
var t_normal: texture_2d<f32>;
[[group(0), binding(3)]]
@group(0) @binding(3)
var s_normal: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);

@ -16,7 +16,7 @@ env_logger = "0.9"
pollster = "0.2"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.12"}
wgpu = { version = "0.13"}
winit = "0.26"
instant = "0.1"
@ -29,7 +29,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -166,7 +166,7 @@ fn create_render_pipeline(
vertex_layouts: &[wgpu::VertexBufferLayout],
shader: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(&shader);
let shader = device.create_shader_module(shader);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some(&format!("{:?}", shader)),
@ -179,14 +179,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -254,7 +254,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -600,7 +600,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -612,7 +612,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,29 +1,29 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
@location(0) position: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -36,7 +36,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}

@ -1,45 +1,45 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(2), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>;
[[location(3)]] tangent: vec3<f32>;
[[location(4)]] bitangent: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
@location(2) normal: vec3<f32>,
@location(3) tangent: vec3<f32>,
@location(4) bitangent: vec3<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
[[location(9)]] normal_matrix_0: vec3<f32>;
[[location(10)]] normal_matrix_1: vec3<f32>;
[[location(11)]] normal_matrix_2: vec3<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
@location(9) normal_matrix_0: vec3<f32>,
@location(10) normal_matrix_1: vec3<f32>,
@location(11) normal_matrix_2: vec3<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] tangent_position: vec3<f32>;
[[location(2)]] tangent_light_position: vec3<f32>;
[[location(3)]] tangent_view_position: vec3<f32>;
};
[[stage(vertex)]]
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
@location(1) tangent_position: vec3<f32>,
@location(2) tangent_light_position: vec3<f32>,
@location(3) tangent_view_position: vec3<f32>,
}
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -79,17 +79,17 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[group(0), binding(2)]]
@group(0)@binding(2)
var t_normal: texture_2d<f32>;
[[group(0), binding(3)]]
@group(0) @binding(3)
var s_normal: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);

@ -16,7 +16,7 @@ env_logger = "0.9"
pollster = "0.2"
log = "0.4"
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.12"}
wgpu = { version = "0.13"}
winit = "0.26"
instant = "0.1"
@ -29,7 +29,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -180,14 +180,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -255,7 +255,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -433,7 +433,7 @@ impl State {
label: Some("Normal Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
};
let shader = device.create_shader_module(&desc);
let shader = device.create_shader_module(desc);
create_render_pipeline(
&device,
&render_pipeline_layout,
@ -454,7 +454,7 @@ impl State {
label: Some("Light Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("light.wgsl").into()),
};
let shader = device.create_shader_module(&desc);
let shader = device.create_shader_module(desc);
create_render_pipeline(
&device,
&layout,
@ -624,7 +624,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -636,7 +636,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,29 +1,29 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
@location(0) position: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -36,7 +36,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}

@ -219,47 +219,49 @@ pub async fn load_model(
Ok(model::Model { meshes, materials })
}
pub fn export_mesh_data(path: &str, device: &wgpu::Device, mesh: &model::Mesh) {
let indices_vec = map_buffer(device, &mesh.index_buffer, |i: &u32| *i);
let indices = indices_vec.chunks(6).collect::<Vec<_>>();
let vertices_vec = map_buffer(device, &mesh.vertex_buffer, |v: &f32| *v);
let vertices = vertices_vec.chunks(8).collect::<Vec<_>>();
let mut file = std::fs::File::create(path).unwrap();
use std::io::Write;
write!(file, "{{\n").unwrap();
write!(file, "\t\"vertices\": [\n").unwrap();
for v in vertices {
write!(file, "\t\t{:?}{}\n", v, ",").unwrap();
}
write!(file, "\t],\n").unwrap();
write!(file, "\t\"indices\": [\n").unwrap();
for i in indices {
write!(file, "\t\t{:?}{}\n", i, ",").unwrap();
}
write!(file, "\t]\n").unwrap();
write!(file, "}}").unwrap();
file.flush().unwrap();
}
fn map_buffer<T: bytemuck::Pod + bytemuck::Zeroable, R>(device: &wgpu::Device, buffer: &wgpu::Buffer, f: impl Fn(&T) -> R) -> Vec<R> {
let mut output = Vec::new();
{
let buffer_slice = buffer.slice(..);
// NOTE: We have to create the mapping THEN device.poll() before await
// the future. Otherwise the application will freeze.
let mapping = buffer_slice.map_async(wgpu::MapMode::Read);
device.poll(wgpu::Maintain::Wait);
pollster::block_on(mapping).unwrap();
let data = buffer_slice.get_mapped_range();
println!("data.len(): {}", data.len());
let data_t: &[T] = bytemuck::cast_slice(&data[..]);
output.extend(data_t.iter().map(f));
}
buffer.unmap();
output
}
// pub fn export_mesh_data(path: &str, device: &wgpu::Device, mesh: &model::Mesh) {
// let indices_vec = map_buffer(device, &mesh.index_buffer, |i: &u32| *i);
// let indices = indices_vec.chunks(6).collect::<Vec<_>>();
// let vertices_vec = map_buffer(device, &mesh.vertex_buffer, |v: &f32| *v);
// let vertices = vertices_vec.chunks(8).collect::<Vec<_>>();
// let mut file = std::fs::File::create(path).unwrap();
// use std::io::Write;
// write!(file, "{{\n").unwrap();
// write!(file, "\t\"vertices\": [\n").unwrap();
// for v in vertices {
// write!(file, "\t\t{:?}{}\n", v, ",").unwrap();
// }
// write!(file, "\t],\n").unwrap();
// write!(file, "\t\"indices\": [\n").unwrap();
// for i in indices {
// write!(file, "\t\t{:?}{}\n", i, ",").unwrap();
// }
// write!(file, "\t]\n").unwrap();
// write!(file, "}}").unwrap();
// file.flush().unwrap();
// }
// fn map_buffer<T: bytemuck::Pod + bytemuck::Zeroable, R>(device: &wgpu::Device, buffer: &wgpu::Buffer, f: impl Fn(&T) -> R) -> Vec<R> {
// let mut output = Vec::new();
// {
// let buffer_slice = buffer.slice(..);
// // NOTE: We have to create the mapping THEN device.poll() before await
// // the future. Otherwise the application will freeze.
// buffer_slice.map_async(wgpu::MapMode::Read, |result| {
// result.unwrap();
// let data = buffer_slice.get_mapped_range();
// println!("data.len(): {}", data.len());
// let data_t: &[T] = bytemuck::cast_slice(&data[..]);
// output.extend(data_t.iter().map(f));
// });
// device.poll(wgpu::Maintain::Wait);
// }
// buffer.unmap();
// output
// }

@ -1,45 +1,45 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(2), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>;
[[location(3)]] tangent: vec3<f32>;
[[location(4)]] bitangent: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
@location(2) normal: vec3<f32>,
@location(3) tangent: vec3<f32>,
@location(4) bitangent: vec3<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
[[location(9)]] normal_matrix_0: vec3<f32>;
[[location(10)]] normal_matrix_1: vec3<f32>;
[[location(11)]] normal_matrix_2: vec3<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
@location(9) normal_matrix_0: vec3<f32>,
@location(10) normal_matrix_1: vec3<f32>,
@location(11) normal_matrix_2: vec3<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] tangent_position: vec3<f32>;
[[location(2)]] tangent_light_position: vec3<f32>;
[[location(3)]] tangent_view_position: vec3<f32>;
};
[[stage(vertex)]]
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
@location(1) tangent_position: vec3<f32>,
@location(2) tangent_light_position: vec3<f32>,
@location(3) tangent_view_position: vec3<f32>,
}
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -79,17 +79,17 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[group(0), binding(2)]]
@group(0)@binding(2)
var t_normal: texture_2d<f32>;
[[group(0), binding(3)]]
@group(0) @binding(3)
var s_normal: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);

@ -108,7 +108,7 @@ impl TerrainPipeline {
],
});
let shader = device.create_shader_module(&wgpu::include_wgsl!("terrain.wgsl"));
let shader = device.create_shader_module(wgpu::include_wgsl!("terrain.wgsl"));
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("TerrainPipeline::Gen::PipelineLayout"),
@ -248,7 +248,7 @@ impl TerrainPipeline {
});
cpass.set_pipeline(&self.gen_pipeline);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.dispatch(
cpass.dispatch_workgroups(
dbg!((((self.chunk_size.x + 1) * (self.chunk_size.y + 1)) as f32 / 64.0).ceil()) as _,
1,
1,

@ -50,27 +50,27 @@ fn fbm(p: vec2<f32>) -> f32 {
}
struct ChunkData {
chunk_size: vec2<u32>;
chunk_corner: vec2<i32>;
min_max_height: vec2<f32>;
};
chunk_size: vec2<u32>,
chunk_corner: vec2<i32>,
min_max_height: vec2<f32>,
}
struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] normal: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
}
struct VertexBuffer {
data: [[stride(32)]] array<Vertex>;
};
data: array<Vertex>, // stride: 32
}
struct IndexBuffer {
data: array<u32>;
};
data: array<u32>,
}
[[group(0), binding(0)]] var<uniform> chunk_data: ChunkData;
[[group(0), binding(1)]] var<storage, read_write> vertices: VertexBuffer;
[[group(0), binding(2)]] var<storage, read_write> indices: IndexBuffer;
@group(0) @binding(0) var<uniform> chunk_data: ChunkData;
@group(0) @binding(1) var<storage, read_write> vertices: VertexBuffer;
@group(0) @binding(2) var<storage, read_write> indices: IndexBuffer;
fn terrain_point(p: vec2<f32>) -> vec3<f32> {
return vec3<f32>(
@ -96,9 +96,9 @@ fn terrain_vertex(p: vec2<f32>) -> Vertex {
return Vertex(v, n);
}
[[stage(compute), workgroup_size(64)]]
@compute @workgroup_size(64)
fn gen_terrain_compute(
[[builtin(global_invocation_id)]] gid: vec3<u32>
@builtin(global_invocation_id) gid: vec3<u32>
) {
// Create vertex
let vertex_index = gid.x;
@ -128,61 +128,32 @@ fn gen_terrain_compute(
indices.data[start_index + 5u] = v10;
}
struct VertexOutput {
[[location(0)]] uv: vec2<f32>;
[[builtin(position)]] position: vec4<f32>;
};
// Draws a fullscreen quad
[[stage(vertex)]]
fn gen_terrain_vertex(
[[builtin(vertex_index)]] index: u32,
) {
let u = f32(((index + 2u) / 3u) % 2u);
let v = f32(((index + 1u) / 3u) % 2u);
let uv = vec2<f32>(u, v);
let position = vec4<f32>(-1.0 + uv * 2.0, 0.0, 1.0);
return VertexOutput(vec2<f32>(uv.x, 1.0-uv.y), position);
}
struct FragmentOutput {
[[location(0)]] output: u32;
};
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> FragmentOutput {
var output = 0u;
return FragmentOutput(output);
}
// ============================
// Terrain Rendering
// ============================
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] normal: vec3<f32>;
[[location(1)]] world_pos: vec3<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) normal: vec3<f32>,
@location(1) world_pos: vec3<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
vertex: Vertex,
) -> VertexOutput {
@ -191,13 +162,13 @@ fn vs_main(
return VertexOutput(clip_position, normal, vertex.position);
}
[[group(2), binding(0)]]
@group(2) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(2), binding(1)]]
@group(2) @binding(1)
var s_diffuse: sampler;
[[group(2), binding(2)]]
@group(2) @binding(2)
var t_normal: texture_2d<f32>;
[[group(2), binding(3)]]
@group(2) @binding(3)
var s_normal: sampler;
fn color23(p: vec2<f32>) -> vec3<f32> {
@ -208,9 +179,9 @@ fn color23(p: vec2<f32>) -> vec3<f32> {
);
}
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
var color = smoothStep(vec3<f32>(0.0), vec3<f32>(0.1), fract(in.world_pos));
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
var color = smoothstep(vec3<f32>(0.0), vec3<f32>(0.1), fract(in.world_pos));
color = mix(vec3<f32>(0.5, 0.1, 0.7), vec3<f32>(0.2, 0.2, 0.2), vec3<f32>(color.x * color.y * color.z));
let ambient_strength = 0.1;

@ -10,11 +10,11 @@ bytemuck = { version = "1.4", features = ["derive"]}
cgmath = "0.18"
env_logger = "0.9"
pollster = "0.2"
image = "0.23"
image = "0.24"
log = "0.4"
rayon = "1.4"
tobj = "2.0"
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
[build-dependencies]
@ -22,4 +22,4 @@ anyhow = "1.0"
fs_extra = "1.2"
glob = "0.3"
rayon = "1.4"
naga = { version = "0.8", features = ["glsl-in", "spv-out", "wgsl-out"]}
naga = { version = "0.9", features = ["glsl-in", "spv-out", "wgsl-out"]}

@ -1,6 +1,6 @@
struct FragmentOutput {
[[location(0)]] f_color: vec4<f32>;
};
@location(0) f_color: vec4<f32>,
}
var<private> v_color_1: vec3<f32>;
var<private> f_color: vec4<f32>;
@ -11,8 +11,8 @@ fn main_1() {
return;
}
[[stage(fragment)]]
fn main([[location(0)]] v_color: vec3<f32>) -> FragmentOutput {
@fragment
fn main(@location(0) v_color: vec3<f32>) -> FragmentOutput {
v_color_1 = v_color;
main_1();
let _e7 = f_color;

@ -1,23 +1,23 @@
struct Camera {
u_view_position: vec3<f32>;
u_view_proj: mat4x4<f32>;
};
u_view_position: vec3<f32>,
u_view_proj: mat4x4<f32>,
}
struct Light {
u_position: vec3<f32>;
u_color: vec3<f32>;
};
u_position: vec3<f32>,
u_color: vec3<f32>,
}
struct VertexOutput {
[[location(0)]] v_color: vec3<f32>;
[[builtin(position)]] member: vec4<f32>;
};
@location(0) v_color: vec3<f32>,
@builtin(position) member: vec4<f32>,
}
var<private> a_position_1: vec3<f32>;
var<private> v_color: vec3<f32>;
[[group(0), binding(0)]]
@group(0) @binding(0)
var<uniform> global: Camera;
[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> global_1: Light;
var<private> scale: f32 = 0.25;
var<private> gl_Position: vec4<f32>;
@ -25,6 +25,7 @@ var<private> gl_Position: vec4<f32>;
fn main_1() {
var v_position: vec3<f32>;
_ = (&global.u_view_position);
let _e11 = a_position_1;
let _e12 = scale;
let _e14 = global_1.u_position;
@ -37,9 +38,13 @@ fn main_1() {
return;
}
[[stage(vertex)]]
fn main([[location(0)]] a_position: vec3<f32>) -> VertexOutput {
@vertex
fn main(@location(0) a_position: vec3<f32>) -> VertexOutput {
a_position_1 = a_position;
_ = (&global.u_view_position);
_ = (&global.u_view_proj);
_ = (&global_1.u_position);
_ = (&global_1.u_color);
main_1();
let _e18 = v_color;
let _e20 = gl_Position;

@ -193,7 +193,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -552,7 +552,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -564,7 +564,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -365,7 +365,7 @@ impl ModelLoader {
});
pass.set_pipeline(&self.pipeline);
pass.set_bind_group(0, &calc_bind_group, &[]);
pass.dispatch(binding.compute_info.num_vertices as u32, 1, 1);
pass.dispatch_workgroups(binding.compute_info.num_vertices as u32, 1, 1);
}
queue.submit(std::iter::once(encoder.finish()));
device.poll(wgpu::Maintain::Wait);

@ -1,76 +1,91 @@
struct ModelVertex {
x: f32;
y: f32;
z: f32;
uv: f32;
uw: f32;
nx: f32;
ny: f32;
nz: f32;
tx: f32;
ty: f32;
tz: f32;
bx: f32;
by: f32;
bz: f32;
pad0_: u32;
pad1_: u32;
};
x: f32,
y: f32,
z: f32,
uv: f32,
uw: f32,
nx: f32,
ny: f32,
nz: f32,
tx: f32,
ty: f32,
tz: f32,
bx: f32,
by: f32,
bz: f32,
pad0_: u32,
pad1_: u32,
}
struct SrcVertexBuffer {
srcVertices: [[stride(64)]] array<ModelVertex>;
};
srcVertices: array<ModelVertex>,
}
struct DstVertexBuffer {
dstVertices: [[stride(64)]] array<ModelVertex>;
};
dstVertices: array<ModelVertex>,
}
struct IndexBuffer {
indices: [[stride(4)]] array<u32>;
};
indices: array<u32>,
}
struct ComputeInfo {
numVertices: u32;
numIndices: u32;
};
numVertices: u32,
numIndices: u32,
}
[[group(0), binding(0)]]
@group(0) @binding(0)
var<storage> global: SrcVertexBuffer;
[[group(0), binding(1)]]
@group(0) @binding(1)
var<storage, read_write> global_1: DstVertexBuffer;
[[group(0), binding(2)]]
@group(0) @binding(2)
var<storage> global_2: IndexBuffer;
[[group(0), binding(3)]]
@group(0) @binding(3)
var<uniform> global_3: ComputeInfo;
var<private> gl_GlobalInvocationID: vec3<u32>;
fn getPos(v: ModelVertex) -> vec3<f32> {
var v_1: ModelVertex;
_ = (&global.srcVertices);
_ = (&global_1.dstVertices);
_ = (&global_2.indices);
_ = (&global_3.numVertices);
_ = (&global_3.numIndices);
v_1 = v;
let _e12 = v_1;
let _e14 = v_1;
let _e16 = v_1;
return vec3<f32>(_e12.x, _e14.y, _e16.z);
let _e13 = v_1.x;
let _e15 = v_1.y;
let _e17 = v_1.z;
return vec3<f32>(_e13, _e15, _e17);
}
fn getUV(v_2: ModelVertex) -> vec2<f32> {
var v_3: ModelVertex;
_ = (&global.srcVertices);
_ = (&global_1.dstVertices);
_ = (&global_2.indices);
_ = (&global_3.numVertices);
_ = (&global_3.numIndices);
v_3 = v_2;
let _e12 = v_3;
let _e14 = v_3;
return vec2<f32>(_e12.uv, _e14.uw);
let _e13 = v_3.uv;
let _e15 = v_3.uw;
return vec2<f32>(_e13, _e15);
}
fn getNormal(v_4: ModelVertex) -> vec3<f32> {
var v_5: ModelVertex;
_ = (&global.srcVertices);
_ = (&global_1.dstVertices);
_ = (&global_2.indices);
_ = (&global_3.numVertices);
_ = (&global_3.numIndices);
v_5 = v_4;
let _e12 = v_5;
let _e14 = v_5;
let _e16 = v_5;
return vec3<f32>(_e12.nx, _e14.ny, _e16.nz);
let _e13 = v_5.nx;
let _e15 = v_5.ny;
let _e17 = v_5.nz;
return vec3<f32>(_e13, _e15, _e17);
}
fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex {
@ -98,14 +113,20 @@ fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex {
var delta_uv2_: vec2<f32>;
var r: f32;
_ = (&global_1.dstVertices);
_ = (&global_3.numVertices);
vertexIndex_1 = vertexIndex;
let _e12 = vertexIndex_1;
let _e14 = global.srcVertices[_e12];
v_6 = _e14;
_ = vec3<f32>(f32(0));
_ = vec3<f32>(f32(0));
_ = u32(0);
_ = u32(0);
loop {
let _e30 = i;
let _e31 = global_3.numIndices;
if (!((_e30 < _e31))) {
if !((_e30 < _e31)) {
break;
}
{
@ -124,7 +145,7 @@ fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex {
let _e60 = vertexIndex_1;
let _e63 = index2_;
let _e64 = vertexIndex_1;
if ((((_e56 == _e57) || (_e59 == _e60)) || (_e63 == _e64))) {
if (((_e56 == _e57) || (_e59 == _e60)) || (_e63 == _e64)) {
{
let _e67 = index0_;
let _e69 = global.srcVertices[_e67];
@ -135,21 +156,27 @@ fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex {
let _e75 = index2_;
let _e77 = global.srcVertices[_e75];
v2_ = _e77;
_ = v0_;
let _e80 = v0_;
let _e81 = getPos(_e80);
pos0_ = _e81;
_ = v1_;
let _e84 = v1_;
let _e85 = getPos(_e84);
pos1_ = _e85;
_ = v2_;
let _e88 = v2_;
let _e89 = getPos(_e88);
pos2_ = _e89;
_ = v0_;
let _e92 = v0_;
let _e93 = getUV(_e92);
uv0_ = _e93;
_ = v1_;
let _e96 = v1_;
let _e97 = getUV(_e96);
uv1_ = _e97;
_ = v2_;
let _e100 = v2_;
let _e101 = getUV(_e100);
uv2_ = _e101;
@ -195,7 +222,7 @@ fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex {
}
}
let _e163 = trianglesIncluded;
if ((_e163 > u32(0))) {
if (_e163 > u32(0)) {
{
let _e167 = tangent;
let _e168 = trianglesIncluded;
@ -203,8 +230,10 @@ fn calcTangentBitangent(vertexIndex: u32) -> ModelVertex {
let _e172 = bitangent;
let _e173 = trianglesIncluded;
bitangent = (_e172 / vec3<f32>(f32(_e173)));
_ = tangent;
let _e178 = tangent;
tangent = normalize(_e178);
_ = bitangent;
let _e181 = bitangent;
bitangent = normalize(_e181);
}
@ -229,8 +258,13 @@ fn main_1() {
var vertexIndex_2: u32;
var result: ModelVertex;
_ = (&global.srcVertices);
_ = (&global_2.indices);
_ = (&global_3.numVertices);
_ = (&global_3.numIndices);
let _e11 = gl_GlobalInvocationID;
vertexIndex_2 = _e11.x;
_ = vertexIndex_2;
let _e15 = vertexIndex_2;
let _e16 = calcTangentBitangent(_e15);
result = _e16;
@ -240,9 +274,13 @@ fn main_1() {
return;
}
[[stage(compute), workgroup_size(64, 1, 1)]]
fn main([[builtin(global_invocation_id)]] param: vec3<u32>) {
@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_id) param: vec3<u32>) {
gl_GlobalInvocationID = param;
_ = (&global.srcVertices);
_ = (&global_1.dstVertices);
_ = (&global_2.indices);
_ = (&global_3.numVertices);
main_1();
return;
}

@ -44,9 +44,9 @@ pub fn create_render_pipeline(
fs_src: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
println!("Creating VS Module =======");
let vs_module = device.create_shader_module(&vs_src);
let vs_module = device.create_shader_module(vs_src);
println!("Creating FS Module =======");
let fs_module = device.create_shader_module(&fs_src);
let fs_module = device.create_shader_module(fs_src);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Render Pipeline"),
@ -59,11 +59,11 @@ pub fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: None,
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -107,7 +107,7 @@ pub fn create_compute_pipeline(
let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label,
layout: Some(&layout),
module: &device.create_shader_module(&shader_src),
module: &device.create_shader_module(shader_src),
entry_point: "main",
});
pipeline

@ -1,26 +1,26 @@
struct Light {
light_position: vec3<f32>;
light_color: vec3<f32>;
};
light_position: vec3<f32>,
light_color: vec3<f32>,
}
struct FragmentOutput {
[[location(0)]] f_color: vec4<f32>;
};
@location(0) f_color: vec4<f32>,
}
var<private> v_tex_coords_1: vec2<f32>;
var<private> v_position_1: vec3<f32>;
var<private> v_light_position_1: vec3<f32>;
var<private> v_view_position_1: vec3<f32>;
var<private> f_color: vec4<f32>;
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0) @binding(1)
var s_diffuse: sampler;
[[group(0), binding(2)]]
@group(0) @binding(2)
var t_normal: texture_2d<f32>;
[[group(0), binding(3)]]
@group(0) @binding(3)
var s_normal: sampler;
[[group(2), binding(0)]]
@group(2) @binding(0)
var<uniform> global: Light;
fn main_1() {
@ -38,9 +38,12 @@ fn main_1() {
var specular_color: vec3<f32>;
var result: vec3<f32>;
_ = (&global.light_position);
_ = v_tex_coords_1;
let _e14 = v_tex_coords_1;
let _e15 = textureSample(t_diffuse, s_diffuse, _e14);
object_color = _e15;
_ = v_tex_coords_1;
let _e18 = v_tex_coords_1;
let _e19 = textureSample(t_normal, s_normal, _e18);
object_normal = _e19;
@ -48,15 +51,22 @@ fn main_1() {
let _e24 = ambient_strength;
ambient_color = (_e23 * _e24);
let _e27 = object_normal;
_ = ((_e27.xyz * 2.0) - vec3<f32>(1.0));
let _e34 = object_normal;
normal = normalize(((_e34.xyz * 2.0) - vec3<f32>(1.0)));
let _e43 = v_light_position_1;
let _e44 = v_position_1;
_ = (_e43 - _e44);
let _e46 = v_light_position_1;
let _e47 = v_position_1;
light_dir = normalize((_e46 - _e47));
_ = normal;
_ = light_dir;
let _e53 = normal;
let _e54 = light_dir;
_ = dot(_e53, _e54);
_ = normal;
_ = light_dir;
let _e59 = normal;
let _e60 = light_dir;
diffuse_strength = max(dot(_e59, _e60), 0.0);
@ -65,20 +75,33 @@ fn main_1() {
diffuse_color = (_e65 * _e66);
let _e69 = v_view_position_1;
let _e70 = v_position_1;
_ = (_e69 - _e70);
let _e72 = v_view_position_1;
let _e73 = v_position_1;
view_dir = normalize((_e72 - _e73));
let _e77 = view_dir;
let _e78 = light_dir;
_ = (_e77 + _e78);
let _e80 = view_dir;
let _e81 = light_dir;
half_dir = normalize((_e80 + _e81));
_ = normal;
_ = half_dir;
let _e87 = normal;
let _e88 = half_dir;
_ = dot(_e87, _e88);
_ = normal;
_ = half_dir;
let _e93 = normal;
let _e94 = half_dir;
_ = max(dot(_e93, _e94), 0.0);
_ = normal;
_ = half_dir;
let _e101 = normal;
let _e102 = half_dir;
_ = dot(_e101, _e102);
_ = normal;
_ = half_dir;
let _e107 = normal;
let _e108 = half_dir;
specular_strength = pow(max(dot(_e107, _e108), 0.0), f32(32));
@ -96,12 +119,13 @@ fn main_1() {
return;
}
[[stage(fragment)]]
fn main([[location(0)]] v_tex_coords: vec2<f32>, [[location(1)]] v_position: vec3<f32>, [[location(2)]] v_light_position: vec3<f32>, [[location(3)]] v_view_position: vec3<f32>) -> FragmentOutput {
@fragment
fn main(@location(0) v_tex_coords: vec2<f32>, @location(1) v_position: vec3<f32>, @location(2) v_light_position: vec3<f32>, @location(3) v_view_position: vec3<f32>) -> FragmentOutput {
v_tex_coords_1 = v_tex_coords;
v_position_1 = v_position;
v_light_position_1 = v_light_position;
v_view_position_1 = v_view_position;
_ = (&global.light_position);
main_1();
let _e31 = f_color;
return FragmentOutput(_e31);

@ -1,20 +1,20 @@
struct Camera {
u_view_position: vec3<f32>;
u_view_proj: mat4x4<f32>;
};
u_view_position: vec3<f32>,
u_view_proj: mat4x4<f32>,
}
struct Light {
light_position: vec3<f32>;
light_color: vec3<f32>;
};
light_position: vec3<f32>,
light_color: vec3<f32>,
}
struct VertexOutput {
[[location(0)]] v_tex_coords: vec2<f32>;
[[location(1)]] v_position: vec3<f32>;
[[location(2)]] v_light_position: vec3<f32>;
[[location(3)]] v_view_position: vec3<f32>;
[[builtin(position)]] member: vec4<f32>;
};
@location(0) v_tex_coords: vec2<f32>,
@location(1) v_position: vec3<f32>,
@location(2) v_light_position: vec3<f32>,
@location(3) v_view_position: vec3<f32>,
@builtin(position) member: vec4<f32>,
}
var<private> a_position_1: vec3<f32>;
var<private> a_tex_coords_1: vec2<f32>;
@ -25,7 +25,7 @@ var<private> v_tex_coords: vec2<f32>;
var<private> v_position: vec3<f32>;
var<private> v_light_position: vec3<f32>;
var<private> v_view_position: vec3<f32>;
[[group(1), binding(0)]]
@group(1) @binding(0)
var<uniform> global: Camera;
var<private> model_matrix_0_1: vec4<f32>;
var<private> model_matrix_1_1: vec4<f32>;
@ -34,7 +34,7 @@ var<private> model_matrix_3_1: vec4<f32>;
var<private> normal_matrix_0_1: vec3<f32>;
var<private> normal_matrix_1_1: vec3<f32>;
var<private> normal_matrix_2_1: vec3<f32>;
[[group(2), binding(0)]]
@group(2) @binding(0)
var<uniform> global_1: Light;
var<private> gl_Position: vec4<f32>;
@ -47,6 +47,7 @@ fn main_1() {
var tangent_matrix: mat3x3<f32>;
var model_space: vec4<f32>;
_ = (&global_1.light_color);
let _e24 = model_matrix_0_1;
let _e25 = model_matrix_1_1;
let _e26 = model_matrix_2_1;
@ -60,22 +61,26 @@ fn main_1() {
normal_matrix = mat3x3<f32>(vec3<f32>(_e51.x, _e51.y, _e51.z), vec3<f32>(_e52.x, _e52.y, _e52.z), vec3<f32>(_e53.x, _e53.y, _e53.z));
let _e68 = normal_matrix;
let _e69 = a_normal_1;
_ = (_e68 * _e69);
let _e71 = normal_matrix;
let _e72 = a_normal_1;
normal = normalize((_e71 * _e72));
let _e76 = normal_matrix;
let _e77 = a_tangent_1;
_ = (_e76 * _e77);
let _e79 = normal_matrix;
let _e80 = a_tangent_1;
tangent = normalize((_e79 * _e80));
let _e84 = normal_matrix;
let _e85 = a_bitangent_1;
_ = (_e84 * _e85);
let _e87 = normal_matrix;
let _e88 = a_bitangent_1;
bitangent = normalize((_e87 * _e88));
let _e92 = tangent;
let _e93 = bitangent;
let _e94 = normal;
_ = mat3x3<f32>(vec3<f32>(_e92.x, _e92.y, _e92.z), vec3<f32>(_e93.x, _e93.y, _e93.z), vec3<f32>(_e94.x, _e94.y, _e94.z));
let _e108 = tangent;
let _e109 = bitangent;
let _e110 = normal;
@ -98,8 +103,8 @@ fn main_1() {
return;
}
[[stage(vertex)]]
fn main([[location(0)]] a_position: vec3<f32>, [[location(1)]] a_tex_coords: vec2<f32>, [[location(2)]] a_normal: vec3<f32>, [[location(3)]] a_tangent: vec3<f32>, [[location(4)]] a_bitangent: vec3<f32>, [[location(5)]] model_matrix_0_: vec4<f32>, [[location(6)]] model_matrix_1_: vec4<f32>, [[location(7)]] model_matrix_2_: vec4<f32>, [[location(8)]] model_matrix_3_: vec4<f32>, [[location(9)]] normal_matrix_0_: vec3<f32>, [[location(10)]] normal_matrix_1_: vec3<f32>, [[location(11)]] normal_matrix_2_: vec3<f32>) -> VertexOutput {
@vertex
fn main(@location(0) a_position: vec3<f32>, @location(1) a_tex_coords: vec2<f32>, @location(2) a_normal: vec3<f32>, @location(3) a_tangent: vec3<f32>, @location(4) a_bitangent: vec3<f32>, @location(5) model_matrix_0_: vec4<f32>, @location(6) model_matrix_1_: vec4<f32>, @location(7) model_matrix_2_: vec4<f32>, @location(8) model_matrix_3_: vec4<f32>, @location(9) normal_matrix_0_: vec3<f32>, @location(10) normal_matrix_1_: vec3<f32>, @location(11) normal_matrix_2_: vec3<f32>) -> VertexOutput {
a_position_1 = a_position;
a_tex_coords_1 = a_tex_coords;
a_normal_1 = a_normal;
@ -112,6 +117,9 @@ fn main([[location(0)]] a_position: vec3<f32>, [[location(1)]] a_tex_coords: vec
normal_matrix_0_1 = normal_matrix_0_;
normal_matrix_1_1 = normal_matrix_1_;
normal_matrix_2_1 = normal_matrix_2_;
_ = (&global.u_view_position);
_ = (&global.u_view_proj);
_ = (&global_1.light_position);
main_1();
let _e65 = v_tex_coords;
let _e67 = v_position;

@ -11,10 +11,10 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.9"
pollster = "0.2"
image = "0.23"
image = "0.24.2"
log = "0.4"
tobj = "2.0"
wgpu = "0.12"
wgpu = "0.13"
wgpu-subscriber = "0.1"
winit = "0.26"
@ -22,5 +22,5 @@ winit = "0.26"
anyhow = "1.0"
fs_extra = "1.2"
glob = "0.3"
naga = { version = "0.8", features = ["glsl-in", "spv-out", "wgsl-out"]}
naga = { version = "0.9", features = ["glsl-in", "spv-out", "wgsl-out"]}
rayon = "1.5"

@ -63,7 +63,7 @@ impl Display {
.unwrap();
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,

@ -13,7 +13,7 @@ pub struct RenderPipelineBuilder<'a> {
depth_bias_slope_scale: f32,
depth_bias_clamp: f32,
primitive_topology: wgpu::PrimitiveTopology,
color_states: Vec<wgpu::ColorTargetState>,
color_states: Vec<Option<wgpu::ColorTargetState>>,
depth_stencil: Option<wgpu::DepthStencilState>,
index_format: wgpu::IndexFormat,
vertex_buffers: Vec<wgpu::VertexBufferLayout<'a>>,
@ -98,7 +98,7 @@ impl<'a> RenderPipelineBuilder<'a> {
}
pub fn color_state(&mut self, cs: wgpu::ColorTargetState) -> &mut Self {
self.color_states.push(cs);
self.color_states.push(Some(cs));
self
}
@ -248,5 +248,5 @@ fn create_shader_module(
device: &wgpu::Device,
spirv: wgpu::ShaderModuleDescriptor,
) -> wgpu::ShaderModule {
device.create_shader_module(&spirv)
device.create_shader_module(spirv)
}

@ -1,17 +1,17 @@
struct SimulationData {
clear_color: vec4<f32>;
canvas_size: vec2<f32>;
mouse_pos: vec2<f32>;
time: vec2<f32>;
};
clear_color: vec4<f32>,
canvas_size: vec2<f32>,
mouse_pos: vec2<f32>,
time: vec2<f32>,
}
struct FragmentOutput {
[[location(0)]] frag_color: vec4<f32>;
};
@location(0) frag_color: vec4<f32>,
}
var<private> clip_coords_1: vec3<f32>;
var<private> frag_color: vec4<f32>;
[[group(0), binding(0)]]
@group(0) @binding(0)
var<uniform> global: SimulationData;
fn main_1() {
@ -19,14 +19,21 @@ fn main_1() {
var uv: vec3<f32>;
var col: vec4<f32>;
_ = (&global.canvas_size);
_ = (&global.mouse_pos);
let _e10 = global.time;
t = _e10.x;
let _e13 = clip_coords_1;
uv = ((_e13 * 0.5) + vec3<f32>(0.5));
let _e20 = uv;
_ = vec4<f32>(_e20.x, _e20.y, _e20.z, 1.0);
_ = global.clear_color;
_ = t;
let _e28 = t;
_ = sin(_e28);
let _e30 = uv;
let _e36 = global.clear_color;
_ = t;
let _e38 = t;
col = mix(vec4<f32>(_e30.x, _e30.y, _e30.z, 1.0), _e36, vec4<f32>(sin(_e38)));
let _e43 = col;
@ -34,9 +41,12 @@ fn main_1() {
return;
}
[[stage(fragment)]]
fn main([[location(0)]] clip_coords: vec3<f32>) -> FragmentOutput {
@fragment
fn main(@location(0) clip_coords: vec3<f32>) -> FragmentOutput {
clip_coords_1 = clip_coords;
_ = (&global.clear_color);
_ = (&global.canvas_size);
_ = (&global.mouse_pos);
main_1();
let _e15 = frag_color;
return FragmentOutput(_e15);

@ -80,14 +80,14 @@ impl ShaderCanvas {
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Shader Canvas Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: frame,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
}],
})],
depth_stencil_attachment: None,
});
pass.set_bind_group(0, &self.simulation_bind_group, &[]);
@ -195,8 +195,8 @@ impl<'a> ShaderCanvasBuilder<'a> {
}],
});
let vert_module = device.create_shader_module(&vert_code);
let frag_module = device.create_shader_module(&frag_code);
let vert_module = device.create_shader_module(vert_code);
let frag_module = device.create_shader_module(frag_code);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: self.label,
@ -214,14 +214,14 @@ impl<'a> ShaderCanvasBuilder<'a> {
fragment: Some(wgpu::FragmentState {
entry_point: "main",
module: &frag_module,
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: display_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,

@ -1,7 +1,7 @@
struct VertexOutput {
[[location(0)]] clip_coords: vec3<f32>;
[[builtin(position)]] member: vec4<f32>;
};
@location(0) clip_coords: vec3<f32>,
@builtin(position) member: vec4<f32>,
}
var<private> clip_coords: vec3<f32>;
var<private> gl_VertexIndex: u32;
@ -23,8 +23,8 @@ fn main_1() {
return;
}
[[stage(vertex)]]
fn main([[builtin(vertex_index)]] param: u32) -> VertexOutput {
@vertex
fn main(@builtin(vertex_index) param: u32) -> VertexOutput {
gl_VertexIndex = param;
main_1();
let _e5 = clip_coords;

@ -11,11 +11,12 @@ bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
env_logger = "0.9"
pollster = "0.2"
image = "0.23"
image = "0.24.2"
log = "0.4"
tobj = "3.1"
wgpu = "0.12"
wgpu = "0.13"
winit = "0.26"
gif = "0.10.3"
gif = "0.11.4"
futures-intrusive = "0.4"
framework = { version = "0.1.0", path = "../framework" }

@ -86,7 +86,7 @@ async fn run() {
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("GIF Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &render_target.view,
resolve_target: None,
ops: wgpu::Operations {
@ -98,7 +98,7 @@ async fn run() {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});
@ -129,13 +129,15 @@ async fn run() {
// Create the map request
let buffer_slice = output_buffer.slice(..);
let request = buffer_slice.map_async(wgpu::MapMode::Read);
let (tx, rx) = futures_intrusive::channel::shared::oneshot_channel();
buffer_slice.map_async(wgpu::MapMode::Read, move |result| {
tx.send(result).unwrap();
});
// wait for the GPU to finish
device.poll(wgpu::Maintain::Wait);
let result = request.await;
match result {
Ok(()) => {
match rx.receive().await {
Some(Ok(())) => {
let padded_data = buffer_slice.get_mapped_range();
let data = padded_data
.chunks(padded_bytes_per_row as _)
@ -155,11 +157,11 @@ async fn run() {
}
fn save_gif(path: &str, frames: &mut Vec<Vec<u8>>, speed: i32, size: u16) -> anyhow::Result<()> {
use gif::{Encoder, Frame, Repeat, SetParameter};
use gif::{Encoder, Frame, Repeat};
let mut image = std::fs::File::create(path)?;
let mut encoder = Encoder::new(&mut image, size, size, &[])?;
encoder.set(Repeat::Infinite)?;
encoder.set_repeat(Repeat::Infinite)?;
for mut frame in frames {
encoder.write_frame(&Frame::from_rgba_speed(size, size, &mut frame, speed))?;
@ -176,7 +178,7 @@ fn create_render_pipeline(
// let fs_src = wgpu::include_spirv!("shader.frag.spv");
// let vs_module = device.create_shader_module(&vs_src);
// let fs_module = device.create_shader_module(&fs_src);
let shader = device.create_shader_module(&wgpu::include_wgsl!("shader.wgsl"));
let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Render Pipeline Layout"),
@ -195,11 +197,11 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: target.desc.format,
blend: Some(wgpu::BlendState::REPLACE),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,

@ -1,10 +1,10 @@
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
@builtin(position) clip_position: vec4<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
[[builtin(vertex_index)]] in_vertex_index: u32,
@builtin(vertex_index) in_vertex_index: u32,
) -> VertexOutput {
var out: VertexOutput;
let x = f32(1 - i32(in_vertex_index)) * 0.5;
@ -13,7 +13,7 @@ fn vs_main(
return out;
}
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.3, 0.2, 0.1, 1.0);
}

@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
anyhow = "1.0"
wgpu = "0.12"
wgpu = "0.13"
pollster = "0.2"
imgui = "0.7"
imgui-wgpu = "0.17"

@ -15,10 +15,10 @@ anyhow = "1.0"
bytemuck = { version = "1.4", features = [ "derive" ] }
cgmath = "0.18"
pollster = "0.2"
wgpu = { version = "0.12", features = ["spirv"]}
wgpu = { version = "0.13", features = ["spirv"]}
wgpu_glyph = "0.16"
rand = "0.8"
rodio = { version = "0.14", default-features = false, features = ["wav"] }
rodio = { version = "0.15", default-features = false, features = ["wav"] }
log = "0.4"
instant = "0.1"
@ -26,7 +26,7 @@ instant = "0.1"
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
getrandom = { version = "0.2", features = ["js"] }
rodio = { version = "0.14", default-features = false, features = ["wasm-bindgen", "wav"] }
rodio = { version = "0.15", default-features = false, features = ["wasm-bindgen", "wav"] }
wasm-bindgen-futures = "0.4.20"
wasm-bindgen = "0.2.76"
web-sys = { version = "0.3.53", features = [
@ -34,11 +34,11 @@ web-sys = { version = "0.3.53", features = [
"Window",
"Element",
]}
wgpu = { version = "0.12", features = ["spirv", "webgl"]}
wgpu = { version = "0.13", features = ["spirv", "webgl"]}
[build-dependencies]
anyhow = "1.0"
fs_extra = "1.2"
glob = "0.3"
rayon = "1.4"
naga = { version = "0.7", features = ["glsl-in", "spv-out", "wgsl-out"]}
naga = { version = "0.9", features = ["glsl-in", "spv-out", "wgsl-out"]}

@ -1,5 +1,5 @@
struct FragmentOutput {
[[location(0)]] fColor: vec4<f32>;
@location(0) fColor: vec4<f32>;
};
var<private> fColor: vec4<f32>;
@ -9,7 +9,7 @@ fn main_1() {
return;
}
[[stage(fragment)]]
@fragment
fn main() -> FragmentOutput {
main_1();
let e3: vec4<f32> = fColor;

@ -1,5 +1,5 @@
struct VertexOutput {
[[builtin(position)]] member: vec4<f32>;
@builtin(position) member: vec4<f32>;
};
var<private> aPosition_1: vec2<f32>;
@ -11,8 +11,8 @@ fn main_1() {
return;
}
[[stage(vertex)]]
fn main([[location(0)]] aPosition: vec2<f32>) -> VertexOutput {
@vertex
fn main(@location(0) aPosition: vec2<f32>) -> VertexOutput {
aPosition_1 = aPosition;
main_1();
let e5: vec4<f32> = gl_Position;

@ -64,7 +64,7 @@ impl Render {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -259,14 +259,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,

@ -17,7 +17,7 @@ pollster = "0.2"
log = "0.4"
rayon = "1.4" # NEW!
tobj = { version = "3.2", features = ["async"]}
wgpu = { version = "0.12"}
wgpu = { version = "0.13"}
winit = "0.26"
instant = "0.1"
async-std = "1"
@ -31,7 +31,7 @@ features = ["png", "jpeg"]
reqwest = { version = "0.11" }
console_error_panic_hook = "0.1"
console_log = "0.2"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -165,7 +165,7 @@ fn create_render_pipeline(
vertex_layouts: &[wgpu::VertexBufferLayout],
shader: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(&shader);
let shader = device.create_shader_module(shader);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some(&format!("{:?}", shader)),
@ -178,14 +178,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -253,7 +253,7 @@ impl State {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -608,7 +608,7 @@ impl State {
{
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
@ -620,7 +620,7 @@ impl State {
}),
store: true,
},
}],
})],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {

@ -1,29 +1,29 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
@location(0) position: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -36,7 +36,7 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}

@ -1,45 +1,45 @@
// Vertex shader
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(2), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>;
[[location(3)]] tangent: vec3<f32>;
[[location(4)]] bitangent: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
@location(2) normal: vec3<f32>,
@location(3) tangent: vec3<f32>,
@location(4) bitangent: vec3<f32>,
}
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
[[location(9)]] normal_matrix_0: vec3<f32>;
[[location(10)]] normal_matrix_1: vec3<f32>;
[[location(11)]] normal_matrix_2: vec3<f32>;
};
@location(5) model_matrix_0: vec4<f32>,
@location(6) model_matrix_1: vec4<f32>,
@location(7) model_matrix_2: vec4<f32>,
@location(8) model_matrix_3: vec4<f32>,
@location(9) normal_matrix_0: vec3<f32>,
@location(10) normal_matrix_1: vec3<f32>,
@location(11) normal_matrix_2: vec3<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] tangent_position: vec3<f32>;
[[location(2)]] tangent_light_position: vec3<f32>;
[[location(3)]] tangent_view_position: vec3<f32>;
};
[[stage(vertex)]]
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
@location(1) tangent_position: vec3<f32>,
@location(2) tangent_light_position: vec3<f32>,
@location(3) tangent_view_position: vec3<f32>,
}
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -79,17 +79,17 @@ fn vs_main(
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[group(0), binding(2)]]
@group(0)@binding(2)
var t_normal: texture_2d<f32>;
[[group(0), binding(3)]]
@group(0) @binding(3)
var s_normal: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);

@ -7,10 +7,11 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
image = "0.23"
shaderc = "0.7"
wgpu = { version = "0.12", features = ["spirv"] }
image = "0.24"
shaderc = "0.8"
wgpu = { version = "0.13", features = ["spirv"] }
pollster = "0.2"
futures-intrusive = "0.4"
[[bin]]
name = "windowless"

@ -48,7 +48,7 @@ async fn run() {
let vs_src = include_str!("shader.vert");
let fs_src = include_str!("shader.frag");
let mut compiler = shaderc::Compiler::new().unwrap();
let compiler = shaderc::Compiler::new().unwrap();
let vs_spirv = compiler
.compile_into_spirv(
vs_src,
@ -69,11 +69,11 @@ async fn run() {
.unwrap();
let vs_data = wgpu::util::make_spirv(vs_spirv.as_binary_u8());
let fs_data = wgpu::util::make_spirv(fs_spirv.as_binary_u8());
let vs_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let vs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Vertex Shader"),
source: vs_data,
});
let fs_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let fs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Fragment Shader"),
source: fs_data,
});
@ -95,14 +95,14 @@ async fn run() {
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: texture_desc.format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -133,7 +133,7 @@ async fn run() {
{
let render_pass_desc = wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &texture_view,
resolve_target: None,
ops: wgpu::Operations {
@ -145,7 +145,7 @@ async fn run() {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
};
let mut render_pass = encoder.begin_render_pass(&render_pass_desc);
@ -181,9 +181,12 @@ async fn run() {
// NOTE: We have to create the mapping THEN device.poll() before await
// the future. Otherwise the application will freeze.
let mapping = buffer_slice.map_async(wgpu::MapMode::Read);
let (tx, rx) = futures_intrusive::channel::shared::oneshot_channel();
buffer_slice.map_async(wgpu::MapMode::Read, move |result| {
tx.send(result).unwrap();
});
device.poll(wgpu::Maintain::Wait);
mapping.await.unwrap();
rx.receive().await.unwrap().unwrap();
let data = buffer_slice.get_mapped_range();
@ -191,8 +194,10 @@ async fn run() {
let buffer =
ImageBuffer::<Rgba<u8>, _>::from_raw(texture_size, texture_size, data).unwrap();
buffer.save("image.png").unwrap();
}
output_buffer.unmap();
}
fn main() {

@ -59,6 +59,7 @@ module.exports = {
title: 'News',
collapsable: true,
children: [
'/news/0.13/',
'/news/0.12/',
'/news/pre-0.12/',
]

@ -11,7 +11,7 @@ For the beginner stuff, we're going to keep things very simple, we'll add things
winit = "0.26"
env_logger = "0.9"
log = "0.4"
wgpu = "0.12"
wgpu = "0.13"
```
## Using Rust's new resolver
@ -110,7 +110,7 @@ cfg-if = "1"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4.30"
web-sys = { version = "0.3", features = [

@ -138,7 +138,7 @@ The `limits` field describes the limit of certain types of resources that we can
```rust
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
@ -217,13 +217,13 @@ cfg-if = "1"
winit = "0.26"
env_logger = "0.9"
log = "0.4"
wgpu = "0.12"
wgpu = "0.13"
pollster = "0.2"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
console_log = "0.2.0"
wgpu = { version = "0.12", features = ["webgl"]}
wgpu = { version = "0.13", features = ["webgl"]}
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = [

@ -47,12 +47,12 @@ In the same folder as `main.rs`, create a file `shader.wgsl`. Write the followin
// Vertex shader
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
@builtin(position) clip_position: vec4<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
[[builtin(vertex_index)]] in_vertex_index: u32,
@builtin(vertex_index) in_vertex_index: u32,
) -> VertexOutput {
var out: VertexOutput;
let x = f32(1 - i32(in_vertex_index)) * 0.5;
@ -62,7 +62,7 @@ fn vs_main(
}
```
First, we declare `struct` to store the output of our vertex shader. This consists of only one field currently which is our vertex's `clip_position`. The `[[builtin(position)]]` bit tells WGPU that this is the value we want to use as the vertex's [clip coordinates](https://en.wikipedia.org/wiki/Clip_coordinates). This is analogous to GLSL's `gl_Position` variable.
First, we declare `struct` to store the output of our vertex shader. This consists of only one field currently which is our vertex's `clip_position`. The `@builtin(position)` bit tells WGPU that this is the value we want to use as the vertex's [clip coordinates](https://en.wikipedia.org/wiki/Clip_coordinates). This is analogous to GLSL's `gl_Position` variable.
<div class="note">
@ -70,7 +70,7 @@ Vector types such as `vec4` are generic. Currently, you must specify the type of
</div>
The next part of the shader code is the `vs_main` function. We are using `[[stage(vertex)]]` to mark this function as a valid entry point for a vertex shader. We expect a `u32` called `in_vertex_index` which gets its value from `[[builtin(vertex_index)]]`.
The next part of the shader code is the `vs_main` function. We are using `@vertex` to mark this function as a valid entry point for a vertex shader. We expect a `u32` called `in_vertex_index` which gets its value from `@builtin(vertex_index)`.
We then declare a variable called `out` using our `VertexOutput` struct. We create two other variables for the `x`, and `y`, of a triangle.
@ -93,10 +93,10 @@ Now we can save our `clip_position` to `out`. We then just return `out` and we'r
We technically didn't need a struct for this example, and could have just done something like the following:
```wgsl
[[stage(vertex)]]
@vertex
fn vs_main(
[[builtin(vertex_index)]] in_vertex_index: u32
) -> [[builtin(position)]] vec4<f32> {
@builtin(vertex_index) in_vertex_index: u32
) -> @builtin(position) vec4<f32> {
// Vertex shader code...
}
```
@ -110,8 +110,8 @@ Next up, the fragment shader. Still in `shader.wgsl` add the following:
```wgsl
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(0.3, 0.2, 0.1, 1.0);
}
```
@ -124,7 +124,7 @@ Notice that the entry point for the vertex shader was named `vs_main` and that t
</div>
The `[[location(0)]]` bit tells WGPU to store the `vec4` value returned by this function in the first color target. We'll get into what this is later.
The `@location(0)` bit tells WGPU to store the `vec4` value returned by this function in the first color target. We'll get into what this is later.
## How do we use the shaders?
This is the part where we finally make the thing in the title: the pipeline. First, let's modify `State` to include the following.
@ -145,7 +145,7 @@ struct State {
Now let's move to the `new()` method, and start making the pipeline. We'll have to load in those shaders we made earlier, as the `render_pipeline` requires those.
```rust
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Shader"),
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
});
@ -197,7 +197,7 @@ let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescrip
```
Several things to note here:
1. Here you can specify which function inside the shader should be the `entry_point`. These are the functions we marked with `[[stage(vertex)]]` and `[[stage(fragment)]]`
1. Here you can specify which function inside the shader should be the `entry_point`. These are the functions we marked with `@vertex` and `@fragment`
2. The `buffers` field tells `wgpu` what type of vertices we want to pass to the vertex shader. We're specifying the vertices in the vertex shader itself, so we'll leave this empty. We'll put something there in the next tutorial.
3. The `fragment` is technically optional, so you have to wrap it in `Some()`. We need it if we want to store color data to the `surface`.
4. The `targets` field tells `wgpu` what color outputs it should set up. Currently, we only need one for the `surface`. We use the `surface`'s format so that copying to it is easy, and we specify that the blending should just replace old pixel data with new data. We also tell `wgpu` to write to all colors: red, blue, green, and alpha. *We'll talk more about* `color_state` *when we talk about textures.*
@ -270,7 +270,7 @@ If you run your program now, it'll take a little longer to start, but it will st
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[
// This is what [[location(0)]] in the fragment shader targets
// This is what @location(0) in the fragment shader targets
wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
@ -300,7 +300,7 @@ If you run your program now, it'll take a little longer to start, but it will st
We didn't change much, but let's talk about what we did change.
1. We renamed `_render_pass` to `render_pass` and made it mutable.
2. We set the pipeline on the `render_pass` using the one we just created.
3. We tell `wgpu` to draw *something* with 3 vertices, and 1 instance. This is where `[[builtin(vertex_index)]]` comes from.
3. We tell `wgpu` to draw *something* with 3 vertices, and 1 instance. This is where `@builtin(vertex_index)` comes from.
With all that you should be seeing a lovely brown triangle.

@ -140,7 +140,7 @@ wgpu::VertexBufferLayout {
2. `step_mode` tells the pipeline how often it should move to the next vertex. This seems redundant in our case, but we can specify `wgpu::VertexStepMode::Instance` if we only want to change vertices when we start drawing a new instance. We'll cover instancing in a later tutorial.
3. Vertex attributes describe the individual parts of the vertex. Generally, this is a 1:1 mapping with a struct's fields, which is true in our case.
4. This defines the `offset` in bytes until the attribute starts. For the first attribute, the offset is usually zero. For any later attributes, the offset is the sum over `size_of` of the previous attributes' data.
5. This tells the shader what location to store this attribute at. For example `[[location(0)]] x: vec3<f32>` in the vertex shader would correspond to the `position` field of the `Vertex` struct, while `[[location(1)]] x: vec3<f32>` would be the `color` field.
5. This tells the shader what location to store this attribute at. For example `@location(0) x: vec3<f32>` in the vertex shader would correspond to the `position` field of the `Vertex` struct, while `@location(1) x: vec3<f32>` would be the `color` field.
6. `format` tells the shader the shape of the attribute. `Float32x3` corresponds to `vec3<f32>` in shader code. The max value we can store in an attribute is `Float32x4` (`Uint32x4`, and `Sint32x4` work as well). We'll keep this in mind for when we have to store things that are bigger than `Float32x4`.
For you visual learners, our vertex buffer looks like this.
@ -280,16 +280,16 @@ Before our changes will have any effect, we need to update our vertex shader to
// Vertex shader
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] color: vec3<f32>;
@location(0) position: vec3<f32>,
@location(1) color: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -301,8 +301,8 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}
```

@ -365,16 +365,16 @@ With our new `Vertex` structure in place, it's time to update our shaders. We'll
// Vertex shader
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -390,13 +390,13 @@ Now that we have our vertex shader outputting our `tex_coords`, we need to chang
```wgsl
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}
```
@ -442,7 +442,7 @@ winit = "0.26"
env_logger = "0.9"
log = "0.4"
pollster = "0.2"
wgpu = "0.12"
wgpu = "0.13"
bytemuck = { version = "1.4", features = [ "derive" ] }
anyhow = "1.0" # NEW!
```

@ -235,22 +235,22 @@ Modify the vertex shader to include the following.
```wgsl
// Vertex shader
struct CameraUniform {
view_proj: mat4x4<f32>;
view_proj: mat4x4<f32>,
};
[[group(1), binding(0)]] // 1.
@group(1) @binding(0) // 1.
var<uniform> camera: CameraUniform;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
};
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>,
}
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
};
@builtin(position) clip_position: vec4<f32>,
@location(0) tex_coords: vec2<f32>,
}
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {

@ -229,17 +229,17 @@ We need to reference the parts of our new matrix in `shader.wgsl` so that we can
```wgsl
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
@location(5) model_matrix_0: vec4<f32>;
@location(6) model_matrix_1: vec4<f32>;
@location(7) model_matrix_2: vec4<f32>;
@location(8) model_matrix_3: vec4<f32>;
};
```
We need to reassemble the matrix before we can use it.
```wgsl
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -257,7 +257,7 @@ fn vs_main(
We'll apply the `model_matrix` before we apply `camera_uniform.view_proj`. We do this because the `camera_uniform.view_proj` changes the coordinate system from `world space` to `camera space`. Our `model_matrix` is a `world space` transformation, so we don't want to be in `camera space` when using it.
```wgsl
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,

@ -1,13 +1,5 @@
# Working with Lights
<div class="warn">
The shaders used in this example don't compile on WASM using version 0.12.0 of wgpu. I created an issue [here](https://github.com/gfx-rs/naga/issues/1739). The issue is fixed on the most recent version of naga, but that is using the updated WGSL syntax.
Once 0.13 comes out I'll port the WGSL code to the new syntax and this example should be working.
</div>
While we can tell that our scene is 3d because of our camera, it still feels very flat. That's because our model stays the same color regardless of how it's oriented. If we want to change that we need to add lighting to our scene.
In the real world, a light source emits photons that bounce around until they enter our eyes. The color we see is the light's original color minus whatever energy it lost while it was bouncing around.
@ -145,7 +137,7 @@ fn create_render_pipeline(
vertex_layouts: &[wgpu::VertexBufferLayout],
shader: wgpu::ShaderModuleDescriptor,
) -> wgpu::RenderPipeline {
let shader = device.create_shader_module(&shader);
let shader = device.create_shader_module(shader);
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Render Pipeline"),
@ -158,14 +150,14 @@ fn create_render_pipeline(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: color_format,
blend: Some(wgpu::BlendState {
alpha: wgpu::BlendComponent::REPLACE,
color: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
@ -338,28 +330,28 @@ With that in place, we need to write the actual shaders.
// Vertex shader
struct Camera {
view_proj: mat4x4<f32>;
};
[[group(0), binding(0)]]
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> camera: Camera;
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(1), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(1) @binding(0)
var<uniform> light: Light;
struct VertexInput {
[[location(0)]] position: vec3<f32>;
@location(0) position: vec3<f32>,
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] color: vec3<f32>;
@builtin(position) clip_position: vec4<f32>,
@location(0) color: vec3<f32>,
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
) -> VertexOutput {
@ -372,8 +364,8 @@ fn vs_main(
// Fragment shader
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color, 1.0);
}
```
@ -500,18 +492,18 @@ The ambient part is based on the light color as well as the object color. We've
```wgsl
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
[[group(2), binding(0)]]
position: vec3<f32>,
color: vec3<f32>,
}
@group(2) @binding(0)
var<uniform> light: Light;
```
Then we need to update our main shader code to calculate and use the ambient color value.
```wgsl
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
// We don't need (or want) much ambient light, so 0.1 is fine
@ -540,9 +532,9 @@ We're going to need to pull in the normal vector into our `shader.wgsl`.
```wgsl
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>; // NEW!
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>;
@location(2) normal: vec3<f32>; // NEW!
};
```
@ -550,17 +542,17 @@ We're also going to want to pass that value, as well as the vertex's position to
```wgsl
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] world_normal: vec3<f32>;
[[location(2)]] world_position: vec3<f32>;
@builtin(position) clip_position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
@location(1) world_normal: vec3<f32>;
@location(2) world_position: vec3<f32>;
};
```
For now, let's just pass the normal directly as-is. This is wrong, but we'll fix it later.
```wgsl
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -727,24 +719,24 @@ Now we need to reconstruct the normal matrix in the vertex shader.
```wgsl
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
@location(5) model_matrix_0: vec4<f32>;
@location(6) model_matrix_1: vec4<f32>;
@location(7) model_matrix_2: vec4<f32>;
@location(8) model_matrix_3: vec4<f32>;
// NEW!
[[location(9)]] normal_matrix_0: vec3<f32>;
[[location(10)]] normal_matrix_1: vec3<f32>;
[[location(11)]] normal_matrix_2: vec3<f32>;
@location(9) normal_matrix_0: vec3<f32>;
@location(10) normal_matrix_1: vec3<f32>;
@location(11) normal_matrix_2: vec3<f32>;
};
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
[[location(1)]] world_normal: vec3<f32>;
[[location(2)]] world_position: vec3<f32>;
@builtin(position) clip_position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
@location(1) world_normal: vec3<f32>;
@location(2) world_position: vec3<f32>;
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -813,10 +805,10 @@ Because this is relative to the view angle, we are going to need to pass in the
```wgsl
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
@group(1) @binding(0)
var<uniform> camera: Camera;
```

@ -1,13 +1,5 @@
# Normal Mapping
<div class="warn">
The shaders used in this example don't compile on WASM using version 0.12.0 of wgpu. I created an issue [here](https://github.com/gfx-rs/naga/issues/1739). The issue is fixed on the most recent version of naga, but that is using the updated WGSL syntax.
Once 0.13 comes out I'll port the WGSL code to the new syntax and this example should be working.
</div>
With just lighting, our scene is already looking pretty good. Still, our models are still overly smooth. This is understandable because we are using a very simple model. If we were using a texture that was supposed to be smooth, this wouldn't be a problem, but our brick texture is supposed to be rougher. We could solve this by adding more geometry, but that would slow our scene down, and it be would hard to know where to add new polygons. This is where normal mapping comes in.
Remember in [the instancing tutorial](/beginner/tutorial7-instancing/#a-different-way-textures), we experimented with storing instance data in a texture? A normal map is doing just that with normal data! We'll use the normals in the normal map in our lighting calculation in addition to the vertex normal.
@ -106,17 +98,17 @@ Now we can use the texture in the fragment shader.
```wgsl
// Fragment shader
[[group(0), binding(0)]]
@group(0) @binding(0)
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
@group(0)@binding(1)
var s_diffuse: sampler;
[[group(0), binding(2)]]
@group(0)@binding(2)
var t_normal: texture_2d<f32>;
[[group(0), binding(3)]]
@group(0) @binding(3)
var s_normal: sampler;
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let object_color: vec4<f32> = textureSample(t_diffuse, s_diffuse, in.tex_coords);
let object_normal: vec4<f32> = textureSample(t_normal, s_normal, in.tex_coords);
@ -333,11 +325,11 @@ Since the normal map by default is in tangent space, we need to transform all th
```wgsl
struct VertexInput {
[[location(0)]] position: vec3<f32>;
[[location(1)]] tex_coords: vec2<f32>;
[[location(2)]] normal: vec3<f32>;
[[location(3)]] tangent: vec3<f32>;
[[location(4)]] bitangent: vec3<f32>;
@location(0) position: vec3<f32>,
@location(1) tex_coords: vec2<f32>;
@location(2) normal: vec3<f32>;
@location(3) tangent: vec3<f32>;
@location(4) bitangent: vec3<f32>;
};
```
@ -345,15 +337,15 @@ Next, we'll construct the `tangent_matrix` and then transform the vertex's light
```wgsl
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
[[location(0)]] tex_coords: vec2<f32>;
@builtin(position) clip_position: vec4<f32>;
@location(0) tex_coords: vec2<f32>;
// UPDATED!
[[location(1)]] tangent_position: vec3<f32>;
[[location(2)]] tangent_light_position: vec3<f32>;
[[location(3)]] tangent_view_position: vec3<f32>;
@location(1) tangent_position: vec3<f32>;
@location(2) tangent_light_position: vec3<f32>;
@location(3) tangent_view_position: vec3<f32>;
};
[[stage(vertex)]]
@vertex
fn vs_main(
model: VertexInput,
instance: InstanceInput,
@ -390,8 +382,8 @@ fn vs_main(
Finally, we'll update the fragment shader to use these transformed lighting values.
```wgsl
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
// Sample textures..
// Create the lighting vectors

@ -1,13 +1,5 @@
# A Better Camera
<div class="warn">
The shaders used in this example don't compile on WASM using version 0.12.0 of wgpu. I created an issue [here](https://github.com/gfx-rs/naga/issues/1739). The issue is fixed on the most recent version of naga, but that is using the updated WGSL syntax.
Once 0.13 comes out I'll port the WGSL code to the new syntax and this example should be working.
</div>
I've been putting this off for a while. Implementing a camera isn't specifically related to using WGPU properly, but it's been bugging me so let's do it.
`lib.rs` is getting a little crowded, so let's create a `camera.rs` file to put our camera code. The first things we're going to put in it are some imports and our `OPENGL_TO_WGPU_MATRIX`.

@ -98,27 +98,27 @@ To generate the terrain mesh we're going to need to pass some information into t
```wgsl
struct ChunkData {
chunk_size: vec2<u32>;
chunk_corner: vec2<i32>;
min_max_height: vec2<f32>;
};
chunk_size: vec2<u32>,
chunk_corner: vec2<i32>,
min_max_height: vec2<f32>,
}
struct Vertex {
[[location(0)]] position: vec3<f32>;
[[location(1)]] normal: vec3<f32>;
};
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
}
struct VertexBuffer {
data: [[stride(32)]] array<Vertex>;
};
data: array<Vertex>, // stride: 32
}
struct IndexBuffer {
data: array<u32>;
};
data: array<u32>,
}
[[group(0), binding(0)]] var<uniform> chunk_data: ChunkData;
[[group(0), binding(1)]] var<storage, read_write> vertices: VertexBuffer;
[[group(0), binding(2)]] var<storage, read_write> indices: IndexBuffer;
@group(0) @binding(0) var<uniform> chunk_data: ChunkData;
@group(0)@binding(1) var<storage, read_write> vertices: VertexBuffer;
@group(0)@binding(2) var<storage, read_write> indices: IndexBuffer;
```
Our shader will expect a `uniform` buffer that includes the size of the quad grid in `chunk_size`, the `chunk_corner` that our noise algorithm should start at, and `min_max_height` of the terrain.
@ -168,9 +168,9 @@ We'll cover a method called triplanar mapping to texture the terrain in a future
Now that we can get a vertex on the terrains surface we can fill our vertex and index buffers with actual data. We'll create a `gen_terrain()` function that will be the entry point for our compute shader:
```wgsl
[[stage(compute), workgroup_size(64)]]
@compute @workgroup_size(64)
fn gen_terrain(
[[builtin(global_invocation_id)]] gid: vec3<u32>
@builtin(global_invocation_id) gid: vec3<u32>
) {
// snipped...
}

@ -18,18 +18,18 @@ as uniform input. For example:
```wgsl
[[block]]
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
```
Can be simplified to just
```wgsl
struct Camera {
view_pos: vec4<f32>;
view_proj: mat4x4<f32>;
};
view_pos: vec4<f32>,
view_proj: mat4x4<f32>,
}
```
## More validation

@ -0,0 +1,52 @@
# Update to 0.13!
[WGPU Change Log](https://github.com/gfx-rs/wgpu/blob/master/CHANGELOG.md#wgpu-013-2022-06-30)
The change log above contains most of the details about what has changed about WGPU and therefore the tutorial. I will make a special mention about how to use `map_async()` as that has changed. Previously `map_async` returned a promise that you had to await before you could access a buffers contents. It now expects a `'static` callback that takes the `Result` of the mapping attempt as a parameter. This means that if we want to save a buffers context to an image instead of doing the following:
```rust
{
let buffer_slice = output_buffer.slice(..);
let mapping = buffer_slice.map_async(wgpu::MapMode::Read);
device.poll(wgpu::Maintain::Wait);
mapping.await.unwrap();
let data = buffer_slice.get_mapped_range();
use image::{ImageBuffer, Rgba};
let buffer =
ImageBuffer::<Rgba<u8>, _>::from_raw(texture_size, texture_size, data).unwrap();
buffer.save("image.png").unwrap();
}
output_buffer.unmap();
```
We would do the following:
```rust
{
let buffer_slice = output_buffer.slice(..);
let (tx, rx) = futures_intrusive::channel::shared::oneshot_channel();
buffer_slice.map_async(wgpu::MapMode::Read, move |result| {
tx.send(result).unwrap();
});
device.poll(wgpu::Maintain::Wait);
rx.receive().await.unwrap().unwrap();
let data = buffer_slice.get_mapped_range();
use image::{ImageBuffer, Rgba};
let buffer =
ImageBuffer::<Rgba<u8>, _>::from_raw(texture_size, texture_size, data).unwrap();
buffer.save("image.png").unwrap();
}
output_buffer.unmap();
```
You can explore the reasoning for the change to `map_async` in [this PR](https://github.com/gfx-rs/wgpu/pull/2698).

@ -39,7 +39,7 @@ It wasn't actually that hard of a fix. I only really use the swapchain directly
```rust
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,

@ -34,9 +34,9 @@ You can see the full table of the alignments in section [4.3.7.1 of the WGSL spe
```wgsl
struct Light {
position: vec3<f32>;
color: vec3<f32>;
};
position: vec3<f32>,
color: vec3<f32>,
}
```
So what's the alignment of this struct? Your first guess would be that it's the sum of the alignments of the individual fields. That might make sense if we were in Rust-land, but in shader-land, it's a little more involved. The alignment for a given struct is given by the following equation:

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save