[WGPU] Migrate to 0.13
This commit is contained in:
parent
131123842c
commit
af551ebc2a
7 changed files with 98 additions and 77 deletions
|
@ -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>;
|
||||
};
|
||||
@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)]]
|
||||
@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);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ pub 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)),
|
||||
|
@ -19,14 +19,14 @@ pub 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,
|
||||
|
|
|
@ -289,7 +289,7 @@ impl super::State for DefaultState {
|
|||
) -> Result<(), wgpu::SurfaceError> {
|
||||
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 {
|
||||
|
@ -301,7 +301,7 @@ impl super::State for DefaultState {
|
|||
}),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
})],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
|
||||
view: &self.depth_texture.view,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
|
|
|
@ -49,7 +49,7 @@ impl Renderer {
|
|||
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue