changed vertex_color to vertex_uv

This commit is contained in:
Piotrek
2021-04-12 20:22:18 +02:00
parent c4c9312d57
commit be288b1fd9
6 changed files with 15 additions and 16 deletions
Binary file not shown.
Binary file not shown.
+8 -9
View File
@@ -3,17 +3,15 @@ use wgpu::util::DeviceExt;
use crate::vertex::Vertex;
const VERTICES: &[Vertex] = &[
Vertex { position: [-0.0868241, 0.49240386, 0.0], color: [1.0, 0.0, 0.0] }, // A
Vertex { position: [-0.49513406, 0.06958647, 0.0], color: [0.0, 1.0, 0.0] }, // B
Vertex { position: [-0.21918549, -0.44939706, 0.0], color: [0.0, 0.0, 1.0] }, // C
Vertex { position: [0.35966998, -0.3473291, 0.0], color: [0.0, 0.5, 0.5] }, // D
Vertex { position: [0.44147372, 0.2347359, 0.0],color: [0.5, 0.5, 0.0] }, // E
Vertex { position: [-0.5, 0.5, 0.0], uv: [0.0, 1.0] },
Vertex { position: [ 0.5, 0.5, 0.0], uv: [1.0, 1.0] },
Vertex { position: [ 0.5,-0.5, 0.0], uv: [1.0, 0.0] },
Vertex { position: [-0.5,-0.5, 0.0], uv: [0.0, 0.0] },
];
const INDICES: &[u16] = &[
0, 1, 4,
1, 2, 4,
2, 3, 4,
0, 1, 3,
3, 1, 2
];
pub struct App {
@@ -91,7 +89,7 @@ impl App {
let prim_state = wgpu::PrimitiveState { // primitive
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::Back,
polygon_mode: wgpu::PolygonMode::Fill,
};
@@ -131,6 +129,7 @@ impl App {
);
// Save values in app
println!("Initialized");
Self { surface, device, queue, swapchain_desc, swapchain, pipeline, vertex_buffer, index_buffer }
}
+2 -2
View File
@@ -1,10 +1,10 @@
// shader.frag
#version 450
layout(location=0) in vec3 vert_color;
layout(location=0) in vec2 vert_uv;
layout(location=0) out vec4 frag_color;
void main()
{
frag_color = vec4(vert_color, 1.0);
frag_color = vec4(vert_uv, 0.0, 1.0);
}
+3 -3
View File
@@ -1,12 +1,12 @@
#version 450
layout(location=0) in vec3 in_position;
layout(location=1) in vec3 in_color;
layout(location=0) out vec3 vert_color;
layout(location=1) in vec2 in_uv;
layout(location=0) out vec2 vert_uv;
void main()
{
vert_color = in_color;
vert_uv = in_uv;
gl_Position = vec4(in_position, 1.0);
}
+2 -2
View File
@@ -4,7 +4,7 @@
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub struct Vertex {
pub position: [f32; 3],
pub color: [f32; 3],
pub uv: [f32; 2],
}
impl Vertex {
@@ -23,7 +23,7 @@ impl Vertex {
wgpu::VertexAttribute {
offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float2,
}
]
}