get rid of tile_infos buffer for world shader and instead just use the vertex uvs
This commit is contained in:
parent
dcd40b6394
commit
434abdc9a7
28
src/main.cpp
28
src/main.cpp
@ -249,8 +249,6 @@ static TileInfo tile_infos[] = {
|
|||||||
{ 0x0423, "tiles/grass_ground_two_corner.png", TILE_CORNER_INFO(TILEKIND_GRASS, TILEKIND_GROUND, TILEKIND_GRASS, TILEKIND_GROUND ) },
|
{ 0x0423, "tiles/grass_ground_two_corner.png", TILE_CORNER_INFO(TILEKIND_GRASS, TILEKIND_GROUND, TILEKIND_GRASS, TILEKIND_GROUND ) },
|
||||||
};
|
};
|
||||||
|
|
||||||
static V4 cpu_tile_infos_buffer[SDL_arraysize(tile_infos)];
|
|
||||||
|
|
||||||
static Sint32 selected_tile_kind = -1;
|
static Sint32 selected_tile_kind = -1;
|
||||||
|
|
||||||
static Sint32 selected_tile = -1;
|
static Sint32 selected_tile = -1;
|
||||||
@ -851,16 +849,6 @@ static bool recreate_graphics_pipelines() {
|
|||||||
.minBindingSize = 0,
|
.minBindingSize = 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.binding = 3,
|
|
||||||
.visibility = WGPUShaderStage_Vertex,
|
|
||||||
|
|
||||||
.buffer = {
|
|
||||||
.type = WGPUBufferBindingType_ReadOnlyStorage,
|
|
||||||
.hasDynamicOffset = false,
|
|
||||||
.minBindingSize = 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WGPUBindGroupLayoutDescriptor world_bind_group_layout_descriptor = {
|
WGPUBindGroupLayoutDescriptor world_bind_group_layout_descriptor = {
|
||||||
@ -902,13 +890,18 @@ 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_Uint32,
|
.format = WGPUVertexFormat_Uint32,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
.shaderLocation = 1,
|
.shaderLocation = 2,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1121,8 +1114,6 @@ static bool recreate_tile_textures() {
|
|||||||
SDL_assert_always(width == TILE_SIZE);
|
SDL_assert_always(width == TILE_SIZE);
|
||||||
SDL_assert_always(height == TILE_SIZE);
|
SDL_assert_always(height == TILE_SIZE);
|
||||||
|
|
||||||
cpu_tile_infos_buffer[i] = V4_(0, 0, 1, 1);
|
|
||||||
|
|
||||||
WGPUTexelCopyTextureInfo texel_copy_texture_info = {
|
WGPUTexelCopyTextureInfo texel_copy_texture_info = {
|
||||||
.texture = tile_textures_array,
|
.texture = tile_textures_array,
|
||||||
.mipLevel = 0,
|
.mipLevel = 0,
|
||||||
@ -1516,12 +1507,6 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tile_infos_buffer = create_buffer(WGPUBufferUsage_Storage, SDL_arraysize(cpu_tile_infos_buffer) * sizeof(*cpu_tile_infos_buffer), cpu_tile_infos_buffer, "tile_infos_buffer");
|
|
||||||
if (!tile_infos_buffer) {
|
|
||||||
log_error("Failed to create buffer. Exiting.");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
WGPUBindGroupEntry per_frame_bind_group_entries[] = {
|
WGPUBindGroupEntry per_frame_bind_group_entries[] = {
|
||||||
{ .binding = 0, .buffer = view_projection_matrix_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
{ .binding = 0, .buffer = view_projection_matrix_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
||||||
{ .binding = 1, .buffer = per_frame_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
{ .binding = 1, .buffer = per_frame_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
||||||
@ -1539,7 +1524,6 @@ int main(int argc, char **argv) {
|
|||||||
{ .binding = 0, .textureView = tile_textures_array_view },
|
{ .binding = 0, .textureView = tile_textures_array_view },
|
||||||
{ .binding = 1, .sampler = pixel_sampler },
|
{ .binding = 1, .sampler = pixel_sampler },
|
||||||
{ .binding = 2, .buffer = tint_color_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
{ .binding = 2, .buffer = tint_color_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
||||||
{ .binding = 3, .buffer = tile_infos_buffer, .offset = 0, .size = WGPU_WHOLE_SIZE },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WGPUBindGroupDescriptor world_bind_group_descriptor = {
|
WGPUBindGroupDescriptor world_bind_group_descriptor = {
|
||||||
|
|||||||
@ -3,11 +3,12 @@ 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
|
||||||
@builtin(instance_index) instance_index: u32,
|
@builtin(instance_index) instance_index: u32,
|
||||||
|
|
||||||
@location(1) tile_info: u32,
|
@location(2) tile_info: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexShaderOutput {
|
struct VertexShaderOutput {
|
||||||
@ -32,8 +33,6 @@ struct Per_Frame_Data {
|
|||||||
@group(0) @binding(0) var<uniform> view_projection_matrix: mat4x4<f32>;
|
@group(0) @binding(0) var<uniform> view_projection_matrix: mat4x4<f32>;
|
||||||
@group(0) @binding(1) var<uniform> per_frame: Per_Frame_Data;
|
@group(0) @binding(1) var<uniform> per_frame: Per_Frame_Data;
|
||||||
|
|
||||||
@group(1) @binding(3) var<storage, read> tile_infos: array<vec4<f32>>;
|
|
||||||
|
|
||||||
@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput {
|
@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput {
|
||||||
var output: VertexShaderOutput;
|
var output: VertexShaderOutput;
|
||||||
|
|
||||||
@ -45,49 +44,11 @@ struct Per_Frame_Data {
|
|||||||
output.tile = tile_type;
|
output.tile = tile_type;
|
||||||
output.pos = vec4<f32>(tile_pos + input.pos.xy, 0, 1) * view_projection_matrix;
|
output.pos = vec4<f32>(tile_pos + input.pos.xy, 0, 1) * view_projection_matrix;
|
||||||
|
|
||||||
let uv_min_max = tile_infos[tile_type];
|
|
||||||
|
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case 0: {
|
case 0: { output.uv = vec2<f32>( input.uv.x, input.uv.y); }
|
||||||
switch (input.vertex_index) {
|
case 1: { output.uv = vec2<f32>(1.0 - input.uv.y, input.uv.x); }
|
||||||
case 0: { output.uv = uv_min_max.xy; }
|
case 2: { output.uv = vec2<f32>(1.0 - input.uv.x, 1.0 - input.uv.y); }
|
||||||
case 1: { output.uv = uv_min_max.xw; }
|
case 3: { output.uv = vec2<f32>( input.uv.y, 1.0 - input.uv.x); }
|
||||||
case 2: { output.uv = uv_min_max.zw; }
|
|
||||||
case 3: { output.uv = uv_min_max.zy; }
|
|
||||||
default: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case 1: {
|
|
||||||
switch (input.vertex_index) {
|
|
||||||
case 0: { output.uv = uv_min_max.zy; }
|
|
||||||
case 1: { output.uv = uv_min_max.xy; }
|
|
||||||
case 2: { output.uv = uv_min_max.xw; }
|
|
||||||
case 3: { output.uv = uv_min_max.zw; }
|
|
||||||
default: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2: {
|
|
||||||
switch (input.vertex_index) {
|
|
||||||
case 0: { output.uv = uv_min_max.zw; }
|
|
||||||
case 1: { output.uv = uv_min_max.zy; }
|
|
||||||
case 2: { output.uv = uv_min_max.xy; }
|
|
||||||
case 3: { output.uv = uv_min_max.xw; }
|
|
||||||
default: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3: {
|
|
||||||
switch (input.vertex_index) {
|
|
||||||
case 0: { output.uv = uv_min_max.xw; }
|
|
||||||
case 1: { output.uv = uv_min_max.zw; }
|
|
||||||
case 2: { output.uv = uv_min_max.zy; }
|
|
||||||
case 3: { output.uv = uv_min_max.xy; }
|
|
||||||
default: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {}
|
default: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user