remove old shaders
This commit is contained in:
@@ -92,7 +92,6 @@ add_subdirectory(libs/tracy)
|
|||||||
add_executable(mikemon
|
add_executable(mikemon
|
||||||
src/smol-atlas.cpp
|
src/smol-atlas.cpp
|
||||||
src/change_directory.c
|
src/change_directory.c
|
||||||
src/shaders/shaders.c
|
|
||||||
src/renderer_wgpu.c
|
src/renderer_wgpu.c
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
@@ -111,7 +110,6 @@ target_link_libraries(mikemon
|
|||||||
add_executable(mikemon-sdlgpu
|
add_executable(mikemon-sdlgpu
|
||||||
src/smol-atlas.cpp
|
src/smol-atlas.cpp
|
||||||
src/change_directory.c
|
src/change_directory.c
|
||||||
src/shaders/shaders.c
|
|
||||||
src/renderer_sdlgpu.c
|
src/renderer_sdlgpu.c
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
#include "change_directory.h"
|
#include "change_directory.h"
|
||||||
|
|
||||||
#include "shaders/shaders.h"
|
|
||||||
|
|
||||||
#pragma clang diagnostic ignored "-Waddress-of-temporary"
|
#pragma clang diagnostic ignored "-Waddress-of-temporary"
|
||||||
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
struct VertexShaderInput {
|
|
||||||
// Per Vertex
|
|
||||||
@builtin(vertex_index) vertex_index: u32,
|
|
||||||
|
|
||||||
@location(0) pos: vec3<f32>,
|
|
||||||
@location(1) uv: vec2<f32>,
|
|
||||||
|
|
||||||
// Per Instance
|
|
||||||
@location(2) pos_size: vec4<f32>,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexShaderOutput {
|
|
||||||
@builtin(position) pos: vec4<f32>,
|
|
||||||
|
|
||||||
@location(0) uv: vec2<f32>,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FragmentShaderOutput {
|
|
||||||
@location(0) color: vec4<f32>,
|
|
||||||
};
|
|
||||||
|
|
||||||
@group(0) @binding(0) var<uniform> view_projection_matrix: mat4x4<f32>;
|
|
||||||
|
|
||||||
@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput {
|
|
||||||
var output: VertexShaderOutput;
|
|
||||||
|
|
||||||
output.pos = vec4<f32>(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<f32>;
|
|
||||||
@group(1) @binding(1) var sampler1: sampler;
|
|
||||||
|
|
||||||
@group(1) @binding(2) var<uniform> tint: vec3<f32>;
|
|
||||||
|
|
||||||
@fragment fn main_fragment(input: VertexShaderOutput) -> FragmentShaderOutput {
|
|
||||||
var output: FragmentShaderOutput;
|
|
||||||
|
|
||||||
output.color = pixel_art_sample(texture1, sampler1, input.uv);
|
|
||||||
output.color = vec4<f32>(output.color.rgb * tint.rgb, output.color.a);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pixel_art_sample(input_texture: texture_2d<f32>, input_sampler: sampler, input_uv: vec2<f32>) -> vec4<f32> {
|
|
||||||
let dimensions = vec2<f32>(textureDimensions(input_texture));
|
|
||||||
|
|
||||||
let texture_uv = input_uv * dimensions.xy;
|
|
||||||
let sample_uv = (floor(texture_uv) + min(fract(texture_uv) / fwidth(texture_uv), vec2<f32>(1.0, 1.0)) - 0.5) / dimensions.xy;
|
|
||||||
|
|
||||||
return textureSample(input_texture, input_sampler, sample_uv);
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
struct VertexShaderInput {
|
|
||||||
// Per Vertex
|
|
||||||
@builtin(vertex_index) vertex_index: u32,
|
|
||||||
|
|
||||||
@location(0) pos: vec3<f32>,
|
|
||||||
|
|
||||||
// Per Instance
|
|
||||||
@builtin(instance_index) instance_index: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexShaderOutput {
|
|
||||||
@builtin(position) pos: vec4<f32>,
|
|
||||||
|
|
||||||
@location(1) selected: i32,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FragmentShaderOutput {
|
|
||||||
@location(0) color: vec4<f32>,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Per_Frame_Data {
|
|
||||||
drag_start: vec2<i32>,
|
|
||||||
mouse: vec2<i32>,
|
|
||||||
grid_offset: vec2<f32>,
|
|
||||||
grid_width: u32,
|
|
||||||
map_width: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
@group(0) @binding(0) var<uniform> view_projection_matrix: mat4x4<f32>;
|
|
||||||
@group(0) @binding(1) var<uniform> per_frame: Per_Frame_Data;
|
|
||||||
|
|
||||||
@vertex fn main_vertex(input: VertexShaderInput) -> VertexShaderOutput {
|
|
||||||
var output: VertexShaderOutput;
|
|
||||||
|
|
||||||
let tile_pos = vec2<f32>(f32(input.instance_index % per_frame.grid_width), f32(input.instance_index / per_frame.grid_width));
|
|
||||||
output.pos = vec4<f32>(tile_pos + per_frame.grid_offset + input.pos.xy, 0, 1) * view_projection_matrix;
|
|
||||||
|
|
||||||
let pos = vec2<i32>(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<f32>(1.0, 1.0, 1.0, 0.1);
|
|
||||||
const selected_tint = vec4<f32>(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;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#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
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
struct VertexShaderInput {
|
|
||||||
@builtin(vertex_index) vertex_index: u32,
|
|
||||||
@builtin(instance_index) instance_index: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct VertexShaderOutput {
|
|
||||||
@builtin(position) pos: vec4<f32>,
|
|
||||||
|
|
||||||
@location(0) uv: vec2<f32>,
|
|
||||||
@location(1) tile: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FragmentShaderOutput {
|
|
||||||
@location(0) color: vec4<f32>,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Per_Frame_Data {
|
|
||||||
drag_start: vec2<i32>,
|
|
||||||
mouse: vec2<i32>,
|
|
||||||
grid_offset: vec2<f32>,
|
|
||||||
grid_width: u32,
|
|
||||||
map_width: u32,
|
|
||||||
};
|
|
||||||
|
|
||||||
@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<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>(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: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
@group(1) @binding(0) var texture1: texture_2d<f32>;
|
|
||||||
@group(1) @binding(1) var sampler1: sampler;
|
|
||||||
|
|
||||||
@group(1) @binding(2) var<uniform> tint: vec3<f32>;
|
|
||||||
|
|
||||||
@group(1) @binding(3) var<storage> tile_uvs: array<vec4<f32>>;
|
|
||||||
|
|
||||||
@fragment fn main_fragment(input: VertexShaderOutput) -> FragmentShaderOutput {
|
|
||||||
var output: FragmentShaderOutput;
|
|
||||||
|
|
||||||
output.color = pixel_art_sample(texture1, sampler1, input.uv, input.tile);
|
|
||||||
output.color = vec4<f32>(output.color.rgb * tint.rgb, output.color.a);
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pixel_art_sample(input_texture: texture_2d<f32>, input_sampler: sampler, input_uv: vec2<f32>, tile: u32) -> vec4<f32> {
|
|
||||||
let dimensions = vec2<f32>(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);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user