Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a6d9dca
v1
jsoulier Jan 2, 2026
2fb80bc
buffer
jsoulier Jan 2, 2026
de90fc7
voxel
jsoulier Jan 2, 2026
1b88cf1
boilerplate
jsoulier Jan 3, 2026
9630b51
boilerplate
jsoulier Jan 3, 2026
72e7f62
drawing
jsoulier Jan 4, 2026
6d07b78
neighbor lookups
jsoulier Jan 4, 2026
c174aba
workers
jsoulier Jan 4, 2026
55d88f4
dda first pass
jsoulier Jan 4, 2026
cef4169
raycast working
jsoulier Jan 4, 2026
1ebca03
msaa v1
jsoulier Jan 5, 2026
19d5894
save first pass
jsoulier Jan 6, 2026
d781476
lights v1
jsoulier Jan 6, 2026
4871ebb
refactor
jsoulier Jan 8, 2026
115db59
ui
jsoulier Jan 8, 2026
b2448a7
postprocess first pass
jsoulier Jan 9, 2026
df9b28f
ssao v2
jsoulier Jan 9, 2026
b043ee9
postprocessing
jsoulier Jan 9, 2026
9e30609
ssao
jsoulier Jan 10, 2026
2b15a8b
anisotropy
jsoulier Jan 10, 2026
15385c6
blur
jsoulier Jan 10, 2026
10ff762
sky v1
jsoulier Jan 10, 2026
47e9f75
shadows
jsoulier Jan 11, 2026
950d676
transparent
jsoulier Jan 12, 2026
b8b30bc
transparent
jsoulier Jan 12, 2026
64b7894
fully async
jsoulier Jan 13, 2026
58c99fe
threading v2
jsoulier Jan 13, 2026
bbc5619
round 3
jsoulier Jan 13, 2026
f9b34df
improve perf
jsoulier Jan 13, 2026
fd5fce8
remesh immediately on edit
jsoulier Jan 13, 2026
7032fdd
fix lighting
jsoulier Jan 13, 2026
fee9244
refactor
jsoulier Jan 14, 2026
a0bf072
restructuring
jsoulier Jan 14, 2026
123ac22
icon
jsoulier Jan 14, 2026
7bb97b6
shader
jsoulier Jan 14, 2026
019b7f7
job refactor
jsoulier Jan 14, 2026
22256e3
refactor
jsoulier Jan 14, 2026
b4b83e2
refactor
jsoulier Jan 14, 2026
d92ea84
retry run
jsoulier Jan 14, 2026
5cd7555
more
jsoulier Jan 14, 2026
daa9434
more
jsoulier Jan 15, 2026
74647e1
fog pass
jsoulier Jan 15, 2026
b47e2ea
camera
jsoulier Jan 15, 2026
ae47f46
shader
jsoulier Jan 15, 2026
43dd0bb
more
jsoulier Jan 16, 2026
c6e3674
fix sprite normal, fix black outline around sprites
jsoulier Jan 16, 2026
0146ac3
more
jsoulier Jan 16, 2026
896ec2a
fix shadow for sprites
jsoulier Jan 16, 2026
7123cb0
refactor
jsoulier Jan 16, 2026
449abcc
more
jsoulier Jan 17, 2026
f151a13
more
jsoulier Jan 17, 2026
c4fece5
palette
jsoulier Jan 17, 2026
fd06d78
depth shading
jsoulier Jan 17, 2026
a19414b
fixed some more bugs
jsoulier Jan 17, 2026
84ee0b5
mostly done visuals
jsoulier Jan 17, 2026
3e18488
almost
jsoulier Jan 17, 2026
ca5df5e
remove -g
jsoulier Jan 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
lib/** linguist-vendored
*.comp linguist-language=HLSL
*.frag linguist-language=HLSL
*.vert linguist-language=HLSL
lib/** linguist-vendored
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.sqlite3
*.sqlite3-journal
build
93 changes: 47 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,58 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${BINARY_DIR})
make_directory(${BINARY_DIR})

configure_file(LICENSE.txt ${BINARY_DIR} COPYONLY)
configure_file(README.md ${BINARY_DIR} COPYONLY)
configure_file(textures/atlas.png ${BINARY_DIR} COPYONLY)

add_subdirectory(lib/SDL)
add_executable(blocks WIN32
lib/sqlite3/sqlite3.c
lib/stb/stb.c
src/block.c
src/buffer.c
src/camera.c
src/chunk.c
src/database.c
src/helpers.c
src/main.c
src/noise.c
src/pipeline.c
src/raycast.c
src/map.c
src/rand.c
src/save.c
src/shader.c
src/voxel.c
src/world.c
)
target_link_libraries(blocks PUBLIC SDL3::SDL3)
set_target_properties(blocks PROPERTIES C_STANDARD 11)
target_include_directories(blocks PUBLIC lib/jsmn)
target_include_directories(blocks PUBLIC lib/sqlite3)
target_include_directories(blocks PUBLIC lib/stb)
set_target_properties(blocks PROPERTIES C_STANDARD 11)
target_link_libraries(blocks PRIVATE SDL3::SDL3)

find_program(GLSLC glslc)
find_program(SHADERCROSS shadercross)
function(shader FILE)
set(GLSL ${CMAKE_SOURCE_DIR}/shaders/${FILE})
function(add_shader FILE)
set(DEPENDS ${ARGN})
set(HLSL ${CMAKE_SOURCE_DIR}/shaders/${FILE})
set(SPV ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.spv)
set(DXIL ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.dxil)
set(MSL ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.msl)
set(JSON ${CMAKE_SOURCE_DIR}/shaders/bin/${FILE}.json)
function(compile PROGRAM SOURCE OUTPUT)
if(MSVC)
set(SHADERCROSS lib/SDL_shadercross/msvc/shadercross.exe)
endif()
function(compile OUTPUT)
add_custom_command(
OUTPUT ${OUTPUT}
COMMAND ${PROGRAM} ${SOURCE} -o ${OUTPUT} -I src
COMMAND ${SHADERCROSS} ${HLSL} -s hlsl -o ${OUTPUT} -I src
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${SOURCE} shaders/helpers.glsl src/config.h
COMMENT "${SOURCE} -> ${OUTPUT}"
DEPENDS ${HLSL} ${DEPENDS}
COMMENT ${OUTPUT}
)
get_filename_component(NAME ${OUTPUT} NAME)
string(REPLACE . _ NAME ${NAME})
set(NAME compile_${NAME})
add_custom_target(${NAME} DEPENDS ${OUTPUT})
add_dependencies(blocks ${NAME})
endfunction()
if(EXISTS ${GLSLC} AND EXISTS ${SHADERCROSS})
compile(${GLSLC} ${GLSL} ${SPV})
compile(${SHADERCROSS} ${SPV} ${MSL})
compile(${SHADERCROSS} ${SPV} ${JSON})
else()
message("Skipping build since dependencies are missing")
if (MSVC)
compile(${SPV})
compile(${MSL})
compile(${JSON})
endif()
function(package OUTPUT)
get_filename_component(NAME ${OUTPUT} NAME)
Expand All @@ -68,35 +71,33 @@ function(shader FILE)
COMMAND ${CMAKE_COMMAND} -E copy ${OUTPUT} ${BINARY}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${OUTPUT}
COMMENT "${OUTPUT} -> ${BINARY}"
COMMENT ${BINARY}
)
string(REPLACE . _ NAME ${NAME})
set(NAME package_${NAME})
add_custom_target(${NAME} DEPENDS ${BINARY})
add_dependencies(blocks ${NAME})
endfunction()
if(NOT APPLE)
package(${SPV})
else()
if(APPLE)
package(${MSL})
else()
package(${SPV})
endif()
package(${JSON})
endfunction()
shader(composite.frag)
shader(fullscreen.vert)
shader(opaque.frag)
shader(opaque.vert)
shader(random.frag)
shader(raycast.frag)
shader(raycast.vert)
shader(shadow.frag)
shader(shadow.vert)
shader(sky.frag)
shader(sky.vert)
shader(ssao.frag)
shader(transparent.frag)
shader(transparent.vert)
shader(ui.frag)

configure_file(LICENSE.txt ${BINARY_DIR} COPYONLY)
configure_file(README.md ${BINARY_DIR} COPYONLY)
configure_file(textures/atlas.png ${BINARY_DIR} COPYONLY)
add_shader(blur.comp shaders/shader.hlsl src/voxel.inc)
add_shader(composite.comp shaders/shader.hlsl src/voxel.inc)
add_shader(depth.frag shaders/shader.hlsl src/voxel.inc)
add_shader(depth.vert shaders/shader.hlsl src/voxel.inc)
add_shader(opaque.frag shaders/shader.hlsl src/voxel.inc)
add_shader(opaque.vert shaders/shader.hlsl src/voxel.inc)
add_shader(raycast.frag shaders/shader.hlsl src/voxel.inc)
add_shader(raycast.vert shaders/shader.hlsl src/voxel.inc)
add_shader(shadow.frag shaders/shader.hlsl src/voxel.inc)
add_shader(shadow.vert shaders/shader.hlsl src/voxel.inc)
add_shader(sky.frag shaders/shader.hlsl src/voxel.inc)
add_shader(sky.vert shaders/shader.hlsl src/voxel.inc)
add_shader(ssao.comp shaders/shader.hlsl src/voxel.inc)
add_shader(transparent.frag shaders/shader.hlsl src/voxel.inc)
add_shader(transparent.vert shaders/shader.hlsl src/voxel.inc)
add_shader(ui.comp shaders/shader.hlsl src/voxel.inc)
85 changes: 55 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# Blocks

![](image.png)
![](doc/image1.png)

Tiny Minecraft clone in C and GLSL using the new SDL3 GPU API
Tiny Minecraft clone in C and HLSL using the new SDL3 GPU API

### Features

- Procedural world generation
- Parallel chunk loading
- Blocks and plants
- Transparency (limited)
- Deferred rendering
- Directional shadows
- SSAO
- Water depth shading
- Asynchronous chunk loading
- Blocks and sprites
- Persistent worlds
- Directional shadows
- Clustered dynamic lighting
- Basic transparency

### Building

Expand Down Expand Up @@ -46,31 +44,58 @@ cd bin

#### Shaders

Shaders have a few dependencies and are prebuilt for your convenience.
To build locally, install [glslc](https://github.com/google/shaderc) and
[SDL_shadercross](https://github.com/libsdl-org/SDL_shadercross) to your path
variable. The build process will automatically use them
Shaders are prebuilt.
To build locally, install [glslc](https://github.com/google/shaderc) and [SDL_shadercross](https://github.com/libsdl-org/SDL_shadercross) to your path

### Controls

- `WASDEQ` to move
- `Escape` to unfocus
- `LClick` to break a block
- `RClick` to place a block
- `B` to toggle blocks
- `Left Click` to break a block
- `Middle Click` to select a block
- `Right Click` to place a block
- `Scroll` to change blocks
- `F11` to toggle fullscreen
- `LControl` to move quickly
- `LShift` to move slowly

### Rendering

1. Draw the sky to the g-buffer
2. Draw the world from the sun's perspective to a depth texture (shadows)
3. Draw the world (opaque only) to the g-buffer
4. Calculate SSAO using the g-buffer
5. Combine the g-buffer, SSAO, and shadows together to create a composite texture
6. Draw the world (transparent only) with blending to the composite texture
7. Draw the raycast block to the composite texture
8. Upscale the composite texture to the swapchain texture
9. Draw the UI over the swapchain texture
10. Submit

### Passes

1. Render opaques to depth texture (for shadows)

![](doc/image2.png)

2. Render sky to G-buffer

![](doc/image3.png)

3. Render opaques to G-buffer

![](doc/image4.png)

4. Calculate SSAO

![](doc/image5.png)

5. Blur SSAO

![](doc/image6.png)

6. Composite G-buffer

![](doc/image7.png)

7. Render transparents to depth teture (for predepth)

![](doc/image8.png)

8. Render transparents and composite

![](doc/image9.png)

9. Render raycast

![](doc/image10.png)

10. Render UI

![](doc/image11.png)
Binary file added doc/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/image9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image.png
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/SDL
Submodule SDL updated 1262 files
Binary file added lib/SDL_shadercross/msvc/SDL3.dll
Binary file not shown.
Binary file added lib/SDL_shadercross/msvc/SDL3_shadercross.dll
Binary file not shown.
Binary file added lib/SDL_shadercross/msvc/dxcompiler.dll
Binary file not shown.
Binary file added lib/SDL_shadercross/msvc/dxil.dll
Binary file not shown.
Binary file added lib/SDL_shadercross/msvc/shadercross.exe
Binary file not shown.
Binary file added lib/SDL_shadercross/msvc/spirv-cross-c-shared.dll
Binary file not shown.
Loading