convert gpu map format from buffer to texture2d

This commit is contained in:
Sven Balzer
2026-05-01 19:55:39 +02:00
parent fa9190b0e5
commit 8bc6f68b3b
2 changed files with 178 additions and 127 deletions
+12 -15
View File
@@ -1,11 +1,6 @@
struct VertexShaderInput {
// Per Vertex
@builtin(vertex_index) vertex_index: u32,
// Per Instance
@builtin(vertex_index) vertex_index: u32,
@builtin(instance_index) instance_index: u32,
@location(0) tile: u32,
};
struct VertexShaderOutput {
@@ -30,22 +25,24 @@ struct Per_Frame_Data {
@group(0) @binding(0) var<uniform> view_projection_matrix: mat4x4<f32>;
@group(0) @binding(1) var<uniform> per_frame: Per_Frame_Data;
@group(2) @binding(0) var map_texture: texture_2d<u32>;
@vertex fn main_vertex(input: VertexShaderInput) -> 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<u32>(input.instance_index % per_frame.map_width, input.instance_index / per_frame.map_width);
output.tile = textureLoad(map_texture, tile_pos, 0).r;
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); }
case 0: { output.pos = vec4<f32>(vec2<f32>(tile_pos) - vec2<f32>(0.5, 0.5) + vec2<f32>(-0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(0, 0); }
case 1: { output.pos = vec4<f32>(vec2<f32>(tile_pos) - vec2<f32>(0.5, 0.5) + vec2<f32>(-0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(0, 1); }
case 2: { output.pos = vec4<f32>(vec2<f32>(tile_pos) - vec2<f32>(0.5, 0.5) + vec2<f32>( 0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(1, 1); }
case 3: { output.pos = vec4<f32>(vec2<f32>(tile_pos) - vec2<f32>(0.5, 0.5) + vec2<f32>(-0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(0, 0); }
case 4: { output.pos = vec4<f32>(vec2<f32>(tile_pos) - vec2<f32>(0.5, 0.5) + vec2<f32>( 0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(1, 1); }
case 5: { output.pos = vec4<f32>(vec2<f32>(tile_pos) - vec2<f32>(0.5, 0.5) + vec2<f32>( 0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2<f32>(1, 0); }
default: {}
}
output.tile = input.tile;
return output;
}