Compare commits

..

26 Commits

Author SHA1 Message Date
Sven Balzer 963ccc4ec8 change rendering offsets for character, character shadow and trees
buildbot/windows Build done.
buildbot/linux Build done.
change default camera tilt
2026-08-05 21:50:13 +02:00
Sven Balzer 4c158f25f0 add trees into the game
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-05 20:48:57 +02:00
Sven Balzer 6a984b40d9 remove vertex_buffer and index_buffer for characters and character shadows
refactor world shader vertex position calculation
2026-08-05 20:48:57 +02:00
Ammerhai 74d55cb087 update female character sprite sheet
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-05 20:39:59 +02:00
Ammerhai 8f277c4d08 add correct tree angle
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-05 20:39:09 +02:00
Sven Balzer 3366008d59 replace placeholder character with female
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-03 18:36:40 +02:00
Ammerhai e49683eb7b update tree again
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-03 18:34:49 +02:00
Ammerhai d04e231f4d update tree
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-03 18:28:41 +02:00
Ammerhai 198ed44bbf add character female
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-03 18:28:14 +02:00
Sven Balzer 7fe5419b02 fix leak of frame_fence in sdlgpu renderer
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-03 17:32:57 +02:00
Sven Balzer 6aa530daea rename basic shader to character
buildbot/windows Build done.
buildbot/linux Build done.
add character shadow
make animation play twice as fast when sprinting
2026-08-03 13:32:52 +02:00
Ammerhai 4f4ec3cfd5 remove map layout
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-02 13:20:08 +02:00
Sven Balzer e5cc22cb95 also respect arrow keys for continuous movement
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-02 13:06:37 +02:00
Ammerhai b9eb121663 add last tile and tree
buildbot/windows Build done.
buildbot/linux Build done.
add water starter

#8
2026-08-02 12:56:13 +02:00
Sven Balzer f72ca9def5 add basic animation
buildbot/windows Build done.
buildbot/linux Build done.
2026-08-02 12:40:24 +02:00
Sven Balzer 70fac5bd72 fix clamping character movement to map boundaries 2026-08-02 10:57:59 +02:00
Ammerhai ab79875263 remove placeholder tiles
buildbot/windows Build done.
#8
2026-08-01 20:23:42 +02:00
Ammerhai 3a012fc564 fix incorrect tile corner infos
#8
2026-08-01 20:09:47 +02:00
Ammerhai bd727a6505 add correct tile values
#8
2026-08-01 19:39:07 +02:00
Ammerhai da801d1937 add region map day/night
add first two starter mons

- fire/feuer
- grass/pflanze
2026-08-01 19:38:10 +02:00
Ammerhai 1b03990f92 add new tiles and change paths to new ones
#8
2026-08-01 19:37:41 +02:00
Sven Balzer d2b472548f move per_frame and view_projection matrix into shared file 2026-08-01 13:36:30 +02:00
Sven Balzer 0c7ec7299e basic smooth movement 2026-08-01 12:37:53 +02:00
Sven Balzer f564c14354 change grid shader primitive to line from triangle 2026-08-01 09:37:43 +02:00
Sven Balzer 08b8b397e2 fix explicitly changing tiles 2026-08-01 09:07:45 +02:00
Sven Balzer e6fa28a18f make shaders be compiled by cmake instead of a script 2026-08-01 09:07:01 +02:00
69 changed files with 1658 additions and 453 deletions
+28
View File
@@ -5,6 +5,7 @@ set(CMAKE_C_STANDARD 23)
set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON)
option(TRACY_ENABLE "Enable Tracy profiling" OFF) option(TRACY_ENABLE "Enable Tracy profiling" OFF)
@@ -89,6 +90,31 @@ target_include_directories(stb_image INTERFACE libs/stb)
option(TRACY_ONLY_LOCALHOST "" ON) option(TRACY_ONLY_LOCALHOST "" ON)
add_subdirectory(libs/tracy) add_subdirectory(libs/tracy)
# shaders
find_program(SLANGC_EXECUTABLE slangc)
set(SHADERS_SPV "")
set(SHADERS_WGSL "")
function(add_shader name)
if(SLANGC_EXECUTABLE)
add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/spirv/${name}.spv" DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/${name}-spv.dep" COMMAND "${SLANGC_EXECUTABLE}" -depfile "${CMAKE_CURRENT_BINARY_DIR}/${name}-spv.dep" "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/src/${name}.slang" -o "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/spirv/${name}.spv" -target spirv -profile spirv_1_0)
add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/wgsl/${name}.wgsl" DEPFILE "${CMAKE_CURRENT_BINARY_DIR}/${name}-wgsl.dep" COMMAND "${SLANGC_EXECUTABLE}" -depfile "${CMAKE_CURRENT_BINARY_DIR}/${name}-wgsl.dep" "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/src/${name}.slang" -o "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/wgsl/${name}.wgsl" -target wgsl -D__wgsl__)
endif()
set(SHADERS_SPV ${SHADERS_SPV} "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/spirv/${name}.spv" PARENT_SCOPE)
set(SHADERS_WGSL ${SHADERS_WGSL} "${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/wgsl/${name}.wgsl" PARENT_SCOPE)
endfunction()
add_shader(character)
add_shader(character_shadow)
add_shader(world)
add_shader(tree)
add_shader(grid)
add_custom_target(shaders-spv DEPENDS ${SHADERS_SPV})
add_custom_target(shaders-wgsl DEPENDS ${SHADERS_WGSL})
# game
add_executable(mikemon add_executable(mikemon
src/smol-atlas.cpp src/smol-atlas.cpp
src/change_directory.c src/change_directory.c
@@ -106,6 +132,7 @@ target_link_libraries(mikemon
TracyClient TracyClient
wgpu wgpu
) )
add_dependencies(mikemon shaders-wgsl)
add_executable(mikemon-sdlgpu add_executable(mikemon-sdlgpu
src/smol-atlas.cpp src/smol-atlas.cpp
@@ -124,3 +151,4 @@ target_link_libraries(mikemon-sdlgpu
TracyClient TracyClient
wgpu wgpu
) )
add_dependencies(mikemon-sdlgpu shaders-spv)
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 283 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.
+490 -193
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -8,8 +8,10 @@ extern "C" {
#endif // __cplusplus #endif // __cplusplus
typedef enum : Uint32 { typedef enum : Uint32 {
R_SHADER_BASIC, R_SHADER_CHARACTER,
R_SHADER_CHARACTER_SHADOW,
R_SHADER_WORLD, R_SHADER_WORLD,
R_SHADER_TREE,
R_SHADER_GRID, R_SHADER_GRID,
R_SHADER_COUNT, R_SHADER_COUNT,
} R_Shader; } R_Shader;
+284 -46
View File
@@ -287,6 +287,7 @@ void renderer_frame_end() {
SDL_GPUFence *frame_fence = SDL_SubmitGPUCommandBufferAndAcquireFence(render_command_buffer); SDL_GPUFence *frame_fence = SDL_SubmitGPUCommandBufferAndAcquireFence(render_command_buffer);
SDL_WaitForGPUFences(device, true, &frame_fence, 1); SDL_WaitForGPUFences(device, true, &frame_fence, 1);
SDL_ReleaseGPUFence(device, frame_fence);
copy_command_buffer = SDL_AcquireGPUCommandBuffer(device); copy_command_buffer = SDL_AcquireGPUCommandBuffer(device);
render_command_buffer = SDL_AcquireGPUCommandBuffer(device); render_command_buffer = SDL_AcquireGPUCommandBuffer(device);
@@ -343,7 +344,7 @@ void renderer_frame_draw(R_Buffer vertex_buffer, R_Buffer index_buffer, R_Buffer
for (int i = 0; i < resources->num_fragment_uniform_buffers; i++) SDL_PushGPUFragmentUniformData(render_command_buffer, i, resources->fragment_uniform_buffers[i]->cpu_uniform_data, resources->fragment_uniform_buffers[i]->num_bytes); for (int i = 0; i < resources->num_fragment_uniform_buffers; i++) SDL_PushGPUFragmentUniformData(render_command_buffer, i, resources->fragment_uniform_buffers[i]->cpu_uniform_data, resources->fragment_uniform_buffers[i]->num_bytes);
if (vertex_buffer) SDL_BindGPUVertexBuffers(render_pass, 0, &(SDL_GPUBufferBinding){ .buffer = vertex_buffer->buffer, .offset = 0 }, 1); if (vertex_buffer) SDL_BindGPUVertexBuffers(render_pass, 0, &(SDL_GPUBufferBinding){ .buffer = vertex_buffer->buffer, .offset = 0 }, 1);
if (instance_buffer) SDL_BindGPUVertexBuffers(render_pass, 1, &(SDL_GPUBufferBinding){ .buffer = instance_buffer->buffer, .offset = 0 }, 1); if (instance_buffer) SDL_BindGPUVertexBuffers(render_pass, vertex_buffer ? 1 : 0, &(SDL_GPUBufferBinding){ .buffer = instance_buffer->buffer, .offset = 0 }, 1);
if (index_buffer) { if (index_buffer) {
SDL_BindGPUIndexBuffer(render_pass, &(SDL_GPUBufferBinding){ .buffer = index_buffer->buffer, .offset = 0 }, SDL_GPU_INDEXELEMENTSIZE_16BIT); SDL_BindGPUIndexBuffer(render_pass, &(SDL_GPUBufferBinding){ .buffer = index_buffer->buffer, .offset = 0 }, SDL_GPU_INDEXELEMENTSIZE_16BIT);
@@ -409,9 +410,9 @@ bool renderer_init(SDL_Window *window_) {
}); });
// Shaders // Shaders
{ // Basic { // Character
const Uint8 shader_source[] = { const Uint8 shader_source[] = {
#embed "shaders/spirv/basic.spv" #embed "shaders/spirv/character.spv"
}; };
SDL_GPUShader *vertex_shader = SDL_CreateGPUShader(device, &(SDL_GPUShaderCreateInfo){ SDL_GPUShader *vertex_shader = SDL_CreateGPUShader(device, &(SDL_GPUShaderCreateInfo){
@@ -443,9 +444,9 @@ bool renderer_init(SDL_Window *window_) {
}); });
SDL_PropertiesID properties = SDL_CreateProperties(); SDL_PropertiesID properties = SDL_CreateProperties();
SDL_SetStringProperty(properties, SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING, "R_SHADER basic"); SDL_SetStringProperty(properties, SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING, "R_SHADER character");
shaders[R_SHADER_BASIC] = SDL_CreateGPUGraphicsPipeline(device, &(SDL_GPUGraphicsPipelineCreateInfo){ shaders[R_SHADER_CHARACTER] = SDL_CreateGPUGraphicsPipeline(device, &(SDL_GPUGraphicsPipelineCreateInfo){
.vertex_shader = vertex_shader, .vertex_shader = vertex_shader,
.fragment_shader = fragment_shader, .fragment_shader = fragment_shader,
@@ -453,42 +454,167 @@ bool renderer_init(SDL_Window *window_) {
.vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){ .vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){
{ {
.slot = 0, .slot = 0,
.pitch = 20, .pitch = 12,
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
.instance_step_rate = 0,
},
{
.slot = 1,
.pitch = 8,
.input_rate = SDL_GPU_VERTEXINPUTRATE_INSTANCE, .input_rate = SDL_GPU_VERTEXINPUTRATE_INSTANCE,
.instance_step_rate = 0, .instance_step_rate = 0,
}, },
}, },
.num_vertex_buffers = 2, .num_vertex_buffers = 1,
.vertex_attributes = (SDL_GPUVertexAttribute[]){ .vertex_attributes = (SDL_GPUVertexAttribute[]){
{ {
.location = 0, .location = 2,
.buffer_slot = 0, .buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
.offset = 0, .offset = 0,
}, },
{ {
.location = 1, .location = 3,
.buffer_slot = 0, .buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2, .format = SDL_GPU_VERTEXELEMENTFORMAT_UINT,
.offset = 12, .offset = 8,
}, },
},
.num_vertex_attributes = 2,
},
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
.rasterizer_state = {
.fill_mode = SDL_GPU_FILLMODE_FILL,
.cull_mode = SDL_GPU_CULLMODE_BACK,
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
.depth_bias_constant_factor = 0.0f,
.depth_bias_clamp = 0.0f,
.depth_bias_slope_factor = 0.0f,
.enable_depth_bias = false,
.enable_depth_clip = false,
},
.multisample_state = {
.sample_count = SDL_GPU_SAMPLECOUNT_8,
.sample_mask = 0,
.enable_mask = 0,
.enable_alpha_to_coverage = false,
},
.depth_stencil_state = {
.compare_op = SDL_GPU_COMPAREOP_GREATER_OR_EQUAL,
.back_stencil_state = { .fail_op = SDL_GPU_STENCILOP_INVALID, .pass_op = SDL_GPU_STENCILOP_INVALID, .depth_fail_op = SDL_GPU_STENCILOP_INVALID, .compare_op = SDL_GPU_COMPAREOP_INVALID, },
.front_stencil_state = { .fail_op = SDL_GPU_STENCILOP_INVALID, .pass_op = SDL_GPU_STENCILOP_INVALID, .depth_fail_op = SDL_GPU_STENCILOP_INVALID, .compare_op = SDL_GPU_COMPAREOP_INVALID, },
.compare_mask = 0,
.write_mask = 0,
.enable_depth_test = false,
.enable_depth_write = false,
.enable_stencil_test = false,
},
.target_info = {
.color_target_descriptions = (SDL_GPUColorTargetDescription[]){
{
.format = texture_formats[surface.format],
.blend_state = {
.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
.color_blend_op = SDL_GPU_BLENDOP_ADD,
.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
.alpha_blend_op = SDL_GPU_BLENDOP_ADD,
.color_write_mask = 0,
.enable_blend = true,
.enable_color_write_mask = false,
},
}
},
.num_color_targets = 1,
.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_INVALID,
.has_depth_stencil_target = false,
},
});
SDL_DestroyProperties(properties);
SDL_ReleaseGPUShader(device, vertex_shader);
SDL_ReleaseGPUShader(device, fragment_shader);
}
{ // Character Shadow
const Uint8 shader_source[] = {
#embed "shaders/spirv/character_shadow.spv"
};
SDL_GPUShader *vertex_shader = SDL_CreateGPUShader(device, &(SDL_GPUShaderCreateInfo){
.code_size = sizeof(shader_source),
.code = shader_source,
.entrypoint = "main_vertex",
.format = SDL_GPU_SHADERFORMAT_SPIRV,
.stage = SDL_GPU_SHADERSTAGE_VERTEX,
.num_samplers = 0,
.num_storage_textures = 0,
.num_storage_buffers = 0,
.num_uniform_buffers = 1,
});
SDL_GPUShader *fragment_shader = SDL_CreateGPUShader(device, &(SDL_GPUShaderCreateInfo){
.code_size = sizeof(shader_source),
.code = shader_source,
.entrypoint = "main_fragment",
.format = SDL_GPU_SHADERFORMAT_SPIRV,
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
.num_samplers = 1,
.num_storage_textures = 0,
.num_storage_buffers = 0,
.num_uniform_buffers = 1,
});
SDL_PropertiesID properties = SDL_CreateProperties();
SDL_SetStringProperty(properties, SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING, "R_SHADER character_shadow");
shaders[R_SHADER_CHARACTER_SHADOW] = SDL_CreateGPUGraphicsPipeline(device, &(SDL_GPUGraphicsPipelineCreateInfo){
.vertex_shader = vertex_shader,
.fragment_shader = fragment_shader,
.vertex_input_state = {
.vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){
{
.slot = 0,
.pitch = 12,
.input_rate = SDL_GPU_VERTEXINPUTRATE_INSTANCE,
.instance_step_rate = 0,
},
},
.num_vertex_buffers = 1,
.vertex_attributes = (SDL_GPUVertexAttribute[]){
{ {
.location = 2, .location = 2,
.buffer_slot = 1, .buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2, .format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
.offset = 0, .offset = 0,
}, },
{
.location = 3,
.buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_UINT,
.offset = 8,
}, },
.num_vertex_attributes = 3, },
.num_vertex_attributes = 2,
}, },
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST, .primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
@@ -600,12 +726,129 @@ bool renderer_init(SDL_Window *window_) {
.vertex_shader = vertex_shader, .vertex_shader = vertex_shader,
.fragment_shader = fragment_shader, .fragment_shader = fragment_shader,
.vertex_input_state = {
.vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]) {},
.num_vertex_buffers = 0,
.vertex_attributes = (SDL_GPUVertexAttribute[]) {},
.num_vertex_attributes = 0,
},
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
.rasterizer_state = {
.fill_mode = SDL_GPU_FILLMODE_FILL,
.cull_mode = SDL_GPU_CULLMODE_BACK,
.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
.depth_bias_constant_factor = 0.0f,
.depth_bias_clamp = 0.0f,
.depth_bias_slope_factor = 0.0f,
.enable_depth_bias = false,
.enable_depth_clip = false,
},
.multisample_state = {
.sample_count = SDL_GPU_SAMPLECOUNT_8,
.sample_mask = 0,
.enable_mask = 0,
.enable_alpha_to_coverage = false,
},
.depth_stencil_state = {
.compare_op = SDL_GPU_COMPAREOP_GREATER_OR_EQUAL,
.back_stencil_state = { .fail_op = SDL_GPU_STENCILOP_INVALID, .pass_op = SDL_GPU_STENCILOP_INVALID, .depth_fail_op = SDL_GPU_STENCILOP_INVALID, .compare_op = SDL_GPU_COMPAREOP_INVALID, },
.front_stencil_state = { .fail_op = SDL_GPU_STENCILOP_INVALID, .pass_op = SDL_GPU_STENCILOP_INVALID, .depth_fail_op = SDL_GPU_STENCILOP_INVALID, .compare_op = SDL_GPU_COMPAREOP_INVALID, },
.compare_mask = 0,
.write_mask = 0,
.enable_depth_test = false,
.enable_depth_write = false,
.enable_stencil_test = false,
},
.target_info = {
.color_target_descriptions = (SDL_GPUColorTargetDescription[]){
{
.format = texture_formats[surface.format],
.blend_state = {
.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
.color_blend_op = SDL_GPU_BLENDOP_ADD,
.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA,
.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
.alpha_blend_op = SDL_GPU_BLENDOP_ADD,
.color_write_mask = 0,
.enable_blend = true,
.enable_color_write_mask = false,
},
}
},
.num_color_targets = 1,
.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_INVALID,
.has_depth_stencil_target = false,
},
});
SDL_DestroyProperties(properties);
SDL_ReleaseGPUShader(device, vertex_shader);
SDL_ReleaseGPUShader(device, fragment_shader);
}
{ // Tree
const Uint8 shader_source[] = {
#embed "shaders/spirv/tree.spv"
};
SDL_GPUShader *vertex_shader = SDL_CreateGPUShader(device, &(SDL_GPUShaderCreateInfo){
.code_size = sizeof(shader_source),
.code = shader_source,
.entrypoint = "main_vertex",
.format = SDL_GPU_SHADERFORMAT_SPIRV,
.stage = SDL_GPU_SHADERSTAGE_VERTEX,
.num_samplers = 0,
.num_storage_textures = 0,
.num_storage_buffers = 0,
.num_uniform_buffers = 2,
});
SDL_GPUShader *fragment_shader = SDL_CreateGPUShader(device, &(SDL_GPUShaderCreateInfo){
.code_size = sizeof(shader_source),
.code = shader_source,
.entrypoint = "main_fragment",
.format = SDL_GPU_SHADERFORMAT_SPIRV,
.stage = SDL_GPU_SHADERSTAGE_FRAGMENT,
.num_samplers = 1,
.num_storage_textures = 0,
.num_storage_buffers = 1,
.num_uniform_buffers = 1,
});
SDL_PropertiesID properties = SDL_CreateProperties();
SDL_SetStringProperty(properties, SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING, "R_SHADER tree");
shaders[R_SHADER_TREE] = SDL_CreateGPUGraphicsPipeline(device, &(SDL_GPUGraphicsPipelineCreateInfo){
.vertex_shader = vertex_shader,
.fragment_shader = fragment_shader,
.vertex_input_state = { .vertex_input_state = {
.vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){ .vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){
{ {
.slot = 0, .slot = 0,
.pitch = 20, .pitch = 12,
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX, .input_rate = SDL_GPU_VERTEXINPUTRATE_INSTANCE,
.instance_step_rate = 0, .instance_step_rate = 0,
}, },
@@ -616,11 +859,17 @@ bool renderer_init(SDL_Window *window_) {
{ {
.location = 0, .location = 0,
.buffer_slot = 0, .buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .format = SDL_GPU_VERTEXELEMENTFORMAT_UINT2,
.offset = 0, .offset = 0,
}, },
{
.location = 1,
.buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_UINT,
.offset = 8,
}, },
.num_vertex_attributes = 1, },
.num_vertex_attributes = 2,
}, },
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST, .primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
@@ -733,29 +982,14 @@ bool renderer_init(SDL_Window *window_) {
.fragment_shader = fragment_shader, .fragment_shader = fragment_shader,
.vertex_input_state = { .vertex_input_state = {
.vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){ .vertex_buffer_descriptions = (SDL_GPUVertexBufferDescription[]){},
{ .num_vertex_buffers = 0,
.slot = 0,
.pitch = 20,
.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX,
.instance_step_rate = 0, .vertex_attributes = (SDL_GPUVertexAttribute[]){},
}, .num_vertex_attributes = 0,
},
.num_vertex_buffers = 1,
.vertex_attributes = (SDL_GPUVertexAttribute[]){
{
.location = 0,
.buffer_slot = 0,
.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
.offset = 0,
},
},
.num_vertex_attributes = 1,
}, },
.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST, .primitive_type = SDL_GPU_PRIMITIVETYPE_LINELIST,
.rasterizer_state = { .rasterizer_state = {
.fill_mode = SDL_GPU_FILLMODE_FILL, .fill_mode = SDL_GPU_FILLMODE_FILL,
@@ -824,9 +1058,13 @@ bool renderer_init(SDL_Window *window_) {
SDL_ReleaseGPUShader(device, fragment_shader); SDL_ReleaseGPUShader(device, fragment_shader);
} }
for (int i = 0; i < R_SHADER_COUNT; i++) {
SDL_assert(shaders[i]);
}
transfer_buffer = SDL_CreateGPUTransferBuffer(device, &(SDL_GPUTransferBufferCreateInfo){ transfer_buffer = SDL_CreateGPUTransferBuffer(device, &(SDL_GPUTransferBufferCreateInfo){
.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD, .usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
.size = 64 * 1024, .size = 512 * 1024,
}); });
copy_command_buffer = SDL_AcquireGPUCommandBuffer(device); copy_command_buffer = SDL_AcquireGPUCommandBuffer(device);
+230 -43
View File
@@ -476,7 +476,7 @@ void renderer_frame_draw(R_Buffer vertex_buffer, R_Buffer index_buffer, R_Buffer
} }
if (vertex_buffer) wgpuRenderPassEncoderSetVertexBuffer(pass_encoder, 0, vertex_buffer->buffer, 0, WGPU_WHOLE_SIZE); if (vertex_buffer) wgpuRenderPassEncoderSetVertexBuffer(pass_encoder, 0, vertex_buffer->buffer, 0, WGPU_WHOLE_SIZE);
if (instance_buffer) wgpuRenderPassEncoderSetVertexBuffer(pass_encoder, 1, instance_buffer->buffer, 0, WGPU_WHOLE_SIZE); if (instance_buffer) wgpuRenderPassEncoderSetVertexBuffer(pass_encoder, vertex_buffer ? 1 : 0, instance_buffer->buffer, 0, WGPU_WHOLE_SIZE);
if (index_buffer) { if (index_buffer) {
wgpuRenderPassEncoderSetIndexBuffer(pass_encoder, index_buffer->buffer, WGPUIndexFormat_Uint16, 0, WGPU_WHOLE_SIZE); wgpuRenderPassEncoderSetIndexBuffer(pass_encoder, index_buffer->buffer, WGPUIndexFormat_Uint16, 0, WGPU_WHOLE_SIZE);
@@ -673,9 +673,9 @@ bool renderer_init(SDL_Window *window_) {
}; };
// Shaders // Shaders
{ // Basic { // Character
const char shader_source[] = { const char shader_source[] = {
#embed "shaders/wgsl/basic.wgsl" #embed "shaders/wgsl/character.wgsl"
}; };
WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &(WGPUShaderModuleDescriptor){ WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &(WGPUShaderModuleDescriptor){
@@ -683,14 +683,14 @@ bool renderer_init(SDL_Window *window_) {
.chain = { .next = NULL, .sType = WGPUSType_ShaderSourceWGSL }, .chain = { .next = NULL, .sType = WGPUSType_ShaderSourceWGSL },
.code = { .data = shader_source, .length = SDL_arraysize(shader_source) }, .code = { .data = shader_source, .length = SDL_arraysize(shader_source) },
}, },
.label = { .data = "basic shader", .length = WGPU_STRLEN } .label = { .data = "character shader", .length = WGPU_STRLEN }
}); });
shaders[R_SHADER_BASIC] = wgpuDeviceCreateRenderPipeline(device, &(WGPURenderPipelineDescriptor){ shaders[R_SHADER_CHARACTER] = wgpuDeviceCreateRenderPipeline(device, &(WGPURenderPipelineDescriptor){
.label = { .data = "basic render_pipeline", .length = WGPU_STRLEN }, .label = { .data = "character render_pipeline", .length = WGPU_STRLEN },
.layout = wgpuDeviceCreatePipelineLayout(device, &(WGPUPipelineLayoutDescriptor){ .layout = wgpuDeviceCreatePipelineLayout(device, &(WGPUPipelineLayoutDescriptor){
.label = { .data = "basic pipeline_layout", .length = WGPU_STRLEN }, .label = { .data = "character pipeline_layout", .length = WGPU_STRLEN },
.bindGroupLayoutCount = 4, .bindGroupLayoutCount = 4,
.bindGroupLayouts = (WGPUBindGroupLayout[]){ .bindGroupLayouts = (WGPUBindGroupLayout[]){
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){ wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
@@ -726,35 +726,127 @@ bool renderer_init(SDL_Window *window_) {
.entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN }, .entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN },
.constantCount = 0, .constantCount = 0,
.constants = NULL, .constants = NULL,
.bufferCount = 2, .bufferCount = 1,
.buffers = (WGPUVertexBufferLayout[]){ .buffers = (WGPUVertexBufferLayout[]){
{
.stepMode = WGPUVertexStepMode_Vertex,
.arrayStride = 20,
.attributeCount = 2,
.attributes = (WGPUVertexAttribute[]){
{
.format = WGPUVertexFormat_Float32x3,
.offset = 0,
.shaderLocation = 0,
},
{
.format = WGPUVertexFormat_Float32x2,
.offset = 12,
.shaderLocation = 1,
},
},
},
{ {
.stepMode = WGPUVertexStepMode_Instance, .stepMode = WGPUVertexStepMode_Instance,
.arrayStride = 8, .arrayStride = 12,
.attributeCount = 1, .attributeCount = 2,
.attributes = (WGPUVertexAttribute[]){ .attributes = (WGPUVertexAttribute[]){
{ {
.format = WGPUVertexFormat_Float32x2, .format = WGPUVertexFormat_Float32x2,
.offset = 0, .offset = 0,
.shaderLocation = 2, .shaderLocation = 2,
}, },
{
.format = WGPUVertexFormat_Uint32,
.offset = 8,
.shaderLocation = 3,
},
},
},
},
},
.primitive = {
.topology = WGPUPrimitiveTopology_TriangleList,
.stripIndexFormat = WGPUIndexFormat_Undefined,
.frontFace = WGPUFrontFace_CCW,
.cullMode = WGPUCullMode_Back,
.unclippedDepth = false,
},
.depthStencil = NULL,
.multisample = {
.count = 4,
.mask = ~0u,
.alphaToCoverageEnabled = false,
},
.fragment = &(WGPUFragmentState){
.module = shader,
.entryPoint = { .data = "main_fragment", .length = WGPU_STRLEN },
.constantCount = 0,
.constants = NULL,
.targetCount = 1,
.targets = &color_target_state,
},
});
wgpuShaderModuleRelease(shader);
}
{ // Character Shadow
const char shader_source[] = {
#embed "shaders/wgsl/character_shadow.wgsl"
};
WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &(WGPUShaderModuleDescriptor){
.nextInChain = (WGPUChainedStruct *)&(WGPUShaderSourceWGSL){
.chain = { .next = NULL, .sType = WGPUSType_ShaderSourceWGSL },
.code = { .data = shader_source, .length = SDL_arraysize(shader_source) },
},
.label = { .data = "character_shadow shader", .length = WGPU_STRLEN }
});
shaders[R_SHADER_CHARACTER_SHADOW] = wgpuDeviceCreateRenderPipeline(device, &(WGPURenderPipelineDescriptor){
.label = { .data = "character_shadow render_pipeline", .length = WGPU_STRLEN },
.layout = wgpuDeviceCreatePipelineLayout(device, &(WGPUPipelineLayoutDescriptor){
.label = { .data = "character_shadow pipeline_layout", .length = WGPU_STRLEN },
.bindGroupLayoutCount = 4,
.bindGroupLayouts = (WGPUBindGroupLayout[]){
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 0,
.entries = (WGPUBindGroupLayoutEntry[]){
},
}),
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 1,
.entries = (WGPUBindGroupLayoutEntry[]){
{ .binding = 0, .visibility = WGPUShaderStage_Vertex, .buffer = { .type = WGPUBufferBindingType_Uniform } },
},
}),
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 2,
.entries = (WGPUBindGroupLayoutEntry[]){
{ .binding = 0, .visibility = WGPUShaderStage_Fragment, .texture = { .sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D } },
{ .binding = 1, .visibility = WGPUShaderStage_Fragment, .sampler = { .type = WGPUSamplerBindingType_Filtering } },
},
}),
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 1,
.entries = (WGPUBindGroupLayoutEntry[]){
{ .binding = 0, .visibility = WGPUShaderStage_Fragment, .buffer = { .type = WGPUBufferBindingType_Uniform } },
},
}),
},
}),
.vertex = {
.module = shader,
.entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN },
.constantCount = 0,
.constants = NULL,
.bufferCount = 1,
.buffers = (WGPUVertexBufferLayout[]){
{
.stepMode = WGPUVertexStepMode_Instance,
.arrayStride = 12,
.attributeCount = 2,
.attributes = (WGPUVertexAttribute[]){
{
.format = WGPUVertexFormat_Float32x2,
.offset = 0,
.shaderLocation = 2,
},
{
.format = WGPUVertexFormat_Uint32,
.offset = 8,
.shaderLocation = 3,
},
}, },
}, },
}, },
@@ -879,6 +971,110 @@ bool renderer_init(SDL_Window *window_) {
wgpuShaderModuleRelease(shader); wgpuShaderModuleRelease(shader);
} }
{ // Tree
const char shader_source[] = {
#embed "shaders/wgsl/tree.wgsl"
};
WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &(WGPUShaderModuleDescriptor){
.nextInChain = (WGPUChainedStruct *)&(WGPUShaderSourceWGSL){
.chain = { .next = NULL, .sType = WGPUSType_ShaderSourceWGSL },
.code = { .data = shader_source, .length = SDL_arraysize(shader_source) },
},
.label = { .data = "tree shader", .length = WGPU_STRLEN }
});
shaders[R_SHADER_TREE] = wgpuDeviceCreateRenderPipeline(device, &(WGPURenderPipelineDescriptor){
.label = { .data = "tree render_pipeline", .length = WGPU_STRLEN },
.layout = wgpuDeviceCreatePipelineLayout(device, &(WGPUPipelineLayoutDescriptor){
.label = { .data = "tree pipeline_layout", .length = WGPU_STRLEN },
.bindGroupLayoutCount = 4,
.bindGroupLayouts = (WGPUBindGroupLayout[]){
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 0,
.entries = (WGPUBindGroupLayoutEntry[]){},
}),
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 2,
.entries = (WGPUBindGroupLayoutEntry[]){
{ .binding = 0, .visibility = WGPUShaderStage_Vertex, .buffer = { .type = WGPUBufferBindingType_Uniform } },
{ .binding = 1, .visibility = WGPUShaderStage_Vertex, .buffer = { .type = WGPUBufferBindingType_Uniform } },
},
}),
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 3,
.entries = (WGPUBindGroupLayoutEntry[]){
{ .binding = 0, .visibility = WGPUShaderStage_Fragment, .texture = { .sampleType = WGPUTextureSampleType_Float, .viewDimension = WGPUTextureViewDimension_2D } },
{ .binding = 1, .visibility = WGPUShaderStage_Fragment, .sampler = { .type = WGPUSamplerBindingType_Filtering } },
{ .binding = 2, .visibility = WGPUShaderStage_Fragment, .buffer = { .type = WGPUBufferBindingType_ReadOnlyStorage } },
},
}),
wgpuDeviceCreateBindGroupLayout(device, &(WGPUBindGroupLayoutDescriptor){
.entryCount = 1,
.entries = (WGPUBindGroupLayoutEntry[]){
{ .binding = 0, .visibility = WGPUShaderStage_Fragment, .buffer = { .type = WGPUBufferBindingType_Uniform } },
},
}),
},
}),
.vertex = {
.module = shader,
.entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN },
.constantCount = 0,
.constants = NULL,
.bufferCount = 1,
.buffers = (WGPUVertexBufferLayout[]){
{
.stepMode = WGPUVertexStepMode_Instance,
.arrayStride = 12,
.attributeCount = 2,
.attributes = (WGPUVertexAttribute[]){
{
.format = WGPUVertexFormat_Uint32x2,
.offset = 0,
.shaderLocation = 0,
},
{
.format = WGPUVertexFormat_Uint32,
.offset = 8,
.shaderLocation = 1,
},
},
},
},
},
.primitive = {
.topology = WGPUPrimitiveTopology_TriangleList,
.stripIndexFormat = WGPUIndexFormat_Undefined,
.frontFace = WGPUFrontFace_CCW,
.cullMode = WGPUCullMode_Back,
.unclippedDepth = false,
},
.depthStencil = NULL,
.multisample = {
.count = 4,
.mask = ~0u,
.alphaToCoverageEnabled = false,
},
.fragment = &(WGPUFragmentState){
.module = shader,
.entryPoint = { .data = "main_fragment", .length = WGPU_STRLEN },
.constantCount = 0,
.constants = NULL,
.targetCount = 1,
.targets = &color_target_state,
},
});
wgpuShaderModuleRelease(shader);
}
{ // Grid { // Grid
const char shader_source[] = { const char shader_source[] = {
#embed "shaders/wgsl/grid.wgsl" #embed "shaders/wgsl/grid.wgsl"
@@ -932,25 +1128,12 @@ bool renderer_init(SDL_Window *window_) {
.entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN }, .entryPoint = { .data = "main_vertex", .length = WGPU_STRLEN },
.constantCount = 0, .constantCount = 0,
.constants = NULL, .constants = NULL,
.bufferCount = 1, .bufferCount = 0,
.buffers = (WGPUVertexBufferLayout[]){ .buffers = NULL,
{
.stepMode = WGPUVertexStepMode_Vertex,
.arrayStride = 20,
.attributeCount = 1,
.attributes = (WGPUVertexAttribute[]){
{
.format = WGPUVertexFormat_Float32x3,
.offset = 0,
.shaderLocation = 0,
},
},
},
},
}, },
.primitive = { .primitive = {
.topology = WGPUPrimitiveTopology_TriangleList, .topology = WGPUPrimitiveTopology_LineList,
.stripIndexFormat = WGPUIndexFormat_Undefined, .stripIndexFormat = WGPUIndexFormat_Undefined,
.frontFace = WGPUFrontFace_CCW, .frontFace = WGPUFrontFace_CCW,
.cullMode = WGPUCullMode_Back, .cullMode = WGPUCullMode_Back,
@@ -978,6 +1161,10 @@ bool renderer_init(SDL_Window *window_) {
wgpuShaderModuleRelease(shader); wgpuShaderModuleRelease(shader);
} }
for (int i = 0; i < R_SHADER_COUNT; i++) {
SDL_assert(shaders[i]);
}
return true; return true;
} }
-9
View File
@@ -1,9 +0,0 @@
#!/bin/bash
slangc src/basic.slang -target wgsl -D__wgsl__ -o wgsl/basic.wgsl
slangc src/world.slang -target wgsl -D__wgsl__ -o wgsl/world.wgsl
slangc src/grid.slang -target wgsl -D__wgsl__ -o wgsl/grid.wgsl
slangc src/basic.slang -target spirv -profile spirv_1_0 -o spirv/basic.spv
slangc src/world.slang -target spirv -profile spirv_1_0 -o spirv/world.spv
slangc src/grid.slang -target spirv -profile spirv_1_0 -o spirv/grid.spv
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+83
View File
@@ -0,0 +1,83 @@
#language 2026
#include "shared.slang"
struct VertexShaderInput {
uint32_t vertex_index : SV_VulkanVertexID;
// Per Instance
[vk::location(2)] float2 world_pos;
[vk::location(3)] uint sprite_selection;
};
struct VertexShaderOutput {
float4 pos : SV_Position;
float2 uv;
};
struct FragmentShaderOutput {
float4 color : SV_Target;
};
[shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) {
var output: VertexShaderOutput;
var vertex_pos = float2(0, 0);
var vertex_uv = float2(0, 0);
switch (input.vertex_index) {
case 0: { vertex_pos = float2(-0.5, 0.5); vertex_uv = float2(0, 0); } break;
case 1: { vertex_pos = float2(-0.5, -0.5); vertex_uv = float2(0, 1); } break;
case 2: { vertex_pos = float2( 0.5, -0.5); vertex_uv = float2(1, 1); } break;
case 3: { vertex_pos = float2(-0.5, 0.5); vertex_uv = float2(0, 0); } break;
case 4: { vertex_pos = float2( 0.5, -0.5); vertex_uv = float2(1, 1); } break;
case 5: { vertex_pos = float2( 0.5, 0.5); vertex_uv = float2(1, 0); } break;
default: {}
}
output.pos = mul(float4(input.world_pos + vertex_pos + float2(0, 0.35), 0, 1), view_projection_matrix);
uint sprite_x = bitfieldExtract(input.sprite_selection, 16, 16);
uint sprite_y = bitfieldExtract(input.sprite_selection, 0, 16);
output.uv = (float2(sprite_x, sprite_y) + vertex_uv) * (1.0 / 4.0);
return output;
}
[vk::binding(0, 2)] Sampler2D<float4> texture1 : register(t0, space2);
[vk::binding(0, 3)] ConstantBuffer<float3> tint : register(b0, space3);
[shader("pixel")]
FragmentShaderOutput main_fragment(VertexShaderOutput input) {
var output: FragmentShaderOutput;
output.color = pixel_art_sample(texture1, input.uv);
output.color = float4(output.color.rgb * tint.rgb, output.color.a);
return output;
}
void GetDimensions(Sampler2D<float4> texture, out float width, out float height) {
__target_switch {
case wgsl: {
texture.__getTexture().GetDimensions(width, height);
} break;
default: {
texture.GetDimensions(width, height);
} break;
}
}
float4 pixel_art_sample(Sampler2D<float4> input_texture, float2 input_uv) {
var dimensions : float2;
GetDimensions(input_texture, dimensions.x, dimensions.y);
let texture_uv = input_uv * dimensions.xy;
let sample_uv = (floor(texture_uv) + min(fract(texture_uv) / fwidth(texture_uv), float2(1.0, 1.0)) - 0.5) / dimensions.xy;
return input_texture.Sample(sample_uv);
}
@@ -1,11 +1,10 @@
#language 2026 #language 2026
#include "shared.slang"
struct VertexShaderInput { struct VertexShaderInput {
uint32_t vertex_index : SV_VulkanVertexID; uint32_t vertex_index : SV_VulkanVertexID;
[vk::location(0)] float3 pos;
[vk::location(1)] float2 uv;
// Per Instance // Per Instance
[vk::location(2)] float2 world_pos; [vk::location(2)] float2 world_pos;
}; };
@@ -20,14 +19,27 @@ struct FragmentShaderOutput {
float4 color : SV_Target; float4 color : SV_Target;
}; };
[vk::binding(0, 1)] ConstantBuffer<float4x4> view_projection_matrix : register(b0, space1);
[shader("vertex")] [shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) { VertexShaderOutput main_vertex(VertexShaderInput input) {
var output: VertexShaderOutput; var output: VertexShaderOutput;
output.pos = mul(float4(input.world_pos + input.pos.xy, 0, 1), view_projection_matrix); var vertex_pos = float2(0, 0);
output.uv = input.uv; var vertex_uv = float2(0, 0);
switch (input.vertex_index) {
case 0: { vertex_pos = float2(-0.5, 0.5); vertex_uv = float2(0, 0); } break;
case 1: { vertex_pos = float2(-0.5, -0.5); vertex_uv = float2(0, 1); } break;
case 2: { vertex_pos = float2( 0.5, -0.5); vertex_uv = float2(1, 1); } break;
case 3: { vertex_pos = float2(-0.5, 0.5); vertex_uv = float2(0, 0); } break;
case 4: { vertex_pos = float2( 0.5, -0.5); vertex_uv = float2(1, 1); } break;
case 5: { vertex_pos = float2( 0.5, 0.5); vertex_uv = float2(1, 0); } break;
default: {}
}
vertex_pos *= 0.5;
output.pos = mul(float4(input.world_pos + vertex_pos, 0, 1), view_projection_matrix);
output.uv = vertex_uv;
return output; return output;
} }
+21 -22
View File
@@ -1,44 +1,43 @@
#language 2026 #language 2026
#include "shared.slang"
struct VertexShaderInput { struct VertexShaderInput {
uint32_t vertex_index : SV_VulkanVertexID; uint32_t vertex_index : SV_VulkanVertexID;
uint32_t instance_index : SV_VulkanInstanceID;
[vk::location(0)] float3 pos;
}; };
struct VertexShaderOutput { struct VertexShaderOutput {
float4 pos : SV_Position; float4 pos : SV_Position;
int selected; nointerpolation int2 selection_min;
nointerpolation int2 selection_max;
float2 tile_pos;
}; };
struct FragmentShaderOutput { struct FragmentShaderOutput {
float4 color : SV_Target; float4 color : SV_Target;
}; };
struct Per_Frame_Data {
int2 drag_start;
int2 mouse;
float2 grid_offset;
uint32_t grid_width;
uint32_t map_width;
};
[vk::binding(0, 1)] ConstantBuffer<float4x4> view_projection_matrix : register(b0, space1);
[vk::binding(1, 1)] ConstantBuffer<Per_Frame_Data> per_frame : register(b1, space1);
[shader("vertex")] [shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) { VertexShaderOutput main_vertex(VertexShaderInput input) {
var output: VertexShaderOutput; var output: VertexShaderOutput;
output.selection_min = min(per_frame.drag_start, per_frame.mouse);
output.selection_max = max(per_frame.drag_start, per_frame.mouse);
let tile_pos = float2(float(input.instance_index % per_frame.grid_width), float(input.instance_index / per_frame.grid_width)); let vertex_pos = select(input.vertex_index < (per_frame.grid_height + 1) * 2,
output.pos = mul(float4(tile_pos + per_frame.grid_offset + input.pos.xy, 0, 1), view_projection_matrix); select(input.vertex_index % 2 == 0,
float2( 0, input.vertex_index / 2),
float2(per_frame.grid_width, input.vertex_index / 2)
),
select(input.vertex_index % 2 == 0,
float2((input.vertex_index % ((per_frame.grid_height + 1) * 2)) / 2, 0),
float2((input.vertex_index % ((per_frame.grid_height + 1) * 2)) / 2, per_frame.grid_height)
)
);
let pos = int2(tile_pos + round(per_frame.grid_offset)); output.pos = mul(float4(vertex_pos + per_frame.grid_offset - float2(0.5, 0.5), 0, 1), view_projection_matrix);
let selection_min = min(per_frame.drag_start, per_frame.mouse); output.tile_pos = vertex_pos + round(per_frame.grid_offset);
let selection_max = max(per_frame.drag_start, per_frame.mouse);
output.selected = select(all(pos >= selection_min) && all(pos <= selection_max), 1, 0);
return output; return output;
} }
@@ -50,7 +49,7 @@ static const float4 selected_color = float4(1.0, 0.0, 1.0, 1.0);
FragmentShaderOutput main_fragment(VertexShaderOutput input) { FragmentShaderOutput main_fragment(VertexShaderOutput input) {
var output: FragmentShaderOutput; var output: FragmentShaderOutput;
output.color = input.selected != 0 ? selected_color : color; output.color = select(all(input.tile_pos >= (input.selection_min - float2(0.01, 0.01))) && all(input.tile_pos <= (input.selection_max + float2(1.01, 1.01))), selected_color, color);
return output; return output;
} }
+11
View File
@@ -0,0 +1,11 @@
struct Per_Frame_Data {
int2 drag_start;
int2 mouse;
float2 grid_offset;
uint32_t grid_width;
uint32_t map_width;
uint32_t grid_height;
};
[vk::binding(0, 1)] ConstantBuffer<float4x4> view_projection_matrix : register(b0, space1);
[vk::binding(1, 1)] ConstantBuffer<Per_Frame_Data> per_frame : register(b1, space1);
+86
View File
@@ -0,0 +1,86 @@
#language 2026
#include "shared.slang"
#include "wgsl_workaround.slang"
struct VertexShaderInput {
uint32_t vertex_index : SV_VulkanVertexID;
uint32_t instance_index : SV_VulkanInstanceID;
// Per Instance
[vk::location(0)] uint32_t2 pos;
[vk::location(1)] uint32_t kind;
};
struct VertexShaderOutput {
float4 pos : SV_Position;
float2 uv;
uint32_t kind;
};
struct FragmentShaderOutput {
float4 color : SV_Target;
};
static const float2 offset = float2(0, 0.25);
[shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) {
var output: VertexShaderOutput;
var vertex_pos = float2(0, 0);
var vertex_uv = float2(0, 0);
switch (input.vertex_index) {
case 0: { vertex_pos = float2(-1.0, 1.0); vertex_uv = float2(0, 0); } break;
case 1: { vertex_pos = float2(-1.0, -1.0); vertex_uv = float2(0, 1); } break;
case 2: { vertex_pos = float2( 1.0, -1.0); vertex_uv = float2(1, 1); } break;
case 3: { vertex_pos = float2(-1.0, 1.0); vertex_uv = float2(0, 0); } break;
case 4: { vertex_pos = float2( 1.0, -1.0); vertex_uv = float2(1, 1); } break;
case 5: { vertex_pos = float2( 1.0, 1.0); vertex_uv = float2(1, 0); } break;
default: {}
}
vertex_pos += offset;
output.pos = mul(float4(input.pos + vertex_pos, 0, 1), view_projection_matrix);
output.uv = vertex_uv;
output.kind = input.kind;
return output;
}
struct Block2 {
CombinedTextureSampler tree_atlas;
StructuredBuffer<float4> tree_uvs;
};
struct Block3 {
ConstantBuffer<float3> tint;
};
[vk::binding(0, 2)] ParameterBlock<Block2> block2;
[vk::binding(0, 3)]ParameterBlock<Block3> block3;
[shader("pixel")]
FragmentShaderOutput main_fragment(VertexShaderOutput input) {
var output: FragmentShaderOutput;
output.color = pixel_art_sample(block2.tree_atlas, input.uv, block2.tree_uvs[input.kind]);
output.color = float4(output.color.rgb * block3.tint.rgb, output.color.a);
return output;
}
float4 pixel_art_sample(CombinedTextureSampler input_texture, float2 input_uv, float4 tree_uv) {
var dimensions : float2;
input_texture.getTexture().GetDimensions(dimensions.x, dimensions.y);
let texture_uv = lerp(tree_uv.xy, tree_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, (tree_uv.xy + 0.5) / dimensions, (tree_uv.zw - 0.5) / dimensions);
return input_texture.Sample(uv);
}
+17 -28
View File
@@ -1,5 +1,6 @@
#language 2026 #language 2026
#include "shared.slang"
#include "wgsl_workaround.slang" #include "wgsl_workaround.slang"
struct VertexShaderInput { struct VertexShaderInput {
@@ -18,44 +19,32 @@ struct FragmentShaderOutput {
float4 color : SV_Target; float4 color : SV_Target;
}; };
struct Per_Frame_Data { [format("r16ui")]
int2 drag_start; [vk::binding(0, 0)] Texture2D<uint32_t> map_texture;
int2 mouse;
float2 grid_offset;
uint32_t grid_width;
uint32_t map_width;
};
struct Block0 {
[format("r16ui")]
Texture2D<uint32_t> map_texture;
};
struct Block1 {
ConstantBuffer<float4x4> view_projection_matrix;
ConstantBuffer<Per_Frame_Data> per_frame;
};
ParameterBlock<Block0> block0;
ParameterBlock<Block1> block1;
[shader("vertex")] [shader("vertex")]
VertexShaderOutput main_vertex(VertexShaderInput input) { VertexShaderOutput main_vertex(VertexShaderInput input) {
var output: VertexShaderOutput; var output: VertexShaderOutput;
let tile_pos = uint32_t2(input.instance_index % block1.per_frame.map_width, input.instance_index / block1.per_frame.map_width); var vertex_pos = float2(0, 0);
output.tile = block0.map_texture.Load(uint32_t3(tile_pos, 0)); var vertex_uv = float2(0, 0);
switch (input.vertex_index) { switch (input.vertex_index) {
case 0: { output.pos = mul(float4(float2(tile_pos) - float2(0.5, 0.5) + float2(-0.5, 0.5), 0, 1), block1.view_projection_matrix); output.uv = float2(0, 0); } break; case 0: { vertex_pos = float2(-1.0, 0.0); vertex_uv = float2(0, 0); } break;
case 1: { output.pos = mul(float4(float2(tile_pos) - float2(0.5, 0.5) + float2(-0.5, -0.5), 0, 1), block1.view_projection_matrix); output.uv = float2(0, 1); } break; case 1: { vertex_pos = float2(-1.0, -1.0); vertex_uv = float2(0, 1); } break;
case 2: { output.pos = mul(float4(float2(tile_pos) - float2(0.5, 0.5) + float2( 0.5, -0.5), 0, 1), block1.view_projection_matrix); output.uv = float2(1, 1); } break; case 2: { vertex_pos = float2( 0.0, -1.0); vertex_uv = float2(1, 1); } break;
case 3: { output.pos = mul(float4(float2(tile_pos) - float2(0.5, 0.5) + float2(-0.5, 0.5), 0, 1), block1.view_projection_matrix); output.uv = float2(0, 0); } break; case 3: { vertex_pos = float2(-1.0, 0.0); vertex_uv = float2(0, 0); } break;
case 4: { output.pos = mul(float4(float2(tile_pos) - float2(0.5, 0.5) + float2( 0.5, -0.5), 0, 1), block1.view_projection_matrix); output.uv = float2(1, 1); } break; case 4: { vertex_pos = float2( 0.0, -1.0); vertex_uv = float2(1, 1); } break;
case 5: { output.pos = mul(float4(float2(tile_pos) - float2(0.5, 0.5) + float2( 0.5, 0.5), 0, 1), block1.view_projection_matrix); output.uv = float2(1, 0); } break; case 5: { vertex_pos = float2( 0.0, 0.0); vertex_uv = float2(1, 0); } break;
default: {} default: {}
} }
let tile_pos = uint32_t2(input.instance_index % per_frame.map_width, input.instance_index / per_frame.map_width);
output.tile = map_texture.Load(uint32_t3(tile_pos, 0));
output.pos = mul(float4(tile_pos + vertex_pos, 0, 1), view_projection_matrix);
output.uv = vertex_uv;
return output; return output;
} }
+116
View File
@@ -0,0 +1,116 @@
struct _MatrixStorage_float4x4_ColMajorstd140_0
{
@align(16) data_0 : array<vec4<f32>, i32(4)>,
};
@binding(0) @group(1) var<uniform> view_projection_matrix_0 : _MatrixStorage_float4x4_ColMajorstd140_0;
@binding(0) @group(2) var texture1_texture_0 : texture_2d<f32>;
@binding(1) @group(2) var texture1_sampler_0 : sampler;
@binding(0) @group(3) var<uniform> tint_0 : vec3<f32>;
struct VertexShaderOutput_0
{
@builtin(position) pos_0 : vec4<f32>,
@location(0) uv_0 : vec2<f32>,
};
struct vertexInput_0
{
@location(2) world_pos_0 : vec2<f32>,
@location(3) sprite_selection_0 : u32,
};
@vertex
fn main_vertex( _S1 : vertexInput_0, @builtin(vertex_index) vertex_index_0 : u32) -> VertexShaderOutput_0
{
var output_0 : VertexShaderOutput_0;
const _S2 : vec2<f32> = vec2<f32>(0.0f, 0.0f);
var vertex_pos_0 : vec2<f32>;
var vertex_uv_0 : vec2<f32>;
switch(vertex_index_0)
{
case u32(0):
{
vertex_pos_0 = vec2<f32>(-0.5f, 0.5f);
vertex_uv_0 = _S2;
}
case u32(1):
{
const _S3 : vec2<f32> = vec2<f32>(0.0f, 1.0f);
vertex_pos_0 = vec2<f32>(-0.5f, -0.5f);
vertex_uv_0 = _S3;
}
case u32(2):
{
const _S4 : vec2<f32> = vec2<f32>(1.0f, 1.0f);
vertex_pos_0 = vec2<f32>(0.5f, -0.5f);
vertex_uv_0 = _S4;
}
case u32(3):
{
vertex_pos_0 = vec2<f32>(-0.5f, 0.5f);
vertex_uv_0 = _S2;
}
case u32(4):
{
const _S5 : vec2<f32> = vec2<f32>(1.0f, 1.0f);
vertex_pos_0 = vec2<f32>(0.5f, -0.5f);
vertex_uv_0 = _S5;
}
case u32(5):
{
const _S6 : vec2<f32> = vec2<f32>(1.0f, 0.0f);
vertex_pos_0 = vec2<f32>(0.5f, 0.5f);
vertex_uv_0 = _S6;
}
default :
{
vertex_pos_0 = _S2;
vertex_uv_0 = _S2;
}
}
output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(_S1.world_pos_0 + vertex_pos_0 + vec2<f32>(0.0f, 0.34999999403953552f), 0.0f, 1.0f))));
output_0.uv_0 = (vec2<f32>(f32((u32(_S1.sprite_selection_0>>(u32(16)))&((((u32(1)<<u32(16))-u32(1)))))), f32((u32(_S1.sprite_selection_0>>(u32(0)))&((((u32(1)<<u32(16))-u32(1))))))) + vertex_uv_0) * vec2<f32>(0.25f);
return output_0;
}
fn GetDimensions_0( texture_texture_0 : texture_2d<f32>, texture_sampler_0 : sampler, width_0 : ptr<function, f32>, height_0 : ptr<function, f32>)
{
{var dim = textureDimensions((texture_texture_0));(((*width_0))) = f32(dim.x);(((*height_0))) = f32(dim.y);};
return;
}
fn pixel_art_sample_0( input_texture_texture_0 : texture_2d<f32>, input_texture_sampler_0 : sampler, input_uv_0 : vec2<f32>) -> vec4<f32>
{
var dimensions_0 : vec2<f32>;
var _S7 : f32 = dimensions_0[i32(0)];
var _S8 : f32 = dimensions_0[i32(1)];
GetDimensions_0(input_texture_texture_0, input_texture_sampler_0, &(_S7), &(_S8));
dimensions_0[i32(0)] = _S7;
dimensions_0[i32(1)] = _S8;
var _S9 : vec2<f32> = input_uv_0 * dimensions_0.xy;
var _S10 : vec2<f32> = (floor(_S9) + min(fract(_S9) / (fwidth((_S9))), vec2<f32>(1.0f, 1.0f)) - vec2<f32>(0.5f)) / dimensions_0.xy;
;
return (textureSample((input_texture_texture_0), (input_texture_sampler_0), (_S10)));
}
struct FragmentShaderOutput_0
{
@location(0) color_0 : vec4<f32>,
};
struct pixelInput_0
{
@location(0) uv_1 : vec2<f32>,
};
@fragment
fn main_fragment( _S11 : pixelInput_0, @builtin(position) pos_1 : vec4<f32>) -> FragmentShaderOutput_0
{
var output_1 : FragmentShaderOutput_0;
var _S12 : vec4<f32> = pixel_art_sample_0(texture1_texture_0, texture1_sampler_0, _S11.uv_1);
output_1.color_0 = vec4<f32>(_S12.xyz * tint_0.xyz, _S12.w);
return output_1;
}
@@ -17,8 +17,6 @@ struct VertexShaderOutput_0
struct vertexInput_0 struct vertexInput_0
{ {
@location(0) pos_1 : vec3<f32>,
@location(1) uv_1 : vec2<f32>,
@location(2) world_pos_0 : vec2<f32>, @location(2) world_pos_0 : vec2<f32>,
}; };
@@ -26,8 +24,55 @@ struct vertexInput_0
fn main_vertex( _S1 : vertexInput_0, @builtin(vertex_index) vertex_index_0 : u32) -> VertexShaderOutput_0 fn main_vertex( _S1 : vertexInput_0, @builtin(vertex_index) vertex_index_0 : u32) -> VertexShaderOutput_0
{ {
var output_0 : VertexShaderOutput_0; var output_0 : VertexShaderOutput_0;
output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(_S1.world_pos_0 + _S1.pos_1.xy, 0.0f, 1.0f)))); const _S2 : vec2<f32> = vec2<f32>(0.0f, 0.0f);
output_0.uv_0 = _S1.uv_1; var vertex_uv_0 : vec2<f32>;
var vertex_pos_0 : vec2<f32>;
switch(vertex_index_0)
{
case u32(0):
{
const _S3 : vec2<f32> = vec2<f32>(-0.5f, 0.5f);
vertex_uv_0 = _S2;
vertex_pos_0 = _S3;
}
case u32(1):
{
const _S4 : vec2<f32> = vec2<f32>(-0.5f, -0.5f);
vertex_uv_0 = vec2<f32>(0.0f, 1.0f);
vertex_pos_0 = _S4;
}
case u32(2):
{
const _S5 : vec2<f32> = vec2<f32>(0.5f, -0.5f);
vertex_uv_0 = vec2<f32>(1.0f, 1.0f);
vertex_pos_0 = _S5;
}
case u32(3):
{
const _S6 : vec2<f32> = vec2<f32>(-0.5f, 0.5f);
vertex_uv_0 = _S2;
vertex_pos_0 = _S6;
}
case u32(4):
{
const _S7 : vec2<f32> = vec2<f32>(0.5f, -0.5f);
vertex_uv_0 = vec2<f32>(1.0f, 1.0f);
vertex_pos_0 = _S7;
}
case u32(5):
{
const _S8 : vec2<f32> = vec2<f32>(0.5f, 0.5f);
vertex_uv_0 = vec2<f32>(1.0f, 0.0f);
vertex_pos_0 = _S8;
}
default :
{
vertex_uv_0 = _S2;
vertex_pos_0 = _S2;
}
}
output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(_S1.world_pos_0 + vertex_pos_0 * vec2<f32>(0.5f), 0.0f, 1.0f))));
output_0.uv_0 = vertex_uv_0;
return output_0; return output_0;
} }
@@ -40,15 +85,15 @@ fn GetDimensions_0( texture_texture_0 : texture_2d<f32>, texture_sampler_0 : sa
fn pixel_art_sample_0( input_texture_texture_0 : texture_2d<f32>, input_texture_sampler_0 : sampler, input_uv_0 : vec2<f32>) -> vec4<f32> fn pixel_art_sample_0( input_texture_texture_0 : texture_2d<f32>, input_texture_sampler_0 : sampler, input_uv_0 : vec2<f32>) -> vec4<f32>
{ {
var dimensions_0 : vec2<f32>; var dimensions_0 : vec2<f32>;
var _S2 : f32 = dimensions_0[i32(0)]; var _S9 : f32 = dimensions_0[i32(0)];
var _S3 : f32 = dimensions_0[i32(1)]; var _S10 : f32 = dimensions_0[i32(1)];
GetDimensions_0(input_texture_texture_0, input_texture_sampler_0, &(_S2), &(_S3)); GetDimensions_0(input_texture_texture_0, input_texture_sampler_0, &(_S9), &(_S10));
dimensions_0[i32(0)] = _S2; dimensions_0[i32(0)] = _S9;
dimensions_0[i32(1)] = _S3; dimensions_0[i32(1)] = _S10;
var _S4 : vec2<f32> = input_uv_0 * dimensions_0.xy; var _S11 : vec2<f32> = input_uv_0 * dimensions_0.xy;
var _S5 : vec2<f32> = (floor(_S4) + min(fract(_S4) / (fwidth((_S4))), vec2<f32>(1.0f, 1.0f)) - vec2<f32>(0.5f)) / dimensions_0.xy; var _S12 : vec2<f32> = (floor(_S11) + min(fract(_S11) / (fwidth((_S11))), vec2<f32>(1.0f, 1.0f)) - vec2<f32>(0.5f)) / dimensions_0.xy;
; ;
return (textureSample((input_texture_texture_0), (input_texture_sampler_0), (_S5))); return (textureSample((input_texture_texture_0), (input_texture_sampler_0), (_S12)));
} }
struct FragmentShaderOutput_0 struct FragmentShaderOutput_0
@@ -58,15 +103,15 @@ struct FragmentShaderOutput_0
struct pixelInput_0 struct pixelInput_0
{ {
@location(0) uv_2 : vec2<f32>, @location(0) uv_1 : vec2<f32>,
}; };
@fragment @fragment
fn main_fragment( _S6 : pixelInput_0, @builtin(position) pos_2 : vec4<f32>) -> FragmentShaderOutput_0 fn main_fragment( _S13 : pixelInput_0, @builtin(position) pos_1 : vec4<f32>) -> FragmentShaderOutput_0
{ {
var output_1 : FragmentShaderOutput_0; var output_1 : FragmentShaderOutput_0;
var _S7 : vec4<f32> = pixel_art_sample_0(texture1_texture_0, texture1_sampler_0, _S6.uv_2); var _S14 : vec4<f32> = pixel_art_sample_0(texture1_texture_0, texture1_sampler_0, _S13.uv_1);
output_1.color_0 = vec4<f32>(_S7.xyz * tint_0.xyz, _S7.w); output_1.color_0 = vec4<f32>(_S14.xyz * tint_0.xyz, _S14.w);
return output_1; return output_1;
} }
+25 -31
View File
@@ -5,6 +5,7 @@ struct Per_Frame_Data_std140_0
@align(16) grid_offset_0 : vec2<f32>, @align(16) grid_offset_0 : vec2<f32>,
@align(8) grid_width_0 : u32, @align(8) grid_width_0 : u32,
@align(4) map_width_0 : u32, @align(4) map_width_0 : u32,
@align(16) grid_height_0 : u32,
}; };
@binding(1) @group(1) var<uniform> per_frame_0 : Per_Frame_Data_std140_0; @binding(1) @group(1) var<uniform> per_frame_0 : Per_Frame_Data_std140_0;
@@ -17,35 +18,26 @@ struct _MatrixStorage_float4x4_ColMajorstd140_0
struct VertexShaderOutput_0 struct VertexShaderOutput_0
{ {
@builtin(position) pos_0 : vec4<f32>, @builtin(position) pos_0 : vec4<f32>,
@location(0) selected_0 : i32, @interpolate(flat) @location(0) selection_min_0 : vec2<i32>,
}; @interpolate(flat) @location(1) selection_max_0 : vec2<i32>,
@location(2) tile_pos_0 : vec2<f32>,
struct vertexInput_0
{
@location(0) pos_1 : vec3<f32>,
}; };
@vertex @vertex
fn main_vertex( _S1 : vertexInput_0, @builtin(vertex_index) vertex_index_0 : u32, @builtin(instance_index) instance_index_0 : u32) -> VertexShaderOutput_0 fn main_vertex(@builtin(vertex_index) vertex_index_0 : u32) -> VertexShaderOutput_0
{ {
var _S2 : u32 = instance_index_0 % per_frame_0.grid_width_0;
var _S3 : f32 = f32(_S2);
var _S4 : u32 = instance_index_0 / per_frame_0.grid_width_0;
var _S5 : vec2<f32> = vec2<f32>(_S3, f32(_S4));
var output_0 : VertexShaderOutput_0; var output_0 : VertexShaderOutput_0;
output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(_S5 + per_frame_0.grid_offset_0 + _S1.pos_1.xy, 0.0f, 1.0f)))); output_0.selection_min_0 = min(per_frame_0.drag_start_0, per_frame_0.mouse_0);
var _S6 : vec2<i32> = vec2<i32>(_S5 + round(per_frame_0.grid_offset_0)); output_0.selection_max_0 = max(per_frame_0.drag_start_0, per_frame_0.mouse_0);
var _S7 : vec2<i32> = max(per_frame_0.drag_start_0, per_frame_0.mouse_0); var _S1 : bool = vertex_index_0 < ((per_frame_0.grid_height_0 + u32(1)) * u32(2));
var _S8 : bool; var _S2 : bool = (vertex_index_0 % u32(2)) == u32(0);
if((all((_S6 >= (min(per_frame_0.drag_start_0, per_frame_0.mouse_0)))))) var _S3 : vec2<f32> = select(vec2<f32>(f32(per_frame_0.grid_width_0), f32(vertex_index_0 / u32(2))), vec2<f32>(0.0f, f32(vertex_index_0 / u32(2))), _S2);
{ var _S4 : u32 = vertex_index_0 % ((per_frame_0.grid_height_0 + u32(1)) * u32(2));
_S8 = (all((_S6 <= _S7))); var _S5 : vec2<f32> = vec2<f32>(f32(_S4 / u32(2)), 0.0f);
} var _S6 : u32 = vertex_index_0 % ((per_frame_0.grid_height_0 + u32(1)) * u32(2));
else var _S7 : vec2<f32> = select(select(vec2<f32>(f32(_S6 / u32(2)), f32(per_frame_0.grid_height_0)), _S5, _S2), _S3, _S1);
{ output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(_S7 + per_frame_0.grid_offset_0 - vec2<f32>(0.5f, 0.5f), 0.0f, 1.0f))));
_S8 = false; output_0.tile_pos_0 = _S7 + round(per_frame_0.grid_offset_0);
}
output_0.selected_0 = select(i32(0), i32(1), _S8);
return output_0; return output_0;
} }
@@ -56,23 +48,25 @@ struct FragmentShaderOutput_0
struct pixelInput_0 struct pixelInput_0
{ {
@location(0) selected_1 : i32, @interpolate(flat) @location(0) selection_min_1 : vec2<i32>,
@interpolate(flat) @location(1) selection_max_1 : vec2<i32>,
@location(2) tile_pos_1 : vec2<f32>,
}; };
@fragment @fragment
fn main_fragment( _S9 : pixelInput_0, @builtin(position) pos_2 : vec4<f32>) -> FragmentShaderOutput_0 fn main_fragment( _S8 : pixelInput_0, @builtin(position) pos_1 : vec4<f32>) -> FragmentShaderOutput_0
{ {
var output_1 : FragmentShaderOutput_0; var output_1 : FragmentShaderOutput_0;
var _S10 : vec4<f32>; var _S9 : bool;
if((_S9.selected_1) != i32(0)) if((all(((_S8.tile_pos_1) >= (vec2<f32>(_S8.selection_min_1) - vec2<f32>(0.00999999977648258f, 0.00999999977648258f))))))
{ {
_S10 = vec4<f32>(1.0f, 0.0f, 1.0f, 1.0f); _S9 = (all(((_S8.tile_pos_1) <= (vec2<f32>(_S8.selection_max_1) + vec2<f32>(1.00999999046325684f, 1.00999999046325684f)))));
} }
else else
{ {
_S10 = vec4<f32>(1.0f, 1.0f, 1.0f, 0.10000000149011612f); _S9 = false;
} }
output_1.color_0 = _S10; output_1.color_0 = select(vec4<f32>(1.0f, 1.0f, 1.0f, 0.10000000149011612f), vec4<f32>(1.0f, 0.0f, 1.0f, 1.0f), _S9);
return output_1; return output_1;
} }
+123
View File
@@ -0,0 +1,123 @@
struct _MatrixStorage_float4x4_ColMajorstd140_0
{
@align(16) data_0 : array<vec4<f32>, i32(4)>,
};
@binding(0) @group(1) var<uniform> view_projection_matrix_0 : _MatrixStorage_float4x4_ColMajorstd140_0;
@binding(0) @group(2) var block2_tree_atlas_texture_0 : texture_2d<f32>;
@binding(1) @group(2) var block2_tree_atlas_sampler_0 : sampler;
@binding(2) @group(2) var<storage, read> block2_tree_uvs_0 : array<vec4<f32>>;
@binding(0) @group(3) var<uniform> block3_tint_0 : vec3<f32>;
struct VertexShaderOutput_0
{
@builtin(position) pos_0 : vec4<f32>,
@location(0) uv_0 : vec2<f32>,
@location(1) kind_0 : u32,
};
struct vertexInput_0
{
@location(0) pos_1 : vec2<u32>,
@location(1) kind_1 : u32,
};
@vertex
fn main_vertex( _S1 : vertexInput_0, @builtin(vertex_index) vertex_index_0 : u32, @builtin(instance_index) instance_index_0 : u32) -> VertexShaderOutput_0
{
var output_0 : VertexShaderOutput_0;
const _S2 : vec2<f32> = vec2<f32>(0.0f, 0.0f);
var vertex_uv_0 : vec2<f32>;
var vertex_pos_0 : vec2<f32>;
switch(vertex_index_0)
{
case u32(0):
{
const _S3 : vec2<f32> = vec2<f32>(-1.0f, 1.0f);
vertex_uv_0 = _S2;
vertex_pos_0 = _S3;
}
case u32(1):
{
const _S4 : vec2<f32> = vec2<f32>(-1.0f, -1.0f);
vertex_uv_0 = vec2<f32>(0.0f, 1.0f);
vertex_pos_0 = _S4;
}
case u32(2):
{
const _S5 : vec2<f32> = vec2<f32>(1.0f, -1.0f);
vertex_uv_0 = vec2<f32>(1.0f, 1.0f);
vertex_pos_0 = _S5;
}
case u32(3):
{
const _S6 : vec2<f32> = vec2<f32>(-1.0f, 1.0f);
vertex_uv_0 = _S2;
vertex_pos_0 = _S6;
}
case u32(4):
{
const _S7 : vec2<f32> = vec2<f32>(1.0f, -1.0f);
vertex_uv_0 = vec2<f32>(1.0f, 1.0f);
vertex_pos_0 = _S7;
}
case u32(5):
{
const _S8 : vec2<f32> = vec2<f32>(1.0f, 1.0f);
vertex_uv_0 = vec2<f32>(1.0f, 0.0f);
vertex_pos_0 = _S8;
}
default :
{
vertex_uv_0 = _S2;
vertex_pos_0 = _S2;
}
}
output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S1.pos_1) + (vertex_pos_0 + vec2<f32>(0.0f, 0.25f)), 0.0f, 1.0f))));
output_0.uv_0 = vertex_uv_0;
output_0.kind_0 = _S1.kind_1;
return output_0;
}
fn CombinedTextureSampler_Sample_0( this_texture_0 : texture_2d<f32>, this_sampler_0 : sampler, location_0 : vec2<f32>) -> vec4<f32>
{
return (textureSample((this_texture_0), (this_sampler_0), (location_0)));
}
fn pixel_art_sample_0( input_texture_texture_0 : texture_2d<f32>, input_texture_sampler_0 : sampler, input_uv_0 : vec2<f32>, tree_uv_0 : vec4<f32>) -> vec4<f32>
{
var dimensions_0 : vec2<f32>;
var _S9 : f32 = dimensions_0[i32(0)];
var _S10 : f32 = dimensions_0[i32(1)];
{var dim = textureDimensions((input_texture_texture_0));((_S9)) = f32(dim.x);((_S10)) = f32(dim.y);};
dimensions_0[i32(0)] = _S9;
dimensions_0[i32(1)] = _S10;
var _S11 : vec2<f32> = tree_uv_0.xy;
var _S12 : vec2<f32> = tree_uv_0.zw;
var _S13 : vec2<f32> = mix(_S11, _S12, input_uv_0);
var _S14 : vec2<f32> = vec2<f32>(0.5f);
return CombinedTextureSampler_Sample_0(input_texture_texture_0, input_texture_sampler_0, clamp((floor(_S13) + saturate(fract(_S13) / (fwidth((_S13)))) - _S14) / dimensions_0, (_S11 + _S14) / dimensions_0, (_S12 - _S14) / dimensions_0));
}
struct FragmentShaderOutput_0
{
@location(0) color_0 : vec4<f32>,
};
struct pixelInput_0
{
@location(0) uv_1 : vec2<f32>,
@location(1) kind_2 : u32,
};
@fragment
fn main_fragment( _S15 : pixelInput_0, @builtin(position) pos_2 : vec4<f32>) -> FragmentShaderOutput_0
{
var output_1 : FragmentShaderOutput_0;
var _S16 : vec4<f32> = pixel_art_sample_0(block2_tree_atlas_texture_0, block2_tree_atlas_sampler_0, _S15.uv_1, block2_tree_uvs_0[_S15.kind_2]);
output_1.color_0 = vec4<f32>(_S16.xyz * block3_tint_0.xyz, _S16.w);
return output_1;
}
+50 -46
View File
@@ -1,9 +1,3 @@
struct _MatrixStorage_float4x4_ColMajorstd140_0
{
@align(16) data_0 : array<vec4<f32>, i32(4)>,
};
@binding(0) @group(1) var<uniform> block1_view_projection_matrix_0 : _MatrixStorage_float4x4_ColMajorstd140_0;
struct Per_Frame_Data_std140_0 struct Per_Frame_Data_std140_0
{ {
@align(16) drag_start_0 : vec2<i32>, @align(16) drag_start_0 : vec2<i32>,
@@ -11,11 +5,18 @@ struct Per_Frame_Data_std140_0
@align(16) grid_offset_0 : vec2<f32>, @align(16) grid_offset_0 : vec2<f32>,
@align(8) grid_width_0 : u32, @align(8) grid_width_0 : u32,
@align(4) map_width_0 : u32, @align(4) map_width_0 : u32,
@align(16) grid_height_0 : u32,
}; };
@binding(1) @group(1) var<uniform> block1_per_frame_0 : Per_Frame_Data_std140_0; @binding(1) @group(1) var<uniform> per_frame_0 : Per_Frame_Data_std140_0;
@binding(0) @group(0) var block0_map_texture_0 : texture_2d<u32>; @binding(0) @group(0) var map_texture_0 : texture_2d<u32>;
struct _MatrixStorage_float4x4_ColMajorstd140_0
{
@align(16) data_0 : array<vec4<f32>, i32(4)>,
};
@binding(0) @group(1) var<uniform> view_projection_matrix_0 : _MatrixStorage_float4x4_ColMajorstd140_0;
@binding(0) @group(2) var block2_tile_atlas_texture_0 : texture_2d<f32>; @binding(0) @group(2) var block2_tile_atlas_texture_0 : texture_2d<f32>;
@binding(1) @group(2) var block2_tile_atlas_sampler_0 : sampler; @binding(1) @group(2) var block2_tile_atlas_sampler_0 : sampler;
@@ -33,56 +34,59 @@ struct VertexShaderOutput_0
@vertex @vertex
fn main_vertex(@builtin(vertex_index) vertex_index_0 : u32, @builtin(instance_index) instance_index_0 : u32) -> VertexShaderOutput_0 fn main_vertex(@builtin(vertex_index) vertex_index_0 : u32, @builtin(instance_index) instance_index_0 : u32) -> VertexShaderOutput_0
{ {
var _S1 : u32 = instance_index_0 % block1_per_frame_0.map_width_0;
var _S2 : u32 = instance_index_0 / block1_per_frame_0.map_width_0;
var _S3 : vec2<u32> = vec2<u32>(_S1, _S2);
var output_0 : VertexShaderOutput_0; var output_0 : VertexShaderOutput_0;
var _S4 : vec3<i32> = vec3<i32>(vec3<u32>(_S3, u32(0))); const _S1 : vec2<f32> = vec2<f32>(0.0f, 0.0f);
output_0.tile_0 = (textureLoad((block0_map_texture_0), ((_S4)).xy, ((_S4)).z).x); var vertex_pos_0 : vec2<f32>;
var vertex_uv_0 : vec2<f32>;
switch(vertex_index_0) switch(vertex_index_0)
{ {
case u32(0): case u32(0):
{ {
output_0.pos_0 = (((mat4x4<f32>(block1_view_projection_matrix_0.data_0[i32(0)][i32(0)], block1_view_projection_matrix_0.data_0[i32(1)][i32(0)], block1_view_projection_matrix_0.data_0[i32(2)][i32(0)], block1_view_projection_matrix_0.data_0[i32(3)][i32(0)], block1_view_projection_matrix_0.data_0[i32(0)][i32(1)], block1_view_projection_matrix_0.data_0[i32(1)][i32(1)], block1_view_projection_matrix_0.data_0[i32(2)][i32(1)], block1_view_projection_matrix_0.data_0[i32(3)][i32(1)], block1_view_projection_matrix_0.data_0[i32(0)][i32(2)], block1_view_projection_matrix_0.data_0[i32(1)][i32(2)], block1_view_projection_matrix_0.data_0[i32(2)][i32(2)], block1_view_projection_matrix_0.data_0[i32(3)][i32(2)], block1_view_projection_matrix_0.data_0[i32(0)][i32(3)], block1_view_projection_matrix_0.data_0[i32(1)][i32(3)], block1_view_projection_matrix_0.data_0[i32(2)][i32(3)], block1_view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S3) - vec2<f32>(0.5f, 0.5f) + vec2<f32>(-0.5f, 0.5f), 0.0f, 1.0f)))); vertex_pos_0 = vec2<f32>(-1.0f, 0.0f);
output_0.uv_0 = vec2<f32>(0.0f, 0.0f); vertex_uv_0 = _S1;
break;
} }
case u32(1): case u32(1):
{ {
output_0.pos_0 = (((mat4x4<f32>(block1_view_projection_matrix_0.data_0[i32(0)][i32(0)], block1_view_projection_matrix_0.data_0[i32(1)][i32(0)], block1_view_projection_matrix_0.data_0[i32(2)][i32(0)], block1_view_projection_matrix_0.data_0[i32(3)][i32(0)], block1_view_projection_matrix_0.data_0[i32(0)][i32(1)], block1_view_projection_matrix_0.data_0[i32(1)][i32(1)], block1_view_projection_matrix_0.data_0[i32(2)][i32(1)], block1_view_projection_matrix_0.data_0[i32(3)][i32(1)], block1_view_projection_matrix_0.data_0[i32(0)][i32(2)], block1_view_projection_matrix_0.data_0[i32(1)][i32(2)], block1_view_projection_matrix_0.data_0[i32(2)][i32(2)], block1_view_projection_matrix_0.data_0[i32(3)][i32(2)], block1_view_projection_matrix_0.data_0[i32(0)][i32(3)], block1_view_projection_matrix_0.data_0[i32(1)][i32(3)], block1_view_projection_matrix_0.data_0[i32(2)][i32(3)], block1_view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S3) - vec2<f32>(0.5f, 0.5f) + vec2<f32>(-0.5f, -0.5f), 0.0f, 1.0f)))); const _S2 : vec2<f32> = vec2<f32>(0.0f, 1.0f);
output_0.uv_0 = vec2<f32>(0.0f, 1.0f); vertex_pos_0 = vec2<f32>(-1.0f, -1.0f);
break; vertex_uv_0 = _S2;
} }
case u32(2): case u32(2):
{ {
output_0.pos_0 = (((mat4x4<f32>(block1_view_projection_matrix_0.data_0[i32(0)][i32(0)], block1_view_projection_matrix_0.data_0[i32(1)][i32(0)], block1_view_projection_matrix_0.data_0[i32(2)][i32(0)], block1_view_projection_matrix_0.data_0[i32(3)][i32(0)], block1_view_projection_matrix_0.data_0[i32(0)][i32(1)], block1_view_projection_matrix_0.data_0[i32(1)][i32(1)], block1_view_projection_matrix_0.data_0[i32(2)][i32(1)], block1_view_projection_matrix_0.data_0[i32(3)][i32(1)], block1_view_projection_matrix_0.data_0[i32(0)][i32(2)], block1_view_projection_matrix_0.data_0[i32(1)][i32(2)], block1_view_projection_matrix_0.data_0[i32(2)][i32(2)], block1_view_projection_matrix_0.data_0[i32(3)][i32(2)], block1_view_projection_matrix_0.data_0[i32(0)][i32(3)], block1_view_projection_matrix_0.data_0[i32(1)][i32(3)], block1_view_projection_matrix_0.data_0[i32(2)][i32(3)], block1_view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S3) - vec2<f32>(0.5f, 0.5f) + vec2<f32>(0.5f, -0.5f), 0.0f, 1.0f)))); const _S3 : vec2<f32> = vec2<f32>(1.0f, 1.0f);
output_0.uv_0 = vec2<f32>(1.0f, 1.0f); vertex_pos_0 = vec2<f32>(0.0f, -1.0f);
break; vertex_uv_0 = _S3;
} }
case u32(3): case u32(3):
{ {
output_0.pos_0 = (((mat4x4<f32>(block1_view_projection_matrix_0.data_0[i32(0)][i32(0)], block1_view_projection_matrix_0.data_0[i32(1)][i32(0)], block1_view_projection_matrix_0.data_0[i32(2)][i32(0)], block1_view_projection_matrix_0.data_0[i32(3)][i32(0)], block1_view_projection_matrix_0.data_0[i32(0)][i32(1)], block1_view_projection_matrix_0.data_0[i32(1)][i32(1)], block1_view_projection_matrix_0.data_0[i32(2)][i32(1)], block1_view_projection_matrix_0.data_0[i32(3)][i32(1)], block1_view_projection_matrix_0.data_0[i32(0)][i32(2)], block1_view_projection_matrix_0.data_0[i32(1)][i32(2)], block1_view_projection_matrix_0.data_0[i32(2)][i32(2)], block1_view_projection_matrix_0.data_0[i32(3)][i32(2)], block1_view_projection_matrix_0.data_0[i32(0)][i32(3)], block1_view_projection_matrix_0.data_0[i32(1)][i32(3)], block1_view_projection_matrix_0.data_0[i32(2)][i32(3)], block1_view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S3) - vec2<f32>(0.5f, 0.5f) + vec2<f32>(-0.5f, 0.5f), 0.0f, 1.0f)))); vertex_pos_0 = vec2<f32>(-1.0f, 0.0f);
output_0.uv_0 = vec2<f32>(0.0f, 0.0f); vertex_uv_0 = _S1;
break;
} }
case u32(4): case u32(4):
{ {
output_0.pos_0 = (((mat4x4<f32>(block1_view_projection_matrix_0.data_0[i32(0)][i32(0)], block1_view_projection_matrix_0.data_0[i32(1)][i32(0)], block1_view_projection_matrix_0.data_0[i32(2)][i32(0)], block1_view_projection_matrix_0.data_0[i32(3)][i32(0)], block1_view_projection_matrix_0.data_0[i32(0)][i32(1)], block1_view_projection_matrix_0.data_0[i32(1)][i32(1)], block1_view_projection_matrix_0.data_0[i32(2)][i32(1)], block1_view_projection_matrix_0.data_0[i32(3)][i32(1)], block1_view_projection_matrix_0.data_0[i32(0)][i32(2)], block1_view_projection_matrix_0.data_0[i32(1)][i32(2)], block1_view_projection_matrix_0.data_0[i32(2)][i32(2)], block1_view_projection_matrix_0.data_0[i32(3)][i32(2)], block1_view_projection_matrix_0.data_0[i32(0)][i32(3)], block1_view_projection_matrix_0.data_0[i32(1)][i32(3)], block1_view_projection_matrix_0.data_0[i32(2)][i32(3)], block1_view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S3) - vec2<f32>(0.5f, 0.5f) + vec2<f32>(0.5f, -0.5f), 0.0f, 1.0f)))); const _S4 : vec2<f32> = vec2<f32>(1.0f, 1.0f);
output_0.uv_0 = vec2<f32>(1.0f, 1.0f); vertex_pos_0 = vec2<f32>(0.0f, -1.0f);
break; vertex_uv_0 = _S4;
} }
case u32(5): case u32(5):
{ {
const _S5 : vec2<f32> = vec2<f32>(0.5f, 0.5f); const _S5 : vec2<f32> = vec2<f32>(1.0f, 0.0f);
output_0.pos_0 = (((mat4x4<f32>(block1_view_projection_matrix_0.data_0[i32(0)][i32(0)], block1_view_projection_matrix_0.data_0[i32(1)][i32(0)], block1_view_projection_matrix_0.data_0[i32(2)][i32(0)], block1_view_projection_matrix_0.data_0[i32(3)][i32(0)], block1_view_projection_matrix_0.data_0[i32(0)][i32(1)], block1_view_projection_matrix_0.data_0[i32(1)][i32(1)], block1_view_projection_matrix_0.data_0[i32(2)][i32(1)], block1_view_projection_matrix_0.data_0[i32(3)][i32(1)], block1_view_projection_matrix_0.data_0[i32(0)][i32(2)], block1_view_projection_matrix_0.data_0[i32(1)][i32(2)], block1_view_projection_matrix_0.data_0[i32(2)][i32(2)], block1_view_projection_matrix_0.data_0[i32(3)][i32(2)], block1_view_projection_matrix_0.data_0[i32(0)][i32(3)], block1_view_projection_matrix_0.data_0[i32(1)][i32(3)], block1_view_projection_matrix_0.data_0[i32(2)][i32(3)], block1_view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S3) - _S5 + _S5, 0.0f, 1.0f)))); vertex_pos_0 = _S1;
output_0.uv_0 = vec2<f32>(1.0f, 0.0f); vertex_uv_0 = _S5;
break;
} }
default : default :
{ {
break; vertex_pos_0 = _S1;
vertex_uv_0 = _S1;
} }
} }
var _S6 : u32 = instance_index_0 % per_frame_0.map_width_0;
var _S7 : u32 = instance_index_0 / per_frame_0.map_width_0;
var _S8 : vec2<u32> = vec2<u32>(_S6, _S7);
var _S9 : vec3<i32> = vec3<i32>(vec3<u32>(_S8, u32(0)));
output_0.tile_0 = (textureLoad((map_texture_0), ((_S9)).xy, ((_S9)).z).x);
output_0.pos_0 = (((mat4x4<f32>(view_projection_matrix_0.data_0[i32(0)][i32(0)], view_projection_matrix_0.data_0[i32(1)][i32(0)], view_projection_matrix_0.data_0[i32(2)][i32(0)], view_projection_matrix_0.data_0[i32(3)][i32(0)], view_projection_matrix_0.data_0[i32(0)][i32(1)], view_projection_matrix_0.data_0[i32(1)][i32(1)], view_projection_matrix_0.data_0[i32(2)][i32(1)], view_projection_matrix_0.data_0[i32(3)][i32(1)], view_projection_matrix_0.data_0[i32(0)][i32(2)], view_projection_matrix_0.data_0[i32(1)][i32(2)], view_projection_matrix_0.data_0[i32(2)][i32(2)], view_projection_matrix_0.data_0[i32(3)][i32(2)], view_projection_matrix_0.data_0[i32(0)][i32(3)], view_projection_matrix_0.data_0[i32(1)][i32(3)], view_projection_matrix_0.data_0[i32(2)][i32(3)], view_projection_matrix_0.data_0[i32(3)][i32(3)])) * (vec4<f32>(vec2<f32>(_S8) + vertex_pos_0, 0.0f, 1.0f))));
output_0.uv_0 = vertex_uv_0;
return output_0; return output_0;
} }
@@ -94,16 +98,16 @@ fn CombinedTextureSampler_Sample_0( this_texture_0 : texture_2d<f32>, this_samp
fn pixel_art_sample_0( input_texture_texture_0 : texture_2d<f32>, input_texture_sampler_0 : sampler, input_uv_0 : vec2<f32>, tile_uv_0 : vec4<f32>) -> vec4<f32> fn pixel_art_sample_0( input_texture_texture_0 : texture_2d<f32>, input_texture_sampler_0 : sampler, input_uv_0 : vec2<f32>, tile_uv_0 : vec4<f32>) -> vec4<f32>
{ {
var dimensions_0 : vec2<f32>; var dimensions_0 : vec2<f32>;
var _S6 : f32 = dimensions_0[i32(0)]; var _S10 : f32 = dimensions_0[i32(0)];
var _S7 : f32 = dimensions_0[i32(1)]; var _S11 : f32 = dimensions_0[i32(1)];
{var dim = textureDimensions((input_texture_texture_0));((_S6)) = f32(dim.x);((_S7)) = f32(dim.y);}; {var dim = textureDimensions((input_texture_texture_0));((_S10)) = f32(dim.x);((_S11)) = f32(dim.y);};
dimensions_0[i32(0)] = _S6; dimensions_0[i32(0)] = _S10;
dimensions_0[i32(1)] = _S7; dimensions_0[i32(1)] = _S11;
var _S8 : vec2<f32> = tile_uv_0.xy; var _S12 : vec2<f32> = tile_uv_0.xy;
var _S9 : vec2<f32> = tile_uv_0.zw; var _S13 : vec2<f32> = tile_uv_0.zw;
var _S10 : vec2<f32> = mix(_S8, _S9, input_uv_0); var _S14 : vec2<f32> = mix(_S12, _S13, input_uv_0);
var _S11 : vec2<f32> = vec2<f32>(0.5f); var _S15 : vec2<f32> = vec2<f32>(0.5f);
return CombinedTextureSampler_Sample_0(input_texture_texture_0, input_texture_sampler_0, clamp((floor(_S10) + saturate(fract(_S10) / (fwidth((_S10)))) - _S11) / dimensions_0, (_S8 + _S11) / dimensions_0, (_S9 - _S11) / dimensions_0)); return CombinedTextureSampler_Sample_0(input_texture_texture_0, input_texture_sampler_0, clamp((floor(_S14) + saturate(fract(_S14) / (fwidth((_S14)))) - _S15) / dimensions_0, (_S12 + _S15) / dimensions_0, (_S13 - _S15) / dimensions_0));
} }
struct FragmentShaderOutput_0 struct FragmentShaderOutput_0
@@ -118,11 +122,11 @@ struct pixelInput_0
}; };
@fragment @fragment
fn main_fragment( _S12 : pixelInput_0, @builtin(position) pos_1 : vec4<f32>) -> FragmentShaderOutput_0 fn main_fragment( _S16 : pixelInput_0, @builtin(position) pos_1 : vec4<f32>) -> FragmentShaderOutput_0
{ {
var output_1 : FragmentShaderOutput_0; var output_1 : FragmentShaderOutput_0;
var _S13 : vec4<f32> = pixel_art_sample_0(block2_tile_atlas_texture_0, block2_tile_atlas_sampler_0, _S12.uv_1, block2_tile_uvs_0[_S12.tile_1]); var _S17 : vec4<f32> = pixel_art_sample_0(block2_tile_atlas_texture_0, block2_tile_atlas_sampler_0, _S16.uv_1, block2_tile_uvs_0[_S16.tile_1]);
output_1.color_0 = vec4<f32>(_S13.xyz * block3_tint_0.xyz, _S13.w); output_1.color_0 = vec4<f32>(_S17.xyz * block3_tint_0.xyz, _S17.w);
return output_1; return output_1;
} }