Skip to content

Commit 9c0078f

Browse files
committed
Added shaders
1 parent 230b509 commit 9c0078f

6 files changed

Lines changed: 35 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,23 @@ add_subdirectory(libs/SDL)
1515
# Find Vulkan
1616
find_package(Vulkan REQUIRED)
1717

18+
if (UNIX)
19+
add_custom_target(build_shaders ALL
20+
COMMAND "${PROJECT_SOURCE_DIR}/shaders/compile.sh"
21+
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/shaders"
22+
)
23+
endif(UNIX)
24+
25+
if (WIN32)
26+
add_custom_target(build_shaders ALL
27+
COMMAND "${PROJECT_SOURCE_DIR}/shaders/compile.bat"
28+
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/shaders"
29+
)
30+
endif(WIN32)
31+
1832
# vulkan_tutorial executable
1933
add_executable(vulkan_tutorial ${SOURCE_FILES})
34+
add_dependencies(vulkan_tutorial build_shaders)
2035
target_include_directories(vulkan_tutorial PUBLIC libs/SDL/include)
2136
target_link_libraries(vulkan_tutorial PUBLIC SDL2-static)
2237
target_include_directories(vulkan_tutorial PUBLIC ${Vulkan_INCLUDE_DIRS})

shaders/compile.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
glslc.exe -fshader-stage=vert triangle_vert.glsl -o triangle_vert.spv
2+
glslc.exe -fshader-stage=frag triangle_frag.glsl -o triangle_frag.spv

shaders/triangle_frag.glsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#version 450 core
2+
3+
layout(location = 0) out vec4 color_out;
4+
5+
void main() {
6+
color_out = vec4(1.0, 1.0, 0.0, 1.0);
7+
}

shaders/triangle_frag.spv

424 Bytes
Binary file not shown.

shaders/triangle_vert.glsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#version 450 core
2+
3+
vec2 positions[3] = vec2[](
4+
vec2(0.0, -0.5),
5+
vec2(0.5, 0.5),
6+
vec2(-0.5, 0.5)
7+
);
8+
9+
void main() {
10+
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
11+
}

shaders/triangle_vert.spv

1.14 KB
Binary file not shown.

0 commit comments

Comments
 (0)