remove vertex and index buffer from world shader
This commit is contained in:
parent
7cb6dbc3e6
commit
fa9190b0e5
33
src/main.cpp
33
src/main.cpp
@ -1037,34 +1037,15 @@ static bool recreate_graphics_pipelines() {
|
|||||||
|
|
||||||
WGPUShaderModule world_shader = wgpuDeviceCreateShaderModule(device, &world_shader_descriptor);
|
WGPUShaderModule world_shader = wgpuDeviceCreateShaderModule(device, &world_shader_descriptor);
|
||||||
|
|
||||||
WGPUVertexAttribute vertex_buffer_attributes[] = {
|
|
||||||
{
|
|
||||||
.format = WGPUVertexFormat_Float32x3,
|
|
||||||
.offset = offsetof(Vertex, pos),
|
|
||||||
.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 = 2,
|
.shaderLocation = 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
WGPUVertexBufferLayout vertex_buffer_layouts[] = {
|
WGPUVertexBufferLayout vertex_buffer_layouts[] = {
|
||||||
{
|
|
||||||
.stepMode = WGPUVertexStepMode_Vertex,
|
|
||||||
.arrayStride = sizeof(Vertex),
|
|
||||||
.attributeCount = SDL_arraysize(vertex_buffer_attributes),
|
|
||||||
.attributes = vertex_buffer_attributes,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.stepMode = WGPUVertexStepMode_Instance,
|
.stepMode = WGPUVertexStepMode_Instance,
|
||||||
.arrayStride = sizeof(Uint32),
|
.arrayStride = sizeof(Uint32),
|
||||||
@ -2111,11 +2092,9 @@ static void render_editor(WGPURenderPassColorAttachment framebuffer) {
|
|||||||
{ // Draw Map
|
{ // Draw Map
|
||||||
ZoneScopedN("Draw Map");
|
ZoneScopedN("Draw Map");
|
||||||
wgpuRenderPassEncoderSetPipeline(render_pass_encoder, world_render_pipeline);
|
wgpuRenderPassEncoderSetPipeline(render_pass_encoder, world_render_pipeline);
|
||||||
wgpuRenderPassEncoderSetIndexBuffer(render_pass_encoder, index_buffer, WGPUIndexFormat_Uint16, 0, WGPU_WHOLE_SIZE);
|
wgpuRenderPassEncoderSetVertexBuffer(render_pass_encoder, 0, current_map.gpu_buffer, 0, WGPU_WHOLE_SIZE);
|
||||||
wgpuRenderPassEncoderSetVertexBuffer(render_pass_encoder, 0, vertex_buffer, 0, WGPU_WHOLE_SIZE);
|
|
||||||
wgpuRenderPassEncoderSetVertexBuffer(render_pass_encoder, 1, current_map.gpu_buffer, 0, WGPU_WHOLE_SIZE);
|
|
||||||
wgpuRenderPassEncoderSetBindGroup(render_pass_encoder, 1, world_bind_group, 0, NULL);
|
wgpuRenderPassEncoderSetBindGroup(render_pass_encoder, 1, world_bind_group, 0, NULL);
|
||||||
wgpuRenderPassEncoderDrawIndexed(render_pass_encoder, 6, current_map.size.y * current_map.size.x, 0, 0, 0);
|
wgpuRenderPassEncoderDraw(render_pass_encoder, 6, current_map.size.y * current_map.size.x, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_grid) { // Draw Grid
|
if (show_grid) { // Draw Grid
|
||||||
@ -2280,11 +2259,9 @@ static void render_game(WGPURenderPassColorAttachment framebuffer) {
|
|||||||
{ // Draw Map
|
{ // Draw Map
|
||||||
ZoneScopedN("Draw Map");
|
ZoneScopedN("Draw Map");
|
||||||
wgpuRenderPassEncoderSetPipeline(render_pass_encoder, world_render_pipeline);
|
wgpuRenderPassEncoderSetPipeline(render_pass_encoder, world_render_pipeline);
|
||||||
wgpuRenderPassEncoderSetIndexBuffer(render_pass_encoder, index_buffer, WGPUIndexFormat_Uint16, 0, WGPU_WHOLE_SIZE);
|
wgpuRenderPassEncoderSetVertexBuffer(render_pass_encoder, 0, current_map.gpu_buffer, 0, WGPU_WHOLE_SIZE);
|
||||||
wgpuRenderPassEncoderSetVertexBuffer(render_pass_encoder, 0, vertex_buffer, 0, WGPU_WHOLE_SIZE);
|
|
||||||
wgpuRenderPassEncoderSetVertexBuffer(render_pass_encoder, 1, current_map.gpu_buffer, 0, WGPU_WHOLE_SIZE);
|
|
||||||
wgpuRenderPassEncoderSetBindGroup(render_pass_encoder, 1, world_bind_group, 0, NULL);
|
wgpuRenderPassEncoderSetBindGroup(render_pass_encoder, 1, world_bind_group, 0, NULL);
|
||||||
wgpuRenderPassEncoderDrawIndexed(render_pass_encoder, 6, current_map.size.y * current_map.size.x, 0, 0, 0);
|
wgpuRenderPassEncoderDraw(render_pass_encoder, 6, current_map.size.y * current_map.size.x, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Draw Player
|
{ // Draw Player
|
||||||
|
|||||||
@ -2,13 +2,10 @@ struct VertexShaderInput {
|
|||||||
// Per Vertex
|
// Per Vertex
|
||||||
@builtin(vertex_index) vertex_index: u32,
|
@builtin(vertex_index) vertex_index: u32,
|
||||||
|
|
||||||
@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(2) tile: u32,
|
@location(0) tile: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexShaderOutput {
|
struct VertexShaderOutput {
|
||||||
@ -37,10 +34,17 @@ struct Per_Frame_Data {
|
|||||||
var output: VertexShaderOutput;
|
var output: VertexShaderOutput;
|
||||||
|
|
||||||
let tile_pos = vec2<f32>(f32(input.instance_index % per_frame.map_width), f32(input.instance_index / per_frame.map_width)) - vec2<f32>(0.5, 0.5);
|
let tile_pos = vec2<f32>(f32(input.instance_index % per_frame.map_width), f32(input.instance_index / per_frame.map_width)) - vec2<f32>(0.5, 0.5);
|
||||||
|
switch (input.vertex_index) {
|
||||||
|
case 0: { output.pos = vec4<f32>(tile_pos + vec2<f32>(-0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(0, 0); }
|
||||||
|
case 1: { output.pos = vec4<f32>(tile_pos + vec2<f32>(-0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(0, 1); }
|
||||||
|
case 2: { output.pos = vec4<f32>(tile_pos + vec2<f32>( 0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(1, 1); }
|
||||||
|
case 3: { output.pos = vec4<f32>(tile_pos + vec2<f32>(-0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(0, 0); }
|
||||||
|
case 4: { output.pos = vec4<f32>(tile_pos + vec2<f32>( 0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(1, 1); }
|
||||||
|
case 5: { output.pos = vec4<f32>(tile_pos + vec2<f32>( 0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(1, 0); }
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
|
||||||
output.tile = input.tile;
|
output.tile = input.tile;
|
||||||
output.pos = vec4<f32>(tile_pos + input.pos.xy, 0, 1) * view_projection_matrix;
|
|
||||||
output.uv = input.uv;
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user