diff --git a/data/shaders/lesson2.frg.spv b/data/shaders/lesson2.frg.spv new file mode 100644 index 0000000..da5fbed Binary files /dev/null and b/data/shaders/lesson2.frg.spv differ diff --git a/data/shaders/lesson2.vtx.spv b/data/shaders/lesson2.vtx.spv new file mode 100644 index 0000000..dde73db Binary files /dev/null and b/data/shaders/lesson2.vtx.spv differ diff --git a/data/shaders/lesson3.frg.spv b/data/shaders/lesson3.frg.spv new file mode 100644 index 0000000..ac9d2fc Binary files /dev/null and b/data/shaders/lesson3.frg.spv differ diff --git a/data/shaders/lesson3.vtx.spv b/data/shaders/lesson3.vtx.spv new file mode 100644 index 0000000..5dddcf1 Binary files /dev/null and b/data/shaders/lesson3.vtx.spv differ diff --git a/data/shaders/lesson6.frg.spv b/data/shaders/lesson6.frg.spv new file mode 100644 index 0000000..23de997 Binary files /dev/null and b/data/shaders/lesson6.frg.spv differ diff --git a/data/shaders/lesson6.vtx.spv b/data/shaders/lesson6.vtx.spv new file mode 100644 index 0000000..3f5a83f Binary files /dev/null and b/data/shaders/lesson6.vtx.spv differ diff --git a/data/shaders/lesson7.frg.spv b/data/shaders/lesson7.frg.spv new file mode 100644 index 0000000..711f8d6 Binary files /dev/null and b/data/shaders/lesson7.frg.spv differ diff --git a/data/shaders/lesson7.vtx.spv b/data/shaders/lesson7.vtx.spv new file mode 100644 index 0000000..d7d2fd4 Binary files /dev/null and b/data/shaders/lesson7.vtx.spv differ diff --git a/data/shaders/lesson8.frg.spv b/data/shaders/lesson8.frg.spv new file mode 100644 index 0000000..711f8d6 Binary files /dev/null and b/data/shaders/lesson8.frg.spv differ diff --git a/data/shaders/lesson8.vtx.spv b/data/shaders/lesson8.vtx.spv new file mode 100644 index 0000000..1b7d499 Binary files /dev/null and b/data/shaders/lesson8.vtx.spv differ diff --git a/data/shaders/lesson9.frg.spv b/data/shaders/lesson9.frg.spv new file mode 100644 index 0000000..711f8d6 Binary files /dev/null and b/data/shaders/lesson9.frg.spv differ diff --git a/data/shaders/lesson9.vtx.spv b/data/shaders/lesson9.vtx.spv new file mode 100644 index 0000000..2a2955d Binary files /dev/null and b/data/shaders/lesson9.vtx.spv differ diff --git a/scripts/compile_shaders.py b/scripts/compile_shaders.py index f516a6c..c5436c6 100755 --- a/scripts/compile_shaders.py +++ b/scripts/compile_shaders.py @@ -211,7 +211,7 @@ def compile_dxbc_shader(shader: Shader, type: str, flags: list[str] | None = Non def compile_shaders() -> None: - build_spirv = False + build_spirv = True build_metal = True build_dxil = False build_dxbc = False diff --git a/src/shaders/lesson2.glsl b/src/shaders/lesson2.glsl new file mode 100644 index 0000000..25d626d --- /dev/null +++ b/src/shaders/lesson2.glsl @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: (C) 2025 a dinosaur + * SPDX-License-Identifier: Zlib + */ + +#version 450 + +#ifdef VERTEX + +layout(location = 0) in vec3 i_position; + +layout(set = 1, binding = 0) uniform UBO +{ + mat4 u_viewproj; +}; + +void main() +{ + gl_Position = u_viewproj * vec4(i_position, 1.0); +} + +#else + +layout(location = 0) out vec4 o_color; + +void main() +{ + o_color = vec4(1.0); +} + +#endif diff --git a/src/shaders/lesson3.glsl b/src/shaders/lesson3.glsl new file mode 100644 index 0000000..7972a55 --- /dev/null +++ b/src/shaders/lesson3.glsl @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: (C) 2025 a dinosaur + * SPDX-License-Identifier: Zlib + */ + +#version 450 + +#ifdef VERTEX + +layout(location = 0) in vec3 i_position; +layout(location = 1) in vec4 i_color; + +layout(location = 0) out vec4 v_color; + +layout(set = 1, binding = 0) uniform UBO +{ + mat4 u_viewproj; +}; + +void main() +{ + v_color = i_color; + gl_Position = u_viewproj * vec4(i_position, 1.0); +} + +#else + +layout(location = 0) in vec4 v_color; + +layout(location = 0) out vec4 o_color; + +void main() +{ + o_color = v_color; +} + +#endif diff --git a/src/shaders/lesson6.glsl b/src/shaders/lesson6.glsl new file mode 100644 index 0000000..70bd2eb --- /dev/null +++ b/src/shaders/lesson6.glsl @@ -0,0 +1,39 @@ +/* + * SPDX-FileCopyrightText: (C) 2025 a dinosaur + * SPDX-License-Identifier: Zlib + */ + +#version 450 + +#ifdef VERTEX + +layout(location = 0) in vec3 i_position; +layout(location = 1) in vec2 i_texcoord; + +layout(location = 0) out vec2 v_texcoord; + +layout(set = 1, binding = 0) uniform UBO +{ + mat4 u_viewproj; +}; + +void main() +{ + v_texcoord = i_texcoord; + gl_Position = u_viewproj * vec4(i_position, 1.0); +} + +#else + +layout(location = 0) in vec2 v_texcoord; + +layout(location = 0) out vec4 o_color; + +layout(set = 2, binding = 0) uniform sampler2D u_texture; + +void main() +{ + o_color = texture(u_texture, v_texcoord); +} + +#endif diff --git a/src/shaders/lesson7.glsl b/src/shaders/lesson7.glsl new file mode 100644 index 0000000..e3b9a24 --- /dev/null +++ b/src/shaders/lesson7.glsl @@ -0,0 +1,62 @@ +/* + * SPDX-FileCopyrightText: (C) 2025 a dinosaur + * SPDX-License-Identifier: Zlib + */ + +#version 450 + +#ifdef VERTEX + +layout(location = 0) in vec3 i_position; +layout(location = 1) in vec2 i_texcoord; +layout(location = 2) in vec3 i_normal; + +layout(location = 0) out vec2 v_texcoord; +layout(location = 1) out vec4 v_color; + +layout(set = 1, binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; +}; + +layout(set = 1, binding = 1) uniform Light +{ + vec4 u_ambient; + vec4 u_diffuse; + vec4 u_position; +}; + +void main() +{ + const vec4 position = u_modelView * vec4(i_position, 1.0); + const vec3 normal = normalize(u_modelView * vec4(i_normal, 0.0)).xyz; + + const vec3 lightVec = u_position.xyz - position.xyz; + const float lightDest2 = dot(lightVec, lightVec); + const vec3 dir = inversesqrt(lightDest2) * lightVec; + const float lambert = max(0.0, dot(normal, dir)); + + const vec3 ambient = 0.04 + 0.2 * u_ambient.rgb; + const vec3 diffuse = 0.8 * u_diffuse.rgb; + + v_texcoord = i_texcoord; + v_color = vec4(ambient + lambert * diffuse, 1.0); + gl_Position = u_projection * position; +} + +#else + +layout(location = 0) in vec2 v_texcoord; +layout(location = 1) in vec4 v_color; + +layout(location = 0) out vec4 o_color; + +layout(set = 2, binding = 0) uniform sampler2D u_texture; + +void main() +{ + o_color = v_color * texture(u_texture, v_texcoord); +} + +#endif diff --git a/src/shaders/lesson8.glsl b/src/shaders/lesson8.glsl new file mode 100644 index 0000000..e403bf5 --- /dev/null +++ b/src/shaders/lesson8.glsl @@ -0,0 +1,43 @@ +/* + * SPDX-FileCopyrightText: (C) 2025 a dinosaur + * SPDX-License-Identifier: Zlib + */ + +#version 450 + +#ifdef VERTEX + +layout(location = 0) in vec3 i_position; +layout(location = 1) in vec2 i_texcoord; + +layout(location = 0) out vec2 v_texcoord; +layout(location = 1) out vec4 v_color; + +layout(set = 1, binding = 0) uniform UBO +{ + mat4 u_viewproj; + vec4 u_color; +}; + +void main() +{ + v_texcoord = i_texcoord; + v_color = u_color; + gl_Position = u_viewproj * vec4(i_position, 1.0); +} + +#else + +layout(location = 0) in vec2 v_texcoord; +layout(location = 1) in vec4 v_color; + +layout(location = 0) out vec4 o_color; + +layout(set = 2, binding = 0) uniform sampler2D u_texture; + +void main() +{ + o_color = v_color * texture(u_texture, v_texcoord); +} + +#endif diff --git a/src/shaders/lesson9.glsl b/src/shaders/lesson9.glsl new file mode 100644 index 0000000..bacd7dc --- /dev/null +++ b/src/shaders/lesson9.glsl @@ -0,0 +1,56 @@ +/* + * SPDX-FileCopyrightText: (C) 2025 a dinosaur + * SPDX-License-Identifier: Zlib + */ + +#version 450 + +#ifdef VERTEX + +layout(location = 0) in vec3 i_position; +layout(location = 1) in vec2 i_texcoord; + +layout(location = 0) out vec2 v_texcoord; +layout(location = 1) out vec4 v_color; + +layout(set = 1, binding = 0) uniform UBO +{ + mat4 u_projection; + vec4 u_color; +}; + +struct Instance +{ + mat4 model; + vec4 color; +}; + +layout(std140, set = 0, binding = 0) readonly buffer InstanceData +{ + Instance instances[]; +} instanceData; + +void main() +{ + const Instance instance = instanceData.instances[gl_InstanceIndex]; + + v_texcoord = i_texcoord; + v_color = instance.color; + gl_Position = u_projection * instance.model * vec4(i_position, 1.0); +} + +#else + +layout(location = 0) in vec2 v_texcoord; +layout(location = 1) in vec4 v_color; + +layout(location = 0) out vec4 o_color; + +layout(set = 2, binding = 0) uniform sampler2D u_texture; + +void main() +{ + o_color = v_color * texture(u_texture, v_texcoord); +} + +#endif