diff --git a/examples/custom-shader/shaders/noise.wgsl b/examples/custom-shader/shaders/noise.wgsl index a1785f1..4ede4b4 100644 --- a/examples/custom-shader/shaders/noise.wgsl +++ b/examples/custom-shader/shaders/noise.wgsl @@ -8,10 +8,9 @@ struct VertexOutput { [[stage(vertex)]] fn vs_main( [[location(0)]] position: vec2, - [[location(1)]] tex_coord: vec2, ) -> VertexOutput { var out: VertexOutput; - out.tex_coord = tex_coord; + out.tex_coord = position * vec2(0.5, -0.5) + 0.5; out.position = vec4(position, 0.0, 1.0); return out; } diff --git a/examples/custom-shader/src/renderers.rs b/examples/custom-shader/src/renderers.rs index 753484c..58d6f40 100644 --- a/examples/custom-shader/src/renderers.rs +++ b/examples/custom-shader/src/renderers.rs @@ -37,12 +37,12 @@ impl NoiseRenderer { }); // Create vertex buffer; array-of-array of position and texture coordinates - let vertex_data: [[[f32; 2]; 2]; 3] = [ + let vertex_data: [[f32; 2]; 3] = [ // One full-screen triangle // See: https://github.com/parasyte/pixels/issues/180 - [[-1.0, -1.0], [0.0, 0.0]], - [[3.0, -1.0], [2.0, 0.0]], - [[-1.0, 3.0], [0.0, 2.0]], + [-1.0, -1.0], + [3.0, -1.0], + [-1.0, 3.0], ]; let vertex_data_slice = bytemuck::cast_slice(&vertex_data); let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -53,18 +53,11 @@ impl NoiseRenderer { let vertex_buffer_layout = wgpu::VertexBufferLayout { array_stride: (vertex_data_slice.len() / vertex_data.len()) as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ - wgpu::VertexAttribute { - format: wgpu::VertexFormat::Float32x2, - offset: 0, - shader_location: 0, - }, - wgpu::VertexAttribute { - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 2, - shader_location: 1, - }, - ], + attributes: &[wgpu::VertexAttribute { + format: wgpu::VertexFormat::Float32x2, + offset: 0, + shader_location: 0, + }], }; // Create uniform buffer diff --git a/shaders/scale.wgsl b/shaders/scale.wgsl index efb7ff1..dc7bfce 100644 --- a/shaders/scale.wgsl +++ b/shaders/scale.wgsl @@ -13,10 +13,9 @@ struct VertexOutput { [[stage(vertex)]] fn vs_main( [[location(0)]] position: vec2, - [[location(1)]] tex_coord: vec2, ) -> VertexOutput { var out: VertexOutput; - out.tex_coord = tex_coord; + out.tex_coord = position * vec2(0.5, -0.5) + 0.5; out.position = r_locals.transform * vec4(position, 0.0, 1.0); return out; } diff --git a/src/renderers.rs b/src/renderers.rs index 129fb3f..2b75545 100644 --- a/src/renderers.rs +++ b/src/renderers.rs @@ -42,12 +42,12 @@ impl ScalingRenderer { }); // Create vertex buffer; array-of-array of position and texture coordinates - let vertex_data: [[[f32; 2]; 2]; 3] = [ + let vertex_data: [[f32; 2]; 3] = [ // One full-screen triangle // See: https://github.com/parasyte/pixels/issues/180 - [[-1.0, -1.0], [0.0, 0.0]], - [[3.0, -1.0], [2.0, 0.0]], - [[-1.0, 3.0], [0.0, 2.0]], + [-1.0, -1.0], + [3.0, -1.0], + [-1.0, 3.0], ]; let vertex_data_slice = bytemuck::cast_slice(&vertex_data); let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { @@ -58,18 +58,11 @@ impl ScalingRenderer { let vertex_buffer_layout = wgpu::VertexBufferLayout { array_stride: (vertex_data_slice.len() / vertex_data.len()) as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ - wgpu::VertexAttribute { - format: wgpu::VertexFormat::Float32x2, - offset: 0, - shader_location: 0, - }, - wgpu::VertexAttribute { - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 2, - shader_location: 1, - }, - ], + attributes: &[wgpu::VertexAttribute { + format: wgpu::VertexFormat::Float32x2, + offset: 0, + shader_location: 0, + }], }; // Create uniform buffer @@ -255,9 +248,9 @@ impl ScalingMatrix { #[rustfmt::skip] let transform: [f32; 16] = [ sw, 0.0, 0.0, 0.0, - 0.0, -sh, 0.0, 0.0, + 0.0, sh, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - tx, ty, 0.0, 1.0, + tx, ty, 0.0, 1.0, ]; // Create a clipping rectangle