add uv to vertex format and remove it from instance
This commit is contained in:
parent
8633cff3cb
commit
dcd40b6394
28
src/main.cpp
28
src/main.cpp
@ -109,13 +109,14 @@ enum Settings_Category {
|
|||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
V3 pos;
|
V3 pos;
|
||||||
|
V2 uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Vertex vertices[] = {
|
static Vertex vertices[] = {
|
||||||
{{ -0.5f, 0.5f }},
|
{{ -0.5f, 0.5f }, { 0.0f, 0.0f }},
|
||||||
{{ -0.5f, -0.5f }},
|
{{ -0.5f, -0.5f }, { 0.0f, 1.0f }},
|
||||||
{{ 0.5f, -0.5f }},
|
{{ 0.5f, -0.5f }, { 1.0f, 1.0f }},
|
||||||
{{ 0.5f, 0.5f }},
|
{{ 0.5f, 0.5f }, { 1.0f, 0.0f }},
|
||||||
};
|
};
|
||||||
|
|
||||||
static Uint16 indices[] = {
|
static Uint16 indices[] = {
|
||||||
@ -170,11 +171,9 @@ static Uint16 grid_indices[] = {
|
|||||||
|
|
||||||
struct Instance {
|
struct Instance {
|
||||||
V2 pos;
|
V2 pos;
|
||||||
V4 uv0uv1;
|
|
||||||
V4 uv2uv3;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static Instance player_instance = { { 0.0f, 0.0f }, { 0, 0, 1, 0 }, { 1, 1, 0, 1 }};
|
static Instance player_instance = {{ 0.0f, 0.0f }};
|
||||||
|
|
||||||
struct Map {
|
struct Map {
|
||||||
Sint32 width;
|
Sint32 width;
|
||||||
@ -745,24 +744,19 @@ static bool recreate_graphics_pipelines() {
|
|||||||
.offset = offsetof(Vertex, pos),
|
.offset = offsetof(Vertex, pos),
|
||||||
.shaderLocation = 0,
|
.shaderLocation = 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.format = WGPUVertexFormat_Float32x2,
|
||||||
|
.offset = offsetof(Vertex, uv),
|
||||||
|
.shaderLocation = 1,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
WGPUVertexAttribute instance_buffer_attributes[] = {
|
WGPUVertexAttribute instance_buffer_attributes[] = {
|
||||||
{
|
{
|
||||||
.format = WGPUVertexFormat_Float32x2,
|
.format = WGPUVertexFormat_Float32x2,
|
||||||
.offset = offsetof(Instance, pos),
|
.offset = offsetof(Instance, pos),
|
||||||
.shaderLocation = 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.format = WGPUVertexFormat_Float32x4,
|
|
||||||
.offset = offsetof(Instance, uv0uv1),
|
|
||||||
.shaderLocation = 2,
|
.shaderLocation = 2,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.format = WGPUVertexFormat_Float32x4,
|
|
||||||
.offset = offsetof(Instance, uv2uv3),
|
|
||||||
.shaderLocation = 3,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WGPUVertexBufferLayout vertex_buffer_layouts[] = {
|
WGPUVertexBufferLayout vertex_buffer_layouts[] = {
|
||||||
|
|||||||
@ -3,11 +3,10 @@ struct VertexShaderInput {
|
|||||||
@builtin(vertex_index) vertex_index: u32,
|
@builtin(vertex_index) vertex_index: u32,
|
||||||
|
|
||||||
@location(0) pos: vec3<f32>,
|
@location(0) pos: vec3<f32>,
|
||||||
|
@location(1) uv: vec2<f32>,
|
||||||
|
|
||||||
// Per Instance
|
// Per Instance
|
||||||
@location(1) pos_size: vec4<f32>,
|
@location(2) pos_size: vec4<f32>,
|
||||||
@location(2) uv0uv1: vec4<f32>,
|
|
||||||
@location(3) uv2uv3: vec4<f32>,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexShaderOutput {
|
struct VertexShaderOutput {
|
||||||
@ -26,14 +25,7 @@ struct FragmentShaderOutput {
|
|||||||
var output: VertexShaderOutput;
|
var output: VertexShaderOutput;
|
||||||
|
|
||||||
output.pos = vec4<f32>(input.pos_size.xy + input.pos.xy, 0, 1) * view_projection_matrix;
|
output.pos = vec4<f32>(input.pos_size.xy + input.pos.xy, 0, 1) * view_projection_matrix;
|
||||||
|
output.uv = input.uv;
|
||||||
switch (input.vertex_index) {
|
|
||||||
case 0: { output.uv = input.uv0uv1.xy; }
|
|
||||||
case 1: { output.uv = input.uv2uv3.zw; }
|
|
||||||
case 2: { output.uv = input.uv2uv3.xy; }
|
|
||||||
case 3: { output.uv = input.uv0uv1.zw; }
|
|
||||||
default: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user