diff --git a/data/shaders/lesson2.frg.spv b/data/shaders/lesson2.frg.spv index da5fbed..7f74aee 100644 Binary files a/data/shaders/lesson2.frg.spv and b/data/shaders/lesson2.frg.spv differ diff --git a/data/shaders/lesson2.vtx.spv b/data/shaders/lesson2.vtx.spv index dde73db..0683adb 100644 Binary files a/data/shaders/lesson2.vtx.spv and b/data/shaders/lesson2.vtx.spv differ diff --git a/data/shaders/lesson3.frg.spv b/data/shaders/lesson3.frg.spv index ac9d2fc..6906b3e 100644 Binary files a/data/shaders/lesson3.frg.spv and b/data/shaders/lesson3.frg.spv differ diff --git a/data/shaders/lesson3.vtx.spv b/data/shaders/lesson3.vtx.spv index 5dddcf1..d1c753a 100644 Binary files a/data/shaders/lesson3.vtx.spv and b/data/shaders/lesson3.vtx.spv differ diff --git a/data/shaders/lesson6.frg.spv b/data/shaders/lesson6.frg.spv index 23de997..f6ec24c 100644 Binary files a/data/shaders/lesson6.frg.spv and b/data/shaders/lesson6.frg.spv differ diff --git a/data/shaders/lesson6.vtx.spv b/data/shaders/lesson6.vtx.spv index 3f5a83f..3bbb29b 100644 Binary files a/data/shaders/lesson6.vtx.spv and b/data/shaders/lesson6.vtx.spv differ diff --git a/data/shaders/lesson7.frg.spv b/data/shaders/lesson7.frg.spv index 711f8d6..78ed9a7 100644 Binary files a/data/shaders/lesson7.frg.spv and b/data/shaders/lesson7.frg.spv differ diff --git a/data/shaders/lesson7.vtx.spv b/data/shaders/lesson7.vtx.spv index d7d2fd4..23aaa4d 100644 Binary files a/data/shaders/lesson7.vtx.spv and b/data/shaders/lesson7.vtx.spv differ diff --git a/data/shaders/lesson8.frg.spv b/data/shaders/lesson8.frg.spv index 711f8d6..78ed9a7 100644 Binary files a/data/shaders/lesson8.frg.spv and b/data/shaders/lesson8.frg.spv differ diff --git a/data/shaders/lesson8.vtx.spv b/data/shaders/lesson8.vtx.spv index 1b7d499..6f342f9 100644 Binary files a/data/shaders/lesson8.vtx.spv and b/data/shaders/lesson8.vtx.spv differ diff --git a/data/shaders/lesson9.frg.spv b/data/shaders/lesson9.frg.spv index 711f8d6..78ed9a7 100644 Binary files a/data/shaders/lesson9.frg.spv and b/data/shaders/lesson9.frg.spv differ diff --git a/data/shaders/lesson9.vtx.spv b/data/shaders/lesson9.vtx.spv index 2a2955d..e912827 100644 Binary files a/data/shaders/lesson9.vtx.spv and b/data/shaders/lesson9.vtx.spv differ diff --git a/src/c/nehe.c b/src/c/nehe.c index 40974b5..3b746d4 100644 --- a/src/c/nehe.c +++ b/src/c/nehe.c @@ -435,9 +435,9 @@ bool NeHe_LoadShaders(NeHeContext* restrict ctx, { const SDL_GPUShaderFormat format = SDL_GPU_SHADERFORMAT_SPIRV; SDL_memcpy(&path[basenameLen], ".vtx.spv", 9); - vtxShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_VERTEX, "main"); + vtxShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_VERTEX, "VertexMain"); SDL_memcpy(&path[basenameLen], ".frg.spv", 9); - frgShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_FRAGMENT, "main"); + frgShader = LoadShader(ctx, path, info, format, SDL_GPU_SHADERSTAGE_FRAGMENT, "FragmentMain"); } else if (availableFormats & SDL_GPU_SHADERFORMAT_DXIL) // Direct3D 12 Shader Model 6.0 { diff --git a/src/shaders/lesson2.glsl b/src/shaders/lesson2.glsl deleted file mode 100644 index 25d626d..0000000 --- a/src/shaders/lesson2.glsl +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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/lesson2.hlsl b/src/shaders/lesson2.hlsl index bd36137..e110d4b 100644 --- a/src/shaders/lesson2.hlsl +++ b/src/shaders/lesson2.hlsl @@ -25,7 +25,11 @@ Vertex2Pixel VertexMain(VertexInput input) return output; } +#ifdef VULKAN +half4 FragmentMain(Vertex2Pixel input) : SV_Target0 +#else half4 PixelMain(Vertex2Pixel input) : SV_Target0 +#endif { return half4(1.0, 1.0, 1.0, 1.0); } diff --git a/src/shaders/lesson3.glsl b/src/shaders/lesson3.glsl deleted file mode 100644 index 7972a55..0000000 --- a/src/shaders/lesson3.glsl +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/lesson3.hlsl b/src/shaders/lesson3.hlsl index 8f4f588..af2fff0 100644 --- a/src/shaders/lesson3.hlsl +++ b/src/shaders/lesson3.hlsl @@ -28,7 +28,11 @@ Vertex2Pixel VertexMain(VertexInput input) return output; } +#ifdef VULKAN +half4 FragmentMain(Vertex2Pixel input) : SV_Target0 +#else half4 PixelMain(Vertex2Pixel input) : SV_Target0 +#endif { return input.color; } diff --git a/src/shaders/lesson6.glsl b/src/shaders/lesson6.glsl deleted file mode 100644 index 70bd2eb..0000000 --- a/src/shaders/lesson6.glsl +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/lesson6.hlsl b/src/shaders/lesson6.hlsl index 59a830d..e48481d 100644 --- a/src/shaders/lesson6.hlsl +++ b/src/shaders/lesson6.hlsl @@ -31,7 +31,11 @@ Vertex2Pixel VertexMain(VertexInput input) Texture2D Texture : register(t0, space2); SamplerState Sampler : register(s0, space2); +#ifdef VULKAN +half4 FragmentMain(Vertex2Pixel input) : SV_Target0 +#else half4 PixelMain(Vertex2Pixel input) : SV_Target0 +#endif { return Texture.Sample(Sampler, input.texcoord); } diff --git a/src/shaders/lesson7.glsl b/src/shaders/lesson7.glsl deleted file mode 100644 index e3b9a24..0000000 --- a/src/shaders/lesson7.glsl +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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/lesson7.hlsl b/src/shaders/lesson7.hlsl index 9144690..a45f416 100644 --- a/src/shaders/lesson7.hlsl +++ b/src/shaders/lesson7.hlsl @@ -53,7 +53,11 @@ Vertex2Pixel VertexMain(VertexInput input) Texture2D Texture : register(t0, space2); SamplerState Sampler : register(s0, space2); +#ifdef VULKAN +half4 FragmentMain(Vertex2Pixel input) : SV_Target0 +#else half4 PixelMain(Vertex2Pixel input) : SV_Target0 +#endif { return input.color * Texture.Sample(Sampler, input.texcoord); } diff --git a/src/shaders/lesson8.glsl b/src/shaders/lesson8.glsl deleted file mode 100644 index e403bf5..0000000 --- a/src/shaders/lesson8.glsl +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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/lesson8.hlsl b/src/shaders/lesson8.hlsl index 066b817..e90ff1c 100644 --- a/src/shaders/lesson8.hlsl +++ b/src/shaders/lesson8.hlsl @@ -34,7 +34,11 @@ Vertex2Pixel VertexMain(VertexInput input) Texture2D Texture : register(t0, space2); SamplerState Sampler : register(s0, space2); +#ifdef VULKAN +half4 FragmentMain(Vertex2Pixel input) : SV_Target0 +#else half4 PixelMain(Vertex2Pixel input) : SV_Target0 +#endif { return input.color * Texture.Sample(Sampler, input.texcoord); } diff --git a/src/shaders/lesson9.glsl b/src/shaders/lesson9.glsl deleted file mode 100644 index bacd7dc..0000000 --- a/src/shaders/lesson9.glsl +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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