From 18c1b3639ceeaea5a0ceaaf544053019397d877a Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Fri, 3 Jul 2026 14:23:55 +0200 Subject: [PATCH] remove old shaders --- CMakeLists.txt | 2 -- src/main.cpp | 2 -- src/shaders/basic.wgsl | 54 ------------------------------ src/shaders/grid.wgsl | 55 ------------------------------ src/shaders/shaders.c | 19 ----------- src/shaders/shaders.h | 7 ---- src/shaders/world.wgsl | 76 ------------------------------------------ 7 files changed, 215 deletions(-) delete mode 100644 src/shaders/basic.wgsl delete mode 100644 src/shaders/grid.wgsl delete mode 100644 src/shaders/shaders.c delete mode 100644 src/shaders/shaders.h delete mode 100644 src/shaders/world.wgsl diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d6b11c..fb356de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,6 @@ add_subdirectory(libs/tracy) add_executable(mikemon src/smol-atlas.cpp src/change_directory.c - src/shaders/shaders.c src/renderer_wgpu.c src/main.cpp ) @@ -111,7 +110,6 @@ target_link_libraries(mikemon add_executable(mikemon-sdlgpu src/smol-atlas.cpp src/change_directory.c - src/shaders/shaders.c src/renderer_sdlgpu.c src/main.cpp ) diff --git a/src/main.cpp b/src/main.cpp index dfd55c1..11efab6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,6 @@ #include "stb_image.h" #include "change_directory.h" -#include "shaders/shaders.h" - #pragma clang diagnostic ignored "-Waddress-of-temporary" using namespace glm; diff --git a/src/shaders/basic.wgsl b/src/shaders/basic.wgsl deleted file mode 100644 index 376157e..0000000 --- a/src/shaders/basic.wgsl +++ /dev/null @@ -1,54 +0,0 @@ -struct VertexShaderInput { - // Per Vertex - @builtin(vertex_index) vertex_index: u32, - - @location(0) pos: vec3, - @location(1) uv: vec2, - - // Per Instance - @location(2) pos_size: vec4, -}; - -struct VertexShaderOutput { - @builtin(position) pos: vec4, - - @location(0) uv: vec2, -}; - -struct FragmentShaderOutput { - @location(0) color: vec4, -}; - -@group(0) @binding(0) var view_projection_matrix: mat4x4; - -@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput { - var output: VertexShaderOutput; - - output.pos = vec4(input.pos_size.xy + input.pos.xy, 0, 1) * view_projection_matrix; - output.uv = input.uv; - - return output; -} - -@group(1) @binding(0) var texture1: texture_2d; -@group(1) @binding(1) var sampler1: sampler; - -@group(1) @binding(2) var tint: vec3; - -@fragment fn main_fragment(input: VertexShaderOutput) -> FragmentShaderOutput { - var output: FragmentShaderOutput; - - output.color = pixel_art_sample(texture1, sampler1, input.uv); - output.color = vec4(output.color.rgb * tint.rgb, output.color.a); - - return output; -} - -fn pixel_art_sample(input_texture: texture_2d, input_sampler: sampler, input_uv: vec2) -> vec4 { - let dimensions = vec2(textureDimensions(input_texture)); - - let texture_uv = input_uv * dimensions.xy; - let sample_uv = (floor(texture_uv) + min(fract(texture_uv) / fwidth(texture_uv), vec2(1.0, 1.0)) - 0.5) / dimensions.xy; - - return textureSample(input_texture, input_sampler, sample_uv); -} diff --git a/src/shaders/grid.wgsl b/src/shaders/grid.wgsl deleted file mode 100644 index 85c75e7..0000000 --- a/src/shaders/grid.wgsl +++ /dev/null @@ -1,55 +0,0 @@ -struct VertexShaderInput { - // Per Vertex - @builtin(vertex_index) vertex_index: u32, - - @location(0) pos: vec3, - - // Per Instance - @builtin(instance_index) instance_index: u32, -}; - -struct VertexShaderOutput { - @builtin(position) pos: vec4, - - @location(1) selected: i32, -}; - -struct FragmentShaderOutput { - @location(0) color: vec4, -}; - -struct Per_Frame_Data { - drag_start: vec2, - mouse: vec2, - grid_offset: vec2, - grid_width: u32, - map_width: u32, -}; - -@group(0) @binding(0) var view_projection_matrix: mat4x4; -@group(0) @binding(1) var per_frame: Per_Frame_Data; - -@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput { - var output: VertexShaderOutput; - - let tile_pos = vec2(f32(input.instance_index % per_frame.grid_width), f32(input.instance_index / per_frame.grid_width)); - output.pos = vec4(tile_pos + per_frame.grid_offset + input.pos.xy, 0, 1) * view_projection_matrix; - - let pos = vec2(tile_pos + round(per_frame.grid_offset)); - let selection_min = min(per_frame.drag_start, per_frame.mouse); - let selection_max = max(per_frame.drag_start, per_frame.mouse); - output.selected = select(1, 0, all(pos >= selection_min) && all(pos <= selection_max)); - - return output; -} - -const tint = vec4(1.0, 1.0, 1.0, 0.1); -const selected_tint = vec4(1.0, 0.0, 1.0, 1.0); - -@fragment fn main_fragment(input: VertexShaderOutput) -> FragmentShaderOutput { - var output: FragmentShaderOutput; - - output.color = select(selected_tint, tint, input.selected != 0); - - return output; -} diff --git a/src/shaders/shaders.c b/src/shaders/shaders.c deleted file mode 100644 index a1a289d..0000000 --- a/src/shaders/shaders.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -static const char _WGSL_basic[] = { - #embed "basic.wgsl" -}; -const char *WGSL_basic = _WGSL_basic; -size_t WGSL_basic_num_bytes = sizeof(_WGSL_basic); - -static const char _WGSL_world[] = { - #embed "world.wgsl" -}; -const char *WGSL_world = _WGSL_world; -size_t WGSL_world_num_bytes = sizeof(_WGSL_world); - -static const char _WGSL_grid[] = { - #embed "grid.wgsl" -}; -const char *WGSL_grid = _WGSL_grid; -size_t WGSL_grid_num_bytes = sizeof(_WGSL_grid); diff --git a/src/shaders/shaders.h b/src/shaders/shaders.h deleted file mode 100644 index 446bc72..0000000 --- a/src/shaders/shaders.h +++ /dev/null @@ -1,7 +0,0 @@ -#include - -#define SHADER(name) extern "C" size_t WGSL_##name##_num_bytes; extern "C" const char *WGSL_##name; -SHADER(basic) -SHADER(world) -SHADER(grid) -#undef SHADER diff --git a/src/shaders/world.wgsl b/src/shaders/world.wgsl deleted file mode 100644 index 56176f5..0000000 --- a/src/shaders/world.wgsl +++ /dev/null @@ -1,76 +0,0 @@ -struct VertexShaderInput { - @builtin(vertex_index) vertex_index: u32, - @builtin(instance_index) instance_index: u32, -}; - -struct VertexShaderOutput { - @builtin(position) pos: vec4, - - @location(0) uv: vec2, - @location(1) tile: u32, -}; - -struct FragmentShaderOutput { - @location(0) color: vec4, -}; - -struct Per_Frame_Data { - drag_start: vec2, - mouse: vec2, - grid_offset: vec2, - grid_width: u32, - map_width: u32, -}; - -@group(0) @binding(0) var view_projection_matrix: mat4x4; -@group(0) @binding(1) var per_frame: Per_Frame_Data; - -@group(2) @binding(0) var map_texture: texture_2d; - -@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput { - var output: VertexShaderOutput; - - let tile_pos = vec2(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(vec2(tile_pos) - vec2(0.5, 0.5) + vec2(-0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2(0, 0); } - case 1: { output.pos = vec4(vec2(tile_pos) - vec2(0.5, 0.5) + vec2(-0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2(0, 1); } - case 2: { output.pos = vec4(vec2(tile_pos) - vec2(0.5, 0.5) + vec2( 0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2(1, 1); } - case 3: { output.pos = vec4(vec2(tile_pos) - vec2(0.5, 0.5) + vec2(-0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2(0, 0); } - case 4: { output.pos = vec4(vec2(tile_pos) - vec2(0.5, 0.5) + vec2( 0.5, -0.5), 0, 1) * view_projection_matrix; output.uv = vec2(1, 1); } - case 5: { output.pos = vec4(vec2(tile_pos) - vec2(0.5, 0.5) + vec2( 0.5, 0.5), 0, 1) * view_projection_matrix; output.uv = vec2(1, 0); } - default: {} - } - - return output; -} - -@group(1) @binding(0) var texture1: texture_2d; -@group(1) @binding(1) var sampler1: sampler; - -@group(1) @binding(2) var tint: vec3; - -@group(1) @binding(3) var tile_uvs: array>; - -@fragment fn main_fragment(input: VertexShaderOutput) -> FragmentShaderOutput { - var output: FragmentShaderOutput; - - output.color = pixel_art_sample(texture1, sampler1, input.uv, input.tile); - output.color = vec4(output.color.rgb * tint.rgb, output.color.a); - - return output; -} - -fn pixel_art_sample(input_texture: texture_2d, input_sampler: sampler, input_uv: vec2, tile: u32) -> vec4 { - let dimensions = vec2(textureDimensions(input_texture)); - - let tile_uv = tile_uvs[tile]; - - let texture_uv = mix(tile_uv.xy, tile_uv.zw, input_uv); - let sample_uv = (floor(texture_uv) + saturate(fract(texture_uv) / fwidth(texture_uv)) - 0.5) / dimensions; - - let uv = clamp(sample_uv, (tile_uv.xy + 0.5) / dimensions, (tile_uv.zw - 0.5) / dimensions); - - return textureSample(input_texture, input_sampler, uv); -}