diff --git a/bldsys/cmake/global_options.cmake b/bldsys/cmake/global_options.cmake index a25d771103..5fecb25154 100644 --- a/bldsys/cmake/global_options.cmake +++ b/bldsys/cmake/global_options.cmake @@ -117,6 +117,7 @@ set(VKB_WSI_SELECTION "XCB" CACHE STRING "Select WSI target (XCB, XLIB, WAYLAND, set(VKB_CLANG_TIDY OFF CACHE STRING "Use CMake Clang Tidy integration") set(VKB_CLANG_TIDY_EXTRAS "-header-filter=framework,samples,app;-checks=-*,google-*,-google-runtime-references;--fix;--fix-errors" CACHE STRING "Clang Tidy Parameters") set(VKB_PROFILING OFF CACHE BOOL "Enable Tracy profiling") +set(VKB_SKIP_SLANG_SHADER_COMPILATION OFF CACHE BOOL "Skips compilation for Slang shader") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib/${CMAKE_BUILD_TYPE}/${TARGET_ARCH}") diff --git a/bldsys/cmake/sample_helper.cmake b/bldsys/cmake/sample_helper.cmake index 43387dea0b..20b4eec15e 100644 --- a/bldsys/cmake/sample_helper.cmake +++ b/bldsys/cmake/sample_helper.cmake @@ -246,7 +246,16 @@ endif() endif() # Slang shader compilation - if(Vulkan_slang_EXECUTABLE AND DEFINED SHADERS_SLANG) + # Skip on MacOS/iOS due to CI/CD using potentially broken slang compiler versions from the SDK + # Might revisit once Slang shipped with the SDK is usable + set(SLANG_SKIP_COMPILE false) + if (($ENV{CI} MATCHES true) AND ((CMAKE_SYSTEM_NAME MATCHES "Darwin") OR (CMAKE_SYSTEM_NAME MATCHES "iOS"))) + set(SLANG_SKIP_COMPILE true) + endif() + if(VKB_SKIP_SLANG_SHADER_COMPILATION) + set(SLANG_SKIP_COMPILE true) + endif() + if(NOT SLANG_SKIP_COMPILE AND Vulkan_slang_EXECUTABLE AND DEFINED SHADERS_SLANG) set(OUTPUT_FILES "") set(SLANG_TARGET_NAME ${PROJECT_NAME}-SLANG) foreach(SHADER_FILE_SLANG ${TARGET_SHADERS_SLANG}) diff --git a/docs/build.adoc b/docs/build.adoc index 5b8d164299..4ecb781006 100644 --- a/docs/build.adoc +++ b/docs/build.adoc @@ -105,6 +105,14 @@ Tracy is not currently enabled for Android builds. In the future, we may add sup *Default:* `OFF` +=== VKB_SKIP_SLANG_SHADER_COMPILATION + +By default, Slang shaders are compiled if a Slang compiler is found on the system. In cases where this is undesirable, set this to `OFF` to disable Slang shader compilation. + +You can still select Slang as a shading language target for the samples since Slang shaders are included as precompiled SPIR-V files. + +*Default:* `OFF` + == Quality Assurance We use a small set of tools to provide a level of quality to the project. diff --git a/framework/vulkan_sample.h b/framework/vulkan_sample.h index f424372af9..2248359abd 100644 --- a/framework/vulkan_sample.h +++ b/framework/vulkan_sample.h @@ -1113,6 +1113,18 @@ inline bool VulkanSample::prepare(const ApplicationOptions &options } } + // Shaders generated by Slang require a certain SPIR-V environment that can't be satisfied by Vulkan 1.0, so we need to expliclity up that to at least 1.1 and enable some required extensions + if (get_shading_language() == ShadingLanguage::SLANG) + { + if (api_version < VK_API_VERSION_1_1) + { + api_version = VK_API_VERSION_1_1; + } + add_device_extension(VK_KHR_SPIRV_1_4_EXTENSION_NAME); + add_device_extension(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME); + add_device_extension(VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME); + } + #ifdef VKB_ENABLE_PORTABILITY // VK_KHR_portability_subset must be enabled if present in the implementation (e.g on macOS/iOS with beta extensions enabled) add_device_extension(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, /*optional=*/true); diff --git a/samples/api/compute_nbody/CMakeLists.txt b/samples/api/compute_nbody/CMakeLists.txt index 47152aa55f..311d9799a8 100644 --- a/samples/api/compute_nbody/CMakeLists.txt +++ b/samples/api/compute_nbody/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample_with_tags( "compute_nbody/hlsl/particle.vert.hlsl" "compute_nbody/hlsl/particle.frag.hlsl" "compute_nbody/hlsl/particle_calculate.comp.hlsl" - "compute_nbody/hlsl/particle_integrate.comp.hlsl") + "compute_nbody/hlsl/particle_integrate.comp.hlsl" + SHADER_FILES_SLANG + "compute_nbody/slang/particle.vert.slang" + "compute_nbody/slang/particle.frag.slang" + "compute_nbody/slang/particle_calculate.comp.slang" + "compute_nbody/slang/particle_integrate.comp.slang") diff --git a/samples/api/dynamic_uniform_buffers/CMakeLists.txt b/samples/api/dynamic_uniform_buffers/CMakeLists.txt index 6e1acc04cd..d6c8df2cac 100644 --- a/samples/api/dynamic_uniform_buffers/CMakeLists.txt +++ b/samples/api/dynamic_uniform_buffers/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "dynamic_uniform_buffers/glsl/base.frag" SHADER_FILES_HLSL "dynamic_uniform_buffers/hlsl/base.vert.hlsl" - "dynamic_uniform_buffers/hlsl/base.frag.hlsl") \ No newline at end of file + "dynamic_uniform_buffers/hlsl/base.frag.hlsl" + SHADER_FILES_SLANG + "dynamic_uniform_buffers/slang/base.vert.slang" + "dynamic_uniform_buffers/slang/base.frag.slang") \ No newline at end of file diff --git a/samples/api/hdr/CMakeLists.txt b/samples/api/hdr/CMakeLists.txt index 04e8271496..eedd58c96f 100644 --- a/samples/api/hdr/CMakeLists.txt +++ b/samples/api/hdr/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "hdr/hlsl/bloom.vert.hlsl" "hdr/hlsl/bloom.frag.hlsl" "hdr/hlsl/gbuffer.vert.hlsl" - "hdr/hlsl/gbuffer.frag.hlsl") + "hdr/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "hdr/slang/composition.vert.slang" + "hdr/slang/composition.frag.slang" + "hdr/slang/bloom.vert.slang" + "hdr/slang/bloom.frag.slang" + "hdr/slang/gbuffer.vert.slang" + "hdr/slang/gbuffer.frag.slang") diff --git a/samples/api/hello_triangle/hello_triangle.cpp b/samples/api/hello_triangle/hello_triangle.cpp index 75e1d18393..15208dc612 100644 --- a/samples/api/hello_triangle/hello_triangle.cpp +++ b/samples/api/hello_triangle/hello_triangle.cpp @@ -287,6 +287,14 @@ void HelloTriangle::init_device() // Since this sample has visual output, the device needs to support the swapchain extension std::vector required_device_extensions{VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + // Shaders generated by Slang require a certain SPIR-V environment that can't be satisfied by Vulkan 1.0, so we need to expliclity up that to at least 1.1 and enable some required extensions + if (get_shading_language() == vkb::ShadingLanguage::SLANG) + { + required_device_extensions.push_back(VK_KHR_SPIRV_1_4_EXTENSION_NAME); + required_device_extensions.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME); + required_device_extensions.push_back(VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME); + } + if (!validate_extensions(required_device_extensions, device_extensions)) { throw std::runtime_error("Required device extensions are missing."); diff --git a/samples/api/hpp_compute_nbody/CMakeLists.txt b/samples/api/hpp_compute_nbody/CMakeLists.txt index 80b7c9e0ce..07ba90c945 100644 --- a/samples/api/hpp_compute_nbody/CMakeLists.txt +++ b/samples/api/hpp_compute_nbody/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample_with_tags( "compute_nbody/hlsl/particle.vert.hlsl" "compute_nbody/hlsl/particle.frag.hlsl" "compute_nbody/hlsl/particle_calculate.comp.hlsl" - "compute_nbody/hlsl/particle_integrate.comp.hlsl") \ No newline at end of file + "compute_nbody/hlsl/particle_integrate.comp.hlsl" + SHADER_FILES_SLANG + "compute_nbody/slang/particle.vert.slang" + "compute_nbody/slang/particle.frag.slang" + "compute_nbody/slang/particle_calculate.comp.slang" + "compute_nbody/slang/particle_integrate.comp.slang") \ No newline at end of file diff --git a/samples/api/hpp_dynamic_uniform_buffers/CMakeLists.txt b/samples/api/hpp_dynamic_uniform_buffers/CMakeLists.txt index 11acd7b743..bb75d9e2e5 100644 --- a/samples/api/hpp_dynamic_uniform_buffers/CMakeLists.txt +++ b/samples/api/hpp_dynamic_uniform_buffers/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2021-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "dynamic_uniform_buffers/glsl/base.frag" SHADER_FILES_HLSL "dynamic_uniform_buffers/hlsl/base.vert.hlsl" - "dynamic_uniform_buffers/hlsl/base.frag.hlsl") \ No newline at end of file + "dynamic_uniform_buffers/hlsl/base.frag.hlsl" + SHADER_FILES_SLANG + "dynamic_uniform_buffers/slang/base.vert.slang" + "dynamic_uniform_buffers/slang/base.frag.slang") \ No newline at end of file diff --git a/samples/api/hpp_hdr/CMakeLists.txt b/samples/api/hpp_hdr/CMakeLists.txt index 136d4a61dc..47dcf78c12 100644 --- a/samples/api/hpp_hdr/CMakeLists.txt +++ b/samples/api/hpp_hdr/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "hdr/hlsl/bloom.vert.hlsl" "hdr/hlsl/bloom.frag.hlsl" "hdr/hlsl/gbuffer.vert.hlsl" - "hdr/hlsl/gbuffer.frag.hlsl") \ No newline at end of file + "hdr/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "hdr/slang/composition.vert.slang" + "hdr/slang/composition.frag.slang" + "hdr/slang/bloom.vert.slang" + "hdr/slang/bloom.frag.slang" + "hdr/slang/gbuffer.vert.slang" + "hdr/slang/gbuffer.frag.slang") \ No newline at end of file diff --git a/samples/api/hpp_instancing/CMakeLists.txt b/samples/api/hpp_instancing/CMakeLists.txt index 93efe7a8a4..d3841fcee1 100644 --- a/samples/api/hpp_instancing/CMakeLists.txt +++ b/samples/api/hpp_instancing/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "instancing/hlsl/planet.vert.hlsl" "instancing/hlsl/planet.frag.hlsl" "instancing/hlsl/starfield.vert.hlsl" - "instancing/hlsl/starfield.frag.hlsl") + "instancing/hlsl/starfield.frag.hlsl" + SHADER_FILES_SLANG + "instancing/slang/instancing.vert.slang" + "instancing/slang/instancing.frag.slang" + "instancing/slang/planet.vert.slang" + "instancing/slang/planet.frag.slang" + "instancing/slang/starfield.vert.slang" + "instancing/slang/starfield.frag.slang") \ No newline at end of file diff --git a/samples/api/hpp_separate_image_sampler/CMakeLists.txt b/samples/api/hpp_separate_image_sampler/CMakeLists.txt index fec60fa5a9..2a3077d39e 100644 --- a/samples/api/hpp_separate_image_sampler/CMakeLists.txt +++ b/samples/api/hpp_separate_image_sampler/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "separate_image_sampler/glsl/separate_image_sampler.frag" SHADER_FILES_HLSL "separate_image_sampler/hlsl/separate_image_sampler.vert.hlsl" - "separate_image_sampler/hlsl/separate_image_sampler.frag.hlsl") \ No newline at end of file + "separate_image_sampler/hlsl/separate_image_sampler.frag.hlsl" + SHADER_FILES_SLANG + "separate_image_sampler/slang/separate_image_sampler.vert.slang" + "separate_image_sampler/slang/separate_image_sampler.frag.slang") \ No newline at end of file diff --git a/samples/api/hpp_terrain_tessellation/CMakeLists.txt b/samples/api/hpp_terrain_tessellation/CMakeLists.txt index b4c07fca39..9e82256198 100644 --- a/samples/api/hpp_terrain_tessellation/CMakeLists.txt +++ b/samples/api/hpp_terrain_tessellation/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "terrain_tessellation/hlsl/terrain.tesc.hlsl" "terrain_tessellation/hlsl/terrain.tese.hlsl" "terrain_tessellation/hlsl/skysphere.vert.hlsl" - "terrain_tessellation/hlsl/skysphere.frag.hlsl") + "terrain_tessellation/hlsl/skysphere.frag.hlsl" + SHADER_FILES_SLANG + "terrain_tessellation/slang/terrain.vert.slang" + "terrain_tessellation/slang/terrain.frag.slang" + "terrain_tessellation/slang/terrain.tesc.slang" + "terrain_tessellation/slang/terrain.tese.slang" + "terrain_tessellation/slang/skysphere.vert.slang" + "terrain_tessellation/slang/skysphere.frag.slang") diff --git a/samples/api/hpp_texture_loading/CMakeLists.txt b/samples/api/hpp_texture_loading/CMakeLists.txt index c1e6262c37..5b478fe3f0 100644 --- a/samples/api/hpp_texture_loading/CMakeLists.txt +++ b/samples/api/hpp_texture_loading/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2021-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "texture_loading/glsl/texture.frag" SHADER_FILES_HLSL "texture_loading/hlsl/texture.vert.hlsl" - "texture_loading/hlsl/texture.frag.hlsl") \ No newline at end of file + "texture_loading/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_loading/slang/texture.vert.slang" + "texture_loading/slang/texture.frag.slang") \ No newline at end of file diff --git a/samples/api/hpp_texture_mipmap_generation/CMakeLists.txt b/samples/api/hpp_texture_mipmap_generation/CMakeLists.txt index 3c4c36d95d..808e6ffd80 100644 --- a/samples/api/hpp_texture_mipmap_generation/CMakeLists.txt +++ b/samples/api/hpp_texture_mipmap_generation/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2022-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "texture_mipmap_generation/glsl/texture.frag" SHADER_FILES_HLSL "texture_mipmap_generation/hlsl/texture.vert.hlsl" - "texture_mipmap_generation/hlsl/texture.frag.hlsl") + "texture_mipmap_generation/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_mipmap_generation/slang/texture.vert.slang" + "texture_mipmap_generation/slang/texture.frag.slang") diff --git a/samples/api/hpp_timestamp_queries/CMakeLists.txt b/samples/api/hpp_timestamp_queries/CMakeLists.txt index 6ad9ed4192..86a7e19561 100644 --- a/samples/api/hpp_timestamp_queries/CMakeLists.txt +++ b/samples/api/hpp_timestamp_queries/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2023-2025, NVIDIA CORPORATION. All rights reserved. # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "hdr/hlsl/bloom.vert.hlsl" "hdr/hlsl/bloom.frag.hlsl" "hdr/hlsl/gbuffer.vert.hlsl" - "hdr/hlsl/gbuffer.frag.hlsl") + "hdr/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "hdr/slang/composition.vert.slang" + "hdr/slang/composition.frag.slang" + "hdr/slang/bloom.vert.slang" + "hdr/slang/bloom.frag.slang" + "hdr/slang/gbuffer.vert.slang" + "hdr/slang/gbuffer.frag.slang") diff --git a/samples/api/instancing/CMakeLists.txt b/samples/api/instancing/CMakeLists.txt index 7949ea5689..9085e4fab1 100644 --- a/samples/api/instancing/CMakeLists.txt +++ b/samples/api/instancing/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "instancing/hlsl/planet.vert.hlsl" "instancing/hlsl/planet.frag.hlsl" "instancing/hlsl/starfield.vert.hlsl" - "instancing/hlsl/starfield.frag.hlsl") + "instancing/hlsl/starfield.frag.hlsl" + SHADER_FILES_SLANG + "instancing/slang/instancing.vert.slang" + "instancing/slang/instancing.frag.slang" + "instancing/slang/planet.vert.slang" + "instancing/slang/planet.frag.slang" + "instancing/slang/starfield.vert.slang" + "instancing/slang/starfield.frag.slang") diff --git a/samples/api/separate_image_sampler/CMakeLists.txt b/samples/api/separate_image_sampler/CMakeLists.txt index 73888bd4d5..35a4f21bc0 100644 --- a/samples/api/separate_image_sampler/CMakeLists.txt +++ b/samples/api/separate_image_sampler/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, Sascha Willems +# Copyright (c) 2021-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "separate_image_sampler/glsl/separate_image_sampler.frag" SHADER_FILES_HLSL "separate_image_sampler/hlsl/separate_image_sampler.vert.hlsl" - "separate_image_sampler/hlsl/separate_image_sampler.frag.hlsl") \ No newline at end of file + "separate_image_sampler/hlsl/separate_image_sampler.frag.hlsl" + SHADER_FILES_SLANG + "separate_image_sampler/slang/separate_image_sampler.vert.slang" + "separate_image_sampler/slang/separate_image_sampler.frag.slang") \ No newline at end of file diff --git a/samples/api/terrain_tessellation/CMakeLists.txt b/samples/api/terrain_tessellation/CMakeLists.txt index b6e820f9fc..c7941b27fc 100644 --- a/samples/api/terrain_tessellation/CMakeLists.txt +++ b/samples/api/terrain_tessellation/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "terrain_tessellation/hlsl/terrain.tesc.hlsl" "terrain_tessellation/hlsl/terrain.tese.hlsl" "terrain_tessellation/hlsl/skysphere.vert.hlsl" - "terrain_tessellation/hlsl/skysphere.frag.hlsl") + "terrain_tessellation/hlsl/skysphere.frag.hlsl" + SHADER_FILES_SLANG + "terrain_tessellation/slang/terrain.vert.slang" + "terrain_tessellation/slang/terrain.frag.slang" + "terrain_tessellation/slang/terrain.tesc.slang" + "terrain_tessellation/slang/terrain.tese.slang" + "terrain_tessellation/slang/skysphere.vert.slang" + "terrain_tessellation/slang/skysphere.frag.slang") diff --git a/samples/api/texture_loading/CMakeLists.txt b/samples/api/texture_loading/CMakeLists.txt index 3ac1d5e1a9..59be6547ea 100644 --- a/samples/api/texture_loading/CMakeLists.txt +++ b/samples/api/texture_loading/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "texture_loading/glsl/texture.frag" SHADER_FILES_HLSL "texture_loading/hlsl/texture.vert.hlsl" - "texture_loading/hlsl/texture.frag.hlsl") \ No newline at end of file + "texture_loading/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_loading/slang/texture.vert.slang" + "texture_loading/slang/texture.frag.slang") \ No newline at end of file diff --git a/samples/api/texture_mipmap_generation/CMakeLists.txt b/samples/api/texture_mipmap_generation/CMakeLists.txt index 5dd0bb2b3f..1def9b134b 100644 --- a/samples/api/texture_mipmap_generation/CMakeLists.txt +++ b/samples/api/texture_mipmap_generation/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "texture_mipmap_generation/glsl/texture.frag" SHADER_FILES_HLSL "texture_mipmap_generation/hlsl/texture.vert.hlsl" - "texture_mipmap_generation/hlsl/texture.frag.hlsl") \ No newline at end of file + "texture_mipmap_generation/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_mipmap_generation/slang/texture.vert.slang" + "texture_mipmap_generation/slang/texture.frag.slang") \ No newline at end of file diff --git a/samples/api/timestamp_queries/CMakeLists.txt b/samples/api/timestamp_queries/CMakeLists.txt index 437f98b41a..49388a3c3b 100644 --- a/samples/api/timestamp_queries/CMakeLists.txt +++ b/samples/api/timestamp_queries/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, Sascha Willems +# Copyright (c) 2022-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "hdr/hlsl/bloom.vert.hlsl" "hdr/hlsl/bloom.frag.hlsl" "hdr/hlsl/gbuffer.vert.hlsl" - "hdr/hlsl/gbuffer.frag.hlsl") + "hdr/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "hdr/slang/composition.vert.slang" + "hdr/slang/composition.frag.slang" + "hdr/slang/bloom.vert.slang" + "hdr/slang/bloom.frag.slang" + "hdr/slang/gbuffer.vert.slang" + "hdr/slang/gbuffer.frag.slang") diff --git a/samples/extensions/buffer_device_address/CMakeLists.txt b/samples/extensions/buffer_device_address/CMakeLists.txt index c06c04d69d..39ef1e1273 100644 --- a/samples/extensions/buffer_device_address/CMakeLists.txt +++ b/samples/extensions/buffer_device_address/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021, Arm Limited and Contributors +# Copyright (c) 2021-2025, Arm Limited and Contributors # # SPDX-License-Identifier: Apache-2.0 # @@ -26,6 +26,10 @@ add_sample_with_tags( NAME "Buffer device address" DESCRIPTION "Demonstrates use of buffer device address for flexible vertex attribute fetch" SHADER_FILES_GLSL - "buffer_device_address/update_vbo.comp" - "buffer_device_address/render.vert" - "buffer_device_address/render.frag") + "buffer_device_address/glsl/update_vbo.comp" + "buffer_device_address/glsl/render.vert" + "buffer_device_address/glsl/render.frag" + SHADER_FILES_SLANG + "buffer_device_address/slang/update_vbo.comp.slang" + "buffer_device_address/slang/render.vert.slang" + "buffer_device_address/slang/render.frag.slang") diff --git a/samples/extensions/buffer_device_address/buffer_device_address.cpp b/samples/extensions/buffer_device_address/buffer_device_address.cpp index f4357bee37..420cbdb0c2 100644 --- a/samples/extensions/buffer_device_address/buffer_device_address.cpp +++ b/samples/extensions/buffer_device_address/buffer_device_address.cpp @@ -109,7 +109,7 @@ void BufferDeviceAddress::create_compute_pipeline() { pipelines.compute_pipeline_layout = create_pipeline_layout(false); VkComputePipelineCreateInfo info = vkb::initializers::compute_pipeline_create_info(pipelines.compute_pipeline_layout); - info.stage = load_shader("buffer_device_address/update_vbo.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); + info.stage = load_shader("buffer_device_address", "update_vbo.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); VK_CHECK(vkCreateComputePipelines(get_device().get_handle(), VK_NULL_HANDLE, 1, &info, nullptr, &pipelines.compute_update_pipeline)); } @@ -155,8 +155,8 @@ void BufferDeviceAddress::create_graphics_pipeline() info.pStages = stages; info.stageCount = 2; - stages[0] = load_shader("buffer_device_address/render.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - stages[1] = load_shader("buffer_device_address/render.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + stages[0] = load_shader("buffer_device_address", "render.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + stages[1] = load_shader("buffer_device_address", "render.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VK_CHECK(vkCreateGraphicsPipelines(get_device().get_handle(), VK_NULL_HANDLE, 1, &info, nullptr, &pipelines.bindless_vbo_pipeline)); } diff --git a/samples/extensions/calibrated_timestamps/CMakeLists.txt b/samples/extensions/calibrated_timestamps/CMakeLists.txt index 75619f8d57..6f8ca2a215 100644 --- a/samples/extensions/calibrated_timestamps/CMakeLists.txt +++ b/samples/extensions/calibrated_timestamps/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Holochip Corporation +# Copyright (c) 2023-2025, Holochip Corporation # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample_with_tags( "hdr/hlsl/bloom.vert.hlsl" "hdr/hlsl/bloom.frag.hlsl" "hdr/hlsl/gbuffer.vert.hlsl" - "hdr/hlsl/gbuffer.frag.hlsl") \ No newline at end of file + "hdr/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "hdr/slang/composition.vert.slang" + "hdr/slang/composition.frag.slang" + "hdr/slang/bloom.vert.slang" + "hdr/slang/bloom.frag.slang" + "hdr/slang/gbuffer.vert.slang" + "hdr/slang/gbuffer.frag.slang") \ No newline at end of file diff --git a/samples/extensions/color_write_enable/CMakeLists.txt b/samples/extensions/color_write_enable/CMakeLists.txt index f579885fba..2808ac7def 100644 --- a/samples/extensions/color_write_enable/CMakeLists.txt +++ b/samples/extensions/color_write_enable/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample( "color_write_enable/hlsl/triangle_separate_channels.vert.hlsl" "color_write_enable/hlsl/triangle_separate_channels.frag.hlsl" "color_write_enable/hlsl/composition.vert.hlsl" - "color_write_enable/hlsl/composition.frag.hlsl") + "color_write_enable/hlsl/composition.frag.hlsl" + SHADER_FILES_SLANG + "color_write_enable/slang/triangle_separate_channels.vert.slang" + "color_write_enable/slang/triangle_separate_channels.frag.slang" + "color_write_enable/slang/composition.vert.slang" + "color_write_enable/slang/composition.frag.slang") diff --git a/samples/extensions/color_write_enable/color_write_enable.cpp b/samples/extensions/color_write_enable/color_write_enable.cpp index fffb742e59..24723b0f37 100644 --- a/samples/extensions/color_write_enable/color_write_enable.cpp +++ b/samples/extensions/color_write_enable/color_write_enable.cpp @@ -245,6 +245,18 @@ void ColorWriteEnable::request_gpu_features(vkb::core::PhysicalDeviceC &gpu) { gpu.get_mutable_requested_features().independentBlend = true; } + + if (get_shading_language() == vkb::ShadingLanguage::SLANG) + { + if (gpu.get_features().shaderStorageImageReadWithoutFormat) + { + gpu.get_mutable_requested_features().shaderStorageImageReadWithoutFormat = true; + } + else + { + throw std::runtime_error("When using Slang shaders, this sample requires support for reading storage images without format (shaderStorageImageReadWithoutFormat)"); + } + } } void ColorWriteEnable::setup_descriptor_pool() diff --git a/samples/extensions/conditional_rendering/CMakeLists.txt b/samples/extensions/conditional_rendering/CMakeLists.txt index 73269d9fc4..72a115aaef 100644 --- a/samples/extensions/conditional_rendering/CMakeLists.txt +++ b/samples/extensions/conditional_rendering/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, Sascha Willems +# Copyright (c) 2022-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample( "conditional_rendering/glsl/model.frag" SHADER_FILES_HLSL "conditional_rendering/hlsl/model.vert.hlsl" - "conditional_rendering/hlsl/model.frag.hlsl") + "conditional_rendering/hlsl/model.frag.hlsl" + SHADER_FILES_SLANG + "conditional_rendering/slang/model.vert.slang" + "conditional_rendering/slang/model.frag.slang") diff --git a/samples/extensions/conservative_rasterization/CMakeLists.txt b/samples/extensions/conservative_rasterization/CMakeLists.txt index 3db67ac5ac..78c8c6fc6f 100644 --- a/samples/extensions/conservative_rasterization/CMakeLists.txt +++ b/samples/extensions/conservative_rasterization/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -36,4 +36,10 @@ add_sample_with_tags( "conservative_rasterization/hlsl/fullscreen.frag.hlsl" "conservative_rasterization/hlsl/triangle.vert.hlsl" "conservative_rasterization/hlsl/triangle.frag.hlsl" - "conservative_rasterization/hlsl/triangleoverlay.frag.hlsl") + "conservative_rasterization/hlsl/triangleoverlay.frag.hlsl" + SHADER_FILES_SLANG + "conservative_rasterization/slang/fullscreen.vert.slang" + "conservative_rasterization/slang/fullscreen.frag.slang" + "conservative_rasterization/slang/triangle.vert.slang" + "conservative_rasterization/slang/triangle.frag.slang" + "conservative_rasterization/slang/triangleoverlay.frag.slang") diff --git a/samples/extensions/debug_utils/CMakeLists.txt b/samples/extensions/debug_utils/CMakeLists.txt index e31aab91fb..ccd0dc325e 100644 --- a/samples/extensions/debug_utils/CMakeLists.txt +++ b/samples/extensions/debug_utils/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2024, Sascha Willems +# Copyright (c) 2020-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample( "debug_utils/hlsl/bloom.vert.hlsl" "debug_utils/hlsl/bloom.frag.hlsl" "debug_utils/hlsl/gbuffer.vert.hlsl" - "debug_utils/hlsl/gbuffer.frag.hlsl") + "debug_utils/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "debug_utils/slang/composition.vert.slang" + "debug_utils/slang/composition.frag.slang" + "debug_utils/slang/bloom.vert.slang" + "debug_utils/slang/bloom.frag.slang" + "debug_utils/slang/gbuffer.vert.slang" + "debug_utils/slang/gbuffer.frag.slang") diff --git a/samples/extensions/descriptor_buffer_basic/CMakeLists.txt b/samples/extensions/descriptor_buffer_basic/CMakeLists.txt index dc2857ee9d..a847778c23 100644 --- a/samples/extensions/descriptor_buffer_basic/CMakeLists.txt +++ b/samples/extensions/descriptor_buffer_basic/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Sascha Willems +# Copyright (c) 2023-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "descriptor_buffer_basic/glsl/cube.frag" SHADER_FILES_HLSL "descriptor_buffer_basic/hlsl/cube.vert.hlsl" - "descriptor_buffer_basic/hlsl/cube.frag.hlsl") + "descriptor_buffer_basic/hlsl/cube.frag.hlsl" + SHADER_FILES_SLANG + "descriptor_buffer_basic/slang/cube.vert.slang" + "descriptor_buffer_basic/slang/cube.frag.slang") diff --git a/samples/extensions/descriptor_buffer_basic/descriptor_buffer_basic.cpp b/samples/extensions/descriptor_buffer_basic/descriptor_buffer_basic.cpp index 845eb14143..da175a50a6 100644 --- a/samples/extensions/descriptor_buffer_basic/descriptor_buffer_basic.cpp +++ b/samples/extensions/descriptor_buffer_basic/descriptor_buffer_basic.cpp @@ -242,9 +242,8 @@ void DescriptorBufferBasic::prepare_pipelines() vkb::initializers::vertex_input_binding_description(0, sizeof(Vertex), VK_VERTEX_INPUT_RATE_VERTEX), }; const std::vector vertex_input_attributes = { - vkb::initializers::vertex_input_attribute_description(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), // Location 0: Position - vkb::initializers::vertex_input_attribute_description(0, 1, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 3), // Location 1: Normal - vkb::initializers::vertex_input_attribute_description(0, 2, VK_FORMAT_R32G32_SFLOAT, sizeof(float) * 6), // Location 2: UV + vkb::initializers::vertex_input_attribute_description(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), // Location 0: Position + vkb::initializers::vertex_input_attribute_description(0, 1, VK_FORMAT_R32G32_SFLOAT, sizeof(float) * 6), // Location 1: UV }; VkPipelineVertexInputStateCreateInfo vertex_input_state = vkb::initializers::pipeline_vertex_input_state_create_info(); vertex_input_state.vertexBindingDescriptionCount = static_cast(vertex_input_bindings.size()); diff --git a/samples/extensions/descriptor_indexing/CMakeLists.txt b/samples/extensions/descriptor_indexing/CMakeLists.txt index 105675f305..74a4389d2b 100644 --- a/samples/extensions/descriptor_indexing/CMakeLists.txt +++ b/samples/extensions/descriptor_indexing/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, Arm Limited and Contributors +# Copyright (c) 2021-2025, Arm Limited and Contributors # # SPDX-License-Identifier: Apache-2.0 # @@ -35,4 +35,9 @@ add_sample_with_tags( "descriptor_indexing/hlsl/nonuniform-quads.frag.hlsl" "descriptor_indexing/hlsl/update-after-bind-quads.vert.hlsl" "descriptor_indexing/hlsl/update-after-bind-quads.frag.hlsl" - DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_EXT_descriptor_indexing") + DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_EXT_descriptor_indexing" + SHADER_FILES_SLANG + "descriptor_indexing/slang/nonuniform-quads.vert.slang" + "descriptor_indexing/slang/nonuniform-quads.frag.slang" + "descriptor_indexing/slang/update-after-bind-quads.vert.slang" + "descriptor_indexing/slang/update-after-bind-quads.frag.slang") diff --git a/samples/extensions/dynamic_blending/CMakeLists.txt b/samples/extensions/dynamic_blending/CMakeLists.txt index 8ebd3e9efb..8a53d7f1b7 100644 --- a/samples/extensions/dynamic_blending/CMakeLists.txt +++ b/samples/extensions/dynamic_blending/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample( "dynamic_blending/glsl/blending.frag" SHADER_FILES_HLSL "dynamic_blending/hlsl/blending.vert.hlsl" - "dynamic_blending/hlsl/blending.frag.hlsl") + "dynamic_blending/hlsl/blending.frag.hlsl" + SHADER_FILES_SLANG + "dynamic_blending/slang/blending.vert.slang" + "dynamic_blending/slang/blending.frag.slang") diff --git a/samples/extensions/dynamic_line_rasterization/CMakeLists.txt b/samples/extensions/dynamic_line_rasterization/CMakeLists.txt index f8444ca9a5..ef8d1d1c41 100644 --- a/samples/extensions/dynamic_line_rasterization/CMakeLists.txt +++ b/samples/extensions/dynamic_line_rasterization/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample( "dynamic_line_rasterization/hlsl/base.vert.hlsl" "dynamic_line_rasterization/hlsl/base.frag.hlsl" "dynamic_line_rasterization/hlsl/grid.vert.hlsl" - "dynamic_line_rasterization/hlsl/grid.frag.hlsl") + "dynamic_line_rasterization/hlsl/grid.frag.hlsl" + SHADER_FILES_SLANG + "dynamic_line_rasterization/slang/base.vert.slang" + "dynamic_line_rasterization/slang/base.frag.slang" + "dynamic_line_rasterization/slang/grid.vert.slang" + "dynamic_line_rasterization/slang/grid.frag.slang") diff --git a/samples/extensions/dynamic_multisample_rasterization/CMakeLists.txt b/samples/extensions/dynamic_multisample_rasterization/CMakeLists.txt index a34576f47a..2f6839847d 100644 --- a/samples/extensions/dynamic_multisample_rasterization/CMakeLists.txt +++ b/samples/extensions/dynamic_multisample_rasterization/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024, Mobica Limited +# Copyright (c) 2024-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -26,5 +26,8 @@ add_sample( NAME "Dynamic Multisample Rasterization" DESCRIPTION "Demonstrate how to use dynamic multisample rasterization (MSAA) from VK_EXT_extended_dynamic_state3 extension" SHADER_FILES_GLSL - "dynamic_multisample_rasterization/model.vert" - "dynamic_multisample_rasterization/model.frag") + "dynamic_multisample_rasterization/glsl/model.vert" + "dynamic_multisample_rasterization/glsl/model.frag" + SHADER_FILES_SLANG + "dynamic_multisample_rasterization/slang/model.vert.slang" + "dynamic_multisample_rasterization/slang/model.frag.slang") diff --git a/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp b/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp index 0788cd9490..aeb0fc290a 100644 --- a/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp +++ b/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp @@ -661,8 +661,8 @@ void DynamicMultisampleRasterization::prepare_pipelines() pipeline_create_info.pVertexInputState = &vertex_input_state; - shader_stages[0] = load_shader("dynamic_multisample_rasterization/model.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shader_stages[1] = load_shader("dynamic_multisample_rasterization/model.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shader_stages[0] = load_shader("dynamic_multisample_rasterization", "model.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shader_stages[1] = load_shader("dynamic_multisample_rasterization", "model.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); // Add a pipeline for the opaque counterclockwise faces VK_CHECK(vkCreateGraphicsPipelines(get_device().get_handle(), pipeline_cache, 1, &pipeline_create_info, nullptr, &pipeline_opaque)); diff --git a/samples/extensions/dynamic_primitive_clipping/CMakeLists.txt b/samples/extensions/dynamic_primitive_clipping/CMakeLists.txt index 8865becd55..06c11cb576 100644 --- a/samples/extensions/dynamic_primitive_clipping/CMakeLists.txt +++ b/samples/extensions/dynamic_primitive_clipping/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024, Mobica Limited +# Copyright (c) 2024-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample( "dynamic_primitive_clipping/glsl/primitive_clipping.frag" SHADER_FILES_HLSL "dynamic_primitive_clipping/hlsl/primitive_clipping.vert.hlsl" - "dynamic_primitive_clipping/hlsl/primitive_clipping.frag.hlsl") + "dynamic_primitive_clipping/hlsl/primitive_clipping.frag.hlsl" + SHADER_FILES_SLANG + "dynamic_primitive_clipping/slang/primitive_clipping.vert.slang" + "dynamic_primitive_clipping/slang/primitive_clipping.frag.slang") \ No newline at end of file diff --git a/samples/extensions/extended_dynamic_state2/CMakeLists.txt b/samples/extensions/extended_dynamic_state2/CMakeLists.txt index 7c1e0c91eb..80ee60445b 100644 --- a/samples/extensions/extended_dynamic_state2/CMakeLists.txt +++ b/samples/extensions/extended_dynamic_state2/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -26,11 +26,20 @@ add_sample( NAME "Extended Dynamic State 2" DESCRIPTION "Demonstrate how to use depth bias, primitive restart, rasterizer discard and patch control points dynamically, which can reduce the number of pipeline objects that are need to be created." SHADER_FILES_GLSL - "extended_dynamic_state2/baseline.vert" - "extended_dynamic_state2/baseline.frag" - "extended_dynamic_state2/tess.vert" - "extended_dynamic_state2/tess.tese" - "extended_dynamic_state2/tess.tesc" - "extended_dynamic_state2/tess.frag" - "extended_dynamic_state2/background.vert" - "extended_dynamic_state2/background.frag") + "extended_dynamic_state2/glsl/baseline.vert" + "extended_dynamic_state2/glsl/baseline.frag" + "extended_dynamic_state2/glsl/tess.vert" + "extended_dynamic_state2/glsl/tess.tese" + "extended_dynamic_state2/glsl/tess.tesc" + "extended_dynamic_state2/glsl/tess.frag" + "extended_dynamic_state2/glsl/background.vert" + "extended_dynamic_state2/glsl/background.frag" + SHADER_FILES_SLANG + "extended_dynamic_state2/slang/baseline.vert.slang" + "extended_dynamic_state2/slang/baseline.frag.slang" + "extended_dynamic_state2/slang/tess.vert.slang" + "extended_dynamic_state2/slang/tess.tese.slang" + "extended_dynamic_state2/slang/tess.tesc.slang" + "extended_dynamic_state2/slang/tess.frag.slang" + "extended_dynamic_state2/slang/background.vert.slang" + "extended_dynamic_state2/slang/background.frag.slang") diff --git a/samples/extensions/extended_dynamic_state2/extended_dynamic_state2.cpp b/samples/extensions/extended_dynamic_state2/extended_dynamic_state2.cpp index a9b8530f55..57823f2fd4 100644 --- a/samples/extensions/extended_dynamic_state2/extended_dynamic_state2.cpp +++ b/samples/extensions/extended_dynamic_state2/extended_dynamic_state2.cpp @@ -296,8 +296,8 @@ void ExtendedDynamicState2::create_pipelines() vertex_input_state.pVertexAttributeDescriptions = vertex_input_attributes.data(); std::array shader_stages{}; - shader_stages[0] = load_shader("extended_dynamic_state2/baseline.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shader_stages[1] = load_shader("extended_dynamic_state2/baseline.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shader_stages[0] = load_shader("extended_dynamic_state2", "baseline.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shader_stages[1] = load_shader("extended_dynamic_state2", "baseline.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); /* Use the pNext to point to the rendering create struct */ VkGraphicsPipelineCreateInfo graphics_create{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; @@ -360,8 +360,8 @@ void ExtendedDynamicState2::create_pipelines() rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - shader_stages[0] = load_shader("extended_dynamic_state2/background.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shader_stages[1] = load_shader("extended_dynamic_state2/background.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shader_stages[0] = load_shader("extended_dynamic_state2", "background.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shader_stages[1] = load_shader("extended_dynamic_state2", "background.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VK_CHECK(vkCreateGraphicsPipelines(get_device().get_handle(), pipeline_cache, @@ -390,14 +390,10 @@ void ExtendedDynamicState2::create_pipelines() rasterization_state.polygonMode = VK_POLYGON_MODE_LINE; } - shader_stages[0] = load_shader("extended_dynamic_state2/tess.vert.spv", - VK_SHADER_STAGE_VERTEX_BIT); - shader_stages[1] = load_shader("extended_dynamic_state2/tess.frag.spv", - VK_SHADER_STAGE_FRAGMENT_BIT); - shader_stages[2] = load_shader("extended_dynamic_state2/tess.tesc.spv", - VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); - shader_stages[3] = load_shader("extended_dynamic_state2/tess.tese.spv", - VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); + shader_stages[0] = load_shader("extended_dynamic_state2", "tess.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shader_stages[1] = load_shader("extended_dynamic_state2", "tess.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shader_stages[2] = load_shader("extended_dynamic_state2", "tess.tesc.spv", VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); + shader_stages[3] = load_shader("extended_dynamic_state2", "tess.tese.spv", VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT); graphics_create.stageCount = static_cast(shader_stages.size()); graphics_create.pStages = shader_stages.data(); /* Enable depth test and write */ diff --git a/samples/extensions/fragment_shader_barycentric/CMakeLists.txt b/samples/extensions/fragment_shader_barycentric/CMakeLists.txt index 11fe0bb477..58302e74b1 100644 --- a/samples/extensions/fragment_shader_barycentric/CMakeLists.txt +++ b/samples/extensions/fragment_shader_barycentric/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -26,7 +26,12 @@ add_sample( NAME "Fragment shader barycentric" DESCRIPTION "Demonstrate how to use fragment shader barycentric feature, which allows accessing barycentric coordinates for each processed fragment." SHADER_FILES_GLSL - "fragment_shader_barycentric/object.vert" - "fragment_shader_barycentric/object.frag" - "fragment_shader_barycentric/skybox.vert" - "fragment_shader_barycentric/skybox.frag") + "fragment_shader_barycentric/glsl/object.vert" + "fragment_shader_barycentric/glsl/object.frag" + "fragment_shader_barycentric/glsl/skybox.vert" + "fragment_shader_barycentric/glsl/skybox.frag" + SHADER_FILES_SLANG + "fragment_shader_barycentric/slang/object.vert.slang" + "fragment_shader_barycentric/slang/object.frag.slang" + "fragment_shader_barycentric/slang/skybox.vert.slang" + "fragment_shader_barycentric/slang/skybox.frag.slang") diff --git a/samples/extensions/fragment_shader_barycentric/fragment_shader_barycentric.cpp b/samples/extensions/fragment_shader_barycentric/fragment_shader_barycentric.cpp index e401ac0505..55a915033b 100644 --- a/samples/extensions/fragment_shader_barycentric/fragment_shader_barycentric.cpp +++ b/samples/extensions/fragment_shader_barycentric/fragment_shader_barycentric.cpp @@ -252,8 +252,8 @@ void FragmentShaderBarycentric::create_pipeline() vertex_input_state.pVertexAttributeDescriptions = vertex_input_attributes.data(); std::array shader_stages{}; - shader_stages[0] = load_shader("fragment_shader_barycentric/skybox.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shader_stages[1] = load_shader("fragment_shader_barycentric/skybox.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shader_stages[0] = load_shader("fragment_shader_barycentric", "skybox.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shader_stages[1] = load_shader("fragment_shader_barycentric", "skybox.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); // Use the pNext to point to the rendering create struct VkGraphicsPipelineCreateInfo graphics_create{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; @@ -275,8 +275,8 @@ void FragmentShaderBarycentric::create_pipeline() VK_CHECK(vkCreateGraphicsPipelines(get_device().get_handle(), pipeline_cache, 1, &graphics_create, VK_NULL_HANDLE, &pipelines.skybox)); // Object pipeline - shader_stages[0] = load_shader("fragment_shader_barycentric/object.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - shader_stages[1] = load_shader("fragment_shader_barycentric/object.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + shader_stages[0] = load_shader("fragment_shader_barycentric", "object.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + shader_stages[1] = load_shader("fragment_shader_barycentric", "object.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); // Flip cull mode rasterization_state.cullMode = VK_CULL_MODE_FRONT_BIT; diff --git a/samples/extensions/fragment_shading_rate/CMakeLists.txt b/samples/extensions/fragment_shading_rate/CMakeLists.txt index 2db27c05da..2412abc54b 100644 --- a/samples/extensions/fragment_shading_rate/CMakeLists.txt +++ b/samples/extensions/fragment_shading_rate/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2024, Sascha Willems +# Copyright (c) 2020-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -31,4 +31,7 @@ add_sample_with_tags( SHADER_FILES_HLSL "fragment_shading_rate/hlsl/scene.vert.hlsl" "fragment_shading_rate/hlsl/scene.frag.hlsl" - DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_fragment_shading_rate") + DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_fragment_shading_rate" + SHADER_FILES_SLANG + "fragment_shading_rate/slang/scene.vert.slang" + "fragment_shading_rate/slang/scene.frag.slang") diff --git a/samples/extensions/graphics_pipeline_library/CMakeLists.txt b/samples/extensions/graphics_pipeline_library/CMakeLists.txt index 5e65d94eb4..067adce5e2 100644 --- a/samples/extensions/graphics_pipeline_library/CMakeLists.txt +++ b/samples/extensions/graphics_pipeline_library/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, Sascha Willems +# Copyright (c) 2022-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample( "graphics_pipeline_library/glsl/uber.frag" SHADER_FILES_HLSL "graphics_pipeline_library/hlsl/shared.vert.hlsl" - "graphics_pipeline_library/hlsl/uber.frag.hlsl") \ No newline at end of file + "graphics_pipeline_library/hlsl/uber.frag.hlsl" + SHADER_FILES_SLANG + "graphics_pipeline_library/slang/shared.vert.slang" + "graphics_pipeline_library/slang/uber.frag.slang") \ No newline at end of file diff --git a/samples/extensions/gshader_to_mshader/CMakeLists.txt b/samples/extensions/gshader_to_mshader/CMakeLists.txt index c6b17313b3..d199dae029 100644 --- a/samples/extensions/gshader_to_mshader/CMakeLists.txt +++ b/samples/extensions/gshader_to_mshader/CMakeLists.txt @@ -26,13 +26,21 @@ add_sample( NAME "Geometry shader to mesh shader" DESCRIPTION "Sample shows migration from geometry shader pipeline to mesh shader one" SHADER_FILES_GLSL - "gshader_to_mshader/gshader_to_mshader.vert" - "gshader_to_mshader/gshader_to_mshader.frag" - "gshader_to_mshader/gshader_to_mshader.geom" - "gshader_to_mshader/gshader_to_mshader.mesh" - "gshader_to_mshader/gshader_to_mshader_base.frag" - "gshader_to_mshader/gshader_to_mshader_base.vert" - "gshader_to_mshader/gshader_to_mshader_mesh.frag" + "gshader_to_mshader/glsl/gshader_to_mshader.vert" + "gshader_to_mshader/glsl/gshader_to_mshader.frag" + "gshader_to_mshader/glsl/gshader_to_mshader.geom" + "gshader_to_mshader/glsl/gshader_to_mshader.mesh" + "gshader_to_mshader/glsl/gshader_to_mshader_base.frag" + "gshader_to_mshader/glsl/gshader_to_mshader_base.vert" + "gshader_to_mshader/glsl/gshader_to_mshader_mesh.frag" GLSLC_ADDITIONAL_ARGUMENTS "--target-spv=spv1.4" - ) + SHADER_FILES_SLANG + "gshader_to_mshader/slang/gshader_to_mshader.vert.slang" + "gshader_to_mshader/slang/gshader_to_mshader.frag.slang" + "gshader_to_mshader/slang/gshader_to_mshader.geom.slang" + "gshader_to_mshader/slang/gshader_to_mshader.mesh.slang" + "gshader_to_mshader/slang/gshader_to_mshader_base.frag.slang" + "gshader_to_mshader/slang/gshader_to_mshader_base.vert.slang" + "gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.slang" + ) diff --git a/samples/extensions/gshader_to_mshader/gshader_to_mshader.cpp b/samples/extensions/gshader_to_mshader/gshader_to_mshader.cpp index 218c5ed972..7c96d70439 100644 --- a/samples/extensions/gshader_to_mshader/gshader_to_mshader.cpp +++ b/samples/extensions/gshader_to_mshader/gshader_to_mshader.cpp @@ -134,10 +134,11 @@ void GshaderToMshader::update_uniform_buffers() { for (auto &ubo : ubos) { - ubo.proj = camera.matrices.perspective; - ubo.view = camera.matrices.view; - ubo.model = glm::mat4(1.f); - ubo.model = glm::rotate(ubo.model, glm::pi(), glm::vec3(0, 0, 1)); + ubo.proj = camera.matrices.perspective; + ubo.view = camera.matrices.view; + ubo.model = glm::mat4(1.f); + ubo.model = glm::rotate(ubo.model, glm::pi(), glm::vec3(0, 0, 1)); + ubo.normal = glm::transpose(glm::inverse(ubo.view * ubo.model)); } uniform_buffer_vs->convert_and_update(ubos[0]); uniform_buffer_gs->convert_and_update(ubos[1]); @@ -147,18 +148,18 @@ void GshaderToMshader::update_uniform_buffers() void GshaderToMshader::prepare_pipelines() { std::array model_stages; - model_stages[0] = load_shader("gshader_to_mshader/gshader_to_mshader.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - model_stages[1] = load_shader("gshader_to_mshader/gshader_to_mshader.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + model_stages[0] = load_shader("gshader_to_mshader", "gshader_to_mshader.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + model_stages[1] = load_shader("gshader_to_mshader", "gshader_to_mshader.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); std::array geometry_stages; - geometry_stages[0] = load_shader("gshader_to_mshader/gshader_to_mshader_base.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - geometry_stages[1] = load_shader("gshader_to_mshader/gshader_to_mshader_base.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); - geometry_stages[2] = load_shader("gshader_to_mshader/gshader_to_mshader.geom.spv", VK_SHADER_STAGE_GEOMETRY_BIT); + geometry_stages[0] = load_shader("gshader_to_mshader", "gshader_to_mshader_base.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + geometry_stages[1] = load_shader("gshader_to_mshader", "gshader_to_mshader_base.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + geometry_stages[2] = load_shader("gshader_to_mshader", "gshader_to_mshader.geom.spv", VK_SHADER_STAGE_GEOMETRY_BIT); // task shader is not used, the amount of spawned mesh shaders is determined by amount of meshlets stored in the storage_buffer_object->vertex_indices std::array mesh_stages; - mesh_stages[0] = load_shader("gshader_to_mshader/gshader_to_mshader.mesh.spv", VK_SHADER_STAGE_MESH_BIT_EXT); - mesh_stages[1] = load_shader("gshader_to_mshader/gshader_to_mshader_mesh.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + mesh_stages[0] = load_shader("gshader_to_mshader", "gshader_to_mshader.mesh.spv", VK_SHADER_STAGE_MESH_BIT_EXT); + mesh_stages[1] = load_shader("gshader_to_mshader", "gshader_to_mshader_mesh.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); // Dynamic State std::vector dynamic_state_enables = { diff --git a/samples/extensions/gshader_to_mshader/gshader_to_mshader.h b/samples/extensions/gshader_to_mshader/gshader_to_mshader.h index 8354924a06..986ec64f56 100644 --- a/samples/extensions/gshader_to_mshader/gshader_to_mshader.h +++ b/samples/extensions/gshader_to_mshader/gshader_to_mshader.h @@ -31,6 +31,7 @@ class GshaderToMshader : public ApiVulkanSample glm::mat4 model; glm::mat4 view; glm::mat4 proj; + glm::mat4 normal; }; std::array ubos; diff --git a/samples/extensions/host_image_copy/CMakeLists.txt b/samples/extensions/host_image_copy/CMakeLists.txt index cff8474d81..48b7c74cf3 100644 --- a/samples/extensions/host_image_copy/CMakeLists.txt +++ b/samples/extensions/host_image_copy/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024, Sascha Willems +# Copyright (c) 2024-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "texture_loading/glsl/texture.frag" SHADER_FILES_HLSL "texture_loading/hlsl/texture.vert.hlsl" - "texture_loading/hlsl/texture.frag.hlsl") + "texture_loading/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_loading/slang/texture.vert.slang" + "texture_loading/slang/texture.frag.slang") diff --git a/samples/extensions/hpp_mesh_shading/CMakeLists.txt b/samples/extensions/hpp_mesh_shading/CMakeLists.txt index 6be846bc91..95d481027c 100644 --- a/samples/extensions/hpp_mesh_shading/CMakeLists.txt +++ b/samples/extensions/hpp_mesh_shading/CMakeLists.txt @@ -35,4 +35,7 @@ add_sample_with_tags( "mesh_shading/hlsl/ps.frag.hlsl" DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_EXT_mesh_shader" + SHADER_FILES_SLANG + "mesh_shading/slang/ms.mesh.slang" + "mesh_shading/slang/ps.frag.slang" ) diff --git a/samples/extensions/hpp_push_descriptors/CMakeLists.txt b/samples/extensions/hpp_push_descriptors/CMakeLists.txt index 8756600e94..e349019201 100644 --- a/samples/extensions/hpp_push_descriptors/CMakeLists.txt +++ b/samples/extensions/hpp_push_descriptors/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "push_descriptors/glsl/cube.frag" SHADER_FILES_HLSL "push_descriptors/hlsl/cube.vert.hlsl" - "push_descriptors/hlsl/cube.frag.hlsl") + "push_descriptors/hlsl/cube.frag.hlsl" + SHADER_FILES_SLANG + "push_descriptors/slang/cube.vert.slang" + "push_descriptors/slang/cube.frag.slang") \ No newline at end of file diff --git a/samples/extensions/logic_op_dynamic_state/CMakeLists.txt b/samples/extensions/logic_op_dynamic_state/CMakeLists.txt index f3933079f6..f43ed724b6 100644 --- a/samples/extensions/logic_op_dynamic_state/CMakeLists.txt +++ b/samples/extensions/logic_op_dynamic_state/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample( "logic_op_dynamic_state/hlsl/background.vert.hlsl" "logic_op_dynamic_state/hlsl/background.frag.hlsl" "logic_op_dynamic_state/hlsl/baseline.vert.hlsl" - "logic_op_dynamic_state/hlsl/baseline.frag.hlsl") + "logic_op_dynamic_state/hlsl/baseline.frag.hlsl" + SHADER_FILES_SLANG + "logic_op_dynamic_state/slang/background.vert.slang" + "logic_op_dynamic_state/slang/background.frag.slang" + "logic_op_dynamic_state/slang/baseline.vert.slang" + "logic_op_dynamic_state/slang/baseline.frag.slang") diff --git a/samples/extensions/memory_budget/CMakeLists.txt b/samples/extensions/memory_budget/CMakeLists.txt index d3ec3fc8b3..02d387b6a4 100644 --- a/samples/extensions/memory_budget/CMakeLists.txt +++ b/samples/extensions/memory_budget/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2019-2024, Sascha Willems -# Copyright (c) 2024, Holochip Corporation +# Copyright (c) 2019-2025, Sascha Willems +# Copyright (c) 2024-2025, Holochip Corporation # # SPDX-License-Identifier: Apache-2.0 # @@ -39,4 +39,11 @@ add_sample_with_tags( "instancing/hlsl/planet.vert.hlsl" "instancing/hlsl/planet.frag.hlsl" "instancing/hlsl/starfield.vert.hlsl" - "instancing/hlsl/starfield.frag.hlsl") + "instancing/hlsl/starfield.frag.hlsl" + SHADER_FILES_SLANG + "instancing/slang/instancing.vert.slang" + "instancing/slang/instancing.frag.slang" + "instancing/slang/planet.vert.slang" + "instancing/slang/planet.frag.slang" + "instancing/slang/starfield.vert.slang" + "instancing/slang/starfield.frag.slang") diff --git a/samples/extensions/mesh_shading/CMakeLists.txt b/samples/extensions/mesh_shading/CMakeLists.txt index 394f363f48..b84166c374 100644 --- a/samples/extensions/mesh_shading/CMakeLists.txt +++ b/samples/extensions/mesh_shading/CMakeLists.txt @@ -35,4 +35,7 @@ add_sample_with_tags( "mesh_shading/hlsl/ps.frag.hlsl" DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_EXT_mesh_shader" + SHADER_FILES_SLANG + "mesh_shading/slang/ms.mesh.slang" + "mesh_shading/slang/ps.frag.slang" ) diff --git a/samples/extensions/open_cl_interop/CMakeLists.txt b/samples/extensions/open_cl_interop/CMakeLists.txt index 274ac3ad4b..3616892ce6 100644 --- a/samples/extensions/open_cl_interop/CMakeLists.txt +++ b/samples/extensions/open_cl_interop/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Sascha Willems +# Copyright (c) 2023-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -40,5 +40,8 @@ if (NOT APPLE) open_cl_interop/procedural_texture.cl SHADER_FILES_HLSL open_cl_interop/hlsl/texture_display.vert.hlsl - open_cl_interop/hlsl/texture_display.frag.hlsl) + open_cl_interop/hlsl/texture_display.frag.hlsl + SHADER_FILES_SLANG + open_cl_interop/slang/texture_display.vert.slang + open_cl_interop/slang/texture_display.frag.slang) endif() \ No newline at end of file diff --git a/samples/extensions/open_gl_interop/CMakeLists.txt b/samples/extensions/open_gl_interop/CMakeLists.txt index 87ae1976f8..8a08b628f5 100644 --- a/samples/extensions/open_gl_interop/CMakeLists.txt +++ b/samples/extensions/open_gl_interop/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2020-2024, Bradley Austin Davis -# Copyright (c) 2020-2024, Arm Limited +# Copyright (c) 2020-2025, Bradley Austin Davis +# Copyright (c) 2020-2025, Arm Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -60,5 +60,8 @@ if (NOT (ANDROID OR DIRECT_TO_DISPLAY OR IOS)) "texture_loading/glsl/texture.frag" SHADER_FILES_HLSL "texture_loading/hlsl/texture.vert.hlsl" - "texture_loading/hlsl/texture.frag.hlsl") + "texture_loading/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_loading/slang/texture.vert.slang" + "texture_loading/slang/texture.frag.slang") endif() \ No newline at end of file diff --git a/samples/extensions/patch_control_points/CMakeLists.txt b/samples/extensions/patch_control_points/CMakeLists.txt index 4955638d0d..854932815a 100644 --- a/samples/extensions/patch_control_points/CMakeLists.txt +++ b/samples/extensions/patch_control_points/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample( "patch_control_points/hlsl/tess.frag.hlsl" "patch_control_points/hlsl/tess.tesc.hlsl" "patch_control_points/hlsl/tess.tese.hlsl" - "patch_control_points/hlsl/tess.vert.hlsl") + "patch_control_points/hlsl/tess.vert.hlsl" + SHADER_FILES_SLANG + "patch_control_points/slang/tess.frag.slang" + "patch_control_points/slang/tess.tesc.slang" + "patch_control_points/slang/tess.tese.slang" + "patch_control_points/slang/tess.vert.slang") diff --git a/samples/extensions/portability/CMakeLists.txt b/samples/extensions/portability/CMakeLists.txt index 18270e3aca..fe24612680 100644 --- a/samples/extensions/portability/CMakeLists.txt +++ b/samples/extensions/portability/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, Holochip +# Copyright (c) 2022-2025, Holochip # # SPDX-License-Identifier: Apache-2.0 # @@ -38,4 +38,11 @@ add_sample( "debug_utils/hlsl/bloom.vert.hlsl" "debug_utils/hlsl/bloom.frag.hlsl" "debug_utils/hlsl/gbuffer.vert.hlsl" - "debug_utils/hlsl/gbuffer.frag.hlsl") + "debug_utils/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "debug_utils/slang/composition.vert.slang" + "debug_utils/slang/composition.frag.slang" + "debug_utils/slang/bloom.vert.slang" + "debug_utils/slang/bloom.frag.slang" + "debug_utils/slang/gbuffer.vert.slang" + "debug_utils/slang/gbuffer.frag.slang") diff --git a/samples/extensions/push_descriptors/CMakeLists.txt b/samples/extensions/push_descriptors/CMakeLists.txt index 673feadf97..07297f782c 100644 --- a/samples/extensions/push_descriptors/CMakeLists.txt +++ b/samples/extensions/push_descriptors/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2024, Sascha Willems +# Copyright (c) 2019-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "push_descriptors/glsl/cube.frag" SHADER_FILES_HLSL "push_descriptors/hlsl/cube.vert.hlsl" - "push_descriptors/hlsl/cube.frag.hlsl") + "push_descriptors/hlsl/cube.frag.hlsl" + SHADER_FILES_SLANG + "push_descriptors/slang/cube.vert.slang" + "push_descriptors/slang/cube.frag.slang") diff --git a/samples/extensions/ray_queries/CMakeLists.txt b/samples/extensions/ray_queries/CMakeLists.txt index f6f403421d..65bc2dda9d 100644 --- a/samples/extensions/ray_queries/CMakeLists.txt +++ b/samples/extensions/ray_queries/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, Holochip Corporation +# Copyright (c) 2021-2025, Holochip Corporation # # SPDX-License-Identifier: Apache-2.0 # @@ -31,5 +31,8 @@ add_sample_with_tags( SHADER_FILES_HLSL "ray_queries/hlsl/ray_shadow.vert.hlsl" "ray_queries/hlsl/ray_shadow.frag.hlsl" - DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_ray_query") + DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_ray_query" + SHADER_FILES_SLANG + "ray_queries/slang/ray_shadow.vert.slang" + "ray_queries/slang/ray_shadow.frag.slang") diff --git a/samples/extensions/ray_tracing_basic/CMakeLists.txt b/samples/extensions/ray_tracing_basic/CMakeLists.txt index 3b0247093e..73b09082e6 100644 --- a/samples/extensions/ray_tracing_basic/CMakeLists.txt +++ b/samples/extensions/ray_tracing_basic/CMakeLists.txt @@ -37,4 +37,8 @@ add_sample_with_tags( "ray_tracing_basic/hlsl/closesthit.rchit.hlsl" DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_ray_query" + SHADER_FILES_SLANG + "ray_tracing_basic/slang/raygen.rgen.slang" + "ray_tracing_basic/slang/miss.rmiss.slang" + "ray_tracing_basic/slang/closesthit.rchit.slang" ) diff --git a/samples/extensions/ray_tracing_extended/CMakeLists.txt b/samples/extensions/ray_tracing_extended/CMakeLists.txt index 2d938479b6..4dd2bf591d 100644 --- a/samples/extensions/ray_tracing_extended/CMakeLists.txt +++ b/samples/extensions/ray_tracing_extended/CMakeLists.txt @@ -37,5 +37,9 @@ add_sample_with_tags( "ray_tracing_extended/hlsl/closesthit.rchit.hlsl" DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_EXT_descriptor_indexing -fspv-extension=SPV_KHR_ray_query" + SHADER_FILES_SLANG + "ray_tracing_extended/slang/raygen.rgen.slang" + "ray_tracing_extended/slang/miss.rmiss.slang" + "ray_tracing_extended/slang/closesthit.rchit.slang" ) diff --git a/samples/extensions/ray_tracing_position_fetch/CMakeLists.txt b/samples/extensions/ray_tracing_position_fetch/CMakeLists.txt index 6b5451692d..e2d5f9c27d 100644 --- a/samples/extensions/ray_tracing_position_fetch/CMakeLists.txt +++ b/samples/extensions/ray_tracing_position_fetch/CMakeLists.txt @@ -37,4 +37,8 @@ add_sample( "ray_tracing_position_fetch/hlsl/raygen.rgen.hlsl" DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_ray_query -fspv-extension=SPV_KHR_ray_tracing" + SHADER_FILES_SLANG + "ray_tracing_position_fetch/slang/closesthit.rchit.slang" + "ray_tracing_position_fetch/slang/miss.rmiss.slang" + "ray_tracing_position_fetch/slang/raygen.rgen.slang" ) diff --git a/samples/extensions/shader_debugprintf/CMakeLists.txt b/samples/extensions/shader_debugprintf/CMakeLists.txt index cf3664c5fd..9d3bb993fe 100644 --- a/samples/extensions/shader_debugprintf/CMakeLists.txt +++ b/samples/extensions/shader_debugprintf/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024, Sascha Willems +# Copyright (c) 2024-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -31,4 +31,7 @@ add_sample( SHADER_FILES_HLSL "shader_debugprintf/hlsl/scene.vert.hlsl" "shader_debugprintf/hlsl/scene.frag.hlsl" - DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_non_semantic_info") \ No newline at end of file + DXC_ADDITIONAL_ARGUMENTS "-fspv-extension=SPV_KHR_non_semantic_info" + SHADER_FILES_SLANG + "shader_debugprintf/slang/scene.vert.slang" + "shader_debugprintf/slang/scene.frag.slang") diff --git a/samples/extensions/sparse_image/CMakeLists.txt b/samples/extensions/sparse_image/CMakeLists.txt index 720e5402a2..43be6e00d6 100644 --- a/samples/extensions/sparse_image/CMakeLists.txt +++ b/samples/extensions/sparse_image/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, Mobica Limited +# Copyright (c) 2023-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample( "sparse_image/glsl/sparse.frag" SHADER_FILES_HLSL "sparse_image/hlsl/sparse.vert.hlsl" - "sparse_image/hlsl/sparse.frag.hlsl") + "sparse_image/hlsl/sparse.frag.hlsl" + SHADER_FILES_SLANG + "sparse_image/slang/sparse.vert.slang" + "sparse_image/slang/sparse.frag.slang") \ No newline at end of file diff --git a/samples/extensions/synchronization_2/CMakeLists.txt b/samples/extensions/synchronization_2/CMakeLists.txt index 5ee329f060..41a84ad5af 100644 --- a/samples/extensions/synchronization_2/CMakeLists.txt +++ b/samples/extensions/synchronization_2/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, Sascha Willems +# Copyright (c) 2021-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -34,4 +34,9 @@ add_sample_with_tags( "synchronization_2/hlsl/particle.vert.hlsl" "synchronization_2/hlsl/particle.frag.hlsl" "synchronization_2/hlsl/particle_calculate.comp.hlsl" - "synchronization_2/hlsl/particle_integrate.comp.hlsl") + "synchronization_2/hlsl/particle_integrate.comp.hlsl" + SHADER_FILES_SLANG + "synchronization_2/slang/particle.vert.slang" + "synchronization_2/slang/particle.frag.slang" + "synchronization_2/slang/particle_calculate.comp.slang" + "synchronization_2/slang/particle_integrate.comp.slang") diff --git a/samples/extensions/timeline_semaphore/CMakeLists.txt b/samples/extensions/timeline_semaphore/CMakeLists.txt index 4458805124..e0ee3f4696 100644 --- a/samples/extensions/timeline_semaphore/CMakeLists.txt +++ b/samples/extensions/timeline_semaphore/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, Arm Limited and Contributors +# Copyright (c) 2021-2025, Arm Limited and Contributors # # SPDX-License-Identifier: Apache-2.0 # @@ -26,8 +26,15 @@ add_sample_with_tags( NAME "Timeline semaphore" DESCRIPTION "Demonstrates use of timeline semaphores to express complex queue dependency graphs" SHADER_FILES_GLSL - "timeline_semaphore/game_of_life_update.comp" - "timeline_semaphore/game_of_life_mutate.comp" - "timeline_semaphore/game_of_life_init.comp" - "timeline_semaphore/render.vert" - "timeline_semaphore/render.frag") + "timeline_semaphore/glsl/game_of_life_update.comp" + "timeline_semaphore/glsl/game_of_life_mutate.comp" + "timeline_semaphore/glsl/game_of_life_init.comp" + "timeline_semaphore/glsl/render.vert" + "timeline_semaphore/glsl/render.frag" + SHADER_FILES_SLANG + "timeline_semaphore/slang/game_of_life_update.comp.slang" + "timeline_semaphore/slang/game_of_life_mutate.comp.slang" + "timeline_semaphore/slang/game_of_life_init.comp.slang" + "timeline_semaphore/slang/render.vert.slang" + "timeline_semaphore/slang/render.frag.slang" +) diff --git a/samples/extensions/timeline_semaphore/timeline_semaphore.cpp b/samples/extensions/timeline_semaphore/timeline_semaphore.cpp index bc60237adc..3c7ee9fd22 100644 --- a/samples/extensions/timeline_semaphore/timeline_semaphore.cpp +++ b/samples/extensions/timeline_semaphore/timeline_semaphore.cpp @@ -330,13 +330,13 @@ void TimelineSemaphore::setup_compute_pipeline() VK_CHECK(vkCreatePipelineLayout(get_device().get_handle(), &layout_info, nullptr, &compute.pipeline_layout)); VkComputePipelineCreateInfo info = vkb::initializers::compute_pipeline_create_info(compute.pipeline_layout); - info.stage = load_shader("timeline_semaphore/game_of_life_update.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); + info.stage = load_shader("timeline_semaphore", "game_of_life_update.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); VK_CHECK(vkCreateComputePipelines(get_device().get_handle(), VK_NULL_HANDLE, 1, &info, nullptr, &compute.update_pipeline)); - info.stage = load_shader("timeline_semaphore/game_of_life_mutate.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); + info.stage = load_shader("timeline_semaphore", "game_of_life_mutate.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); VK_CHECK(vkCreateComputePipelines(get_device().get_handle(), VK_NULL_HANDLE, 1, &info, nullptr, &compute.mutate_pipeline)); - info.stage = load_shader("timeline_semaphore/game_of_life_init.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); + info.stage = load_shader("timeline_semaphore", "game_of_life_init.comp.spv", VK_SHADER_STAGE_COMPUTE_BIT); VK_CHECK(vkCreateComputePipelines(get_device().get_handle(), VK_NULL_HANDLE, 1, &info, nullptr, &compute.init_pipeline)); } @@ -550,8 +550,8 @@ void TimelineSemaphore::setup_graphics_pipeline() info.pStages = stages; info.stageCount = 2; - stages[0] = load_shader("timeline_semaphore/render.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); - stages[1] = load_shader("timeline_semaphore/render.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); + stages[0] = load_shader("timeline_semaphore", "render.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); + stages[1] = load_shader("timeline_semaphore", "render.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); VK_CHECK(vkCreateGraphicsPipelines(get_device().get_handle(), VK_NULL_HANDLE, 1, &info, nullptr, &graphics.pipeline)); } diff --git a/samples/extensions/vertex_dynamic_state/CMakeLists.txt b/samples/extensions/vertex_dynamic_state/CMakeLists.txt index a8f7449f46..4e6f59d648 100644 --- a/samples/extensions/vertex_dynamic_state/CMakeLists.txt +++ b/samples/extensions/vertex_dynamic_state/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024, Mobica Limited +# Copyright (c) 2022-2025, Mobica Limited # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,8 @@ add_sample( "vertex_dynamic_state/glsl/gbuffer.frag" SHADER_FILES_HLSL "vertex_dynamic_state/hlsl/gbuffer.vert.hlsl" - "vertex_dynamic_state/hlsl/gbuffer.frag.hlsl") + "vertex_dynamic_state/hlsl/gbuffer.frag.hlsl" + SHADER_FILES_SLANG + "vertex_dynamic_state/slang/gbuffer.vert.slang" + "vertex_dynamic_state/slang/gbuffer.frag.slang") + diff --git a/samples/performance/texture_compression_basisu/CMakeLists.txt b/samples/performance/texture_compression_basisu/CMakeLists.txt index 9dae12e039..ce24220f99 100644 --- a/samples/performance/texture_compression_basisu/CMakeLists.txt +++ b/samples/performance/texture_compression_basisu/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2024, Sascha Willems +# Copyright (c) 2021-2025, Sascha Willems # # SPDX-License-Identifier: Apache-2.0 # @@ -30,4 +30,7 @@ add_sample_with_tags( "texture_compression_basisu/glsl/texture.frag" SHADER_FILES_HLSL "texture_compression_basisu/hlsl/texture.vert.hlsl" - "texture_compression_basisu/hlsl/texture.frag.hlsl") + "texture_compression_basisu/hlsl/texture.frag.hlsl" + SHADER_FILES_SLANG + "texture_compression_basisu/slang/texture.vert.slang" + "texture_compression_basisu/slang/texture.frag.slang") diff --git a/shaders/README.adoc b/shaders/README.adoc index acdd4b5702..9932c150b0 100644 --- a/shaders/README.adoc +++ b/shaders/README.adoc @@ -20,15 +20,22 @@ == Shader languages -This folder contains the textual shaders for the samples. All samples come with GLSL shaders and some optionally with HLSL shaders. For samples that support both shader language this is a good way to compare GLSL to HLSL syntax when targeting SPIR-V for Vulkan. +This folder contains the textual shaders for the samples. All samples come with GLSL shaders and some optionally with Slang and HLSL shaders. For samples that support multiple shader languages, this is a good way to compare the syntax differences when targeting SPIR-V for Vulkan. == Compiling shaders -The samples load offline compiled SPIR-V variants of the GLSL/HLSL shaders. If you have the appropriate compiler installed, e.g. via the LunarG VUlkan SDK, shaders will be automatically compiled when building the samples project. +The samples load offline compiled SPIR-V variants of the GLSL/Slang/HLSL shaders. If you have the appropriate compiler installed, e.g. via the LunarG VUlkan SDK, shaders will be automatically compiled when building the samples project. + +**Note for compiling Slang shaders**: The minimum required version of the Slang compiler is `2025.16.1`. Older versions might have issues compiling shaders or may result in invalid SPIR-V. It's advised to use the latest version from link:https://github.com/shader-slang/slang/releases[here]. + +== Selecting shading language + +To select a shading language, use the `--shading-language` argument followed by the shading language `glsl`, `slang` or `hlsl`. Samples default to `glsl`. == Further information The xref:guide:ROOT:index.adoc[Vulkan Guide] contains further information on how to use HLSL with Vulkan and how it compares to GLSL: * xref:guide::hlsl.adoc[HLSL in Vulkan] -* xref:guide::high_level_shader_language_comparison.adoc[High level shading language comparison] \ No newline at end of file +* xref:guide::high_level_shader_language_comparison.adoc[High level shading language comparison] +* link:https://shader-slang.org/docs/[Slang shading language documentation] \ No newline at end of file diff --git a/shaders/buffer_device_address/render.frag b/shaders/buffer_device_address/glsl/render.frag similarity index 93% rename from shaders/buffer_device_address/render.frag rename to shaders/buffer_device_address/glsl/render.frag index 9c9f1fb7a8..9c140ec04e 100644 --- a/shaders/buffer_device_address/render.frag +++ b/shaders/buffer_device_address/glsl/render.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/buffer_device_address/render.frag.spv b/shaders/buffer_device_address/glsl/render.frag.spv similarity index 100% rename from shaders/buffer_device_address/render.frag.spv rename to shaders/buffer_device_address/glsl/render.frag.spv diff --git a/shaders/buffer_device_address/render.vert b/shaders/buffer_device_address/glsl/render.vert similarity index 98% rename from shaders/buffer_device_address/render.vert rename to shaders/buffer_device_address/glsl/render.vert index ffc8871306..dc4223bd9c 100644 --- a/shaders/buffer_device_address/render.vert +++ b/shaders/buffer_device_address/glsl/render.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/buffer_device_address/render.vert.spv b/shaders/buffer_device_address/glsl/render.vert.spv similarity index 100% rename from shaders/buffer_device_address/render.vert.spv rename to shaders/buffer_device_address/glsl/render.vert.spv diff --git a/shaders/buffer_device_address/update_vbo.comp b/shaders/buffer_device_address/glsl/update_vbo.comp similarity index 98% rename from shaders/buffer_device_address/update_vbo.comp rename to shaders/buffer_device_address/glsl/update_vbo.comp index 14ac1ef9dc..5dba0c8ac1 100644 --- a/shaders/buffer_device_address/update_vbo.comp +++ b/shaders/buffer_device_address/glsl/update_vbo.comp @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/buffer_device_address/update_vbo.comp.spv b/shaders/buffer_device_address/glsl/update_vbo.comp.spv similarity index 100% rename from shaders/buffer_device_address/update_vbo.comp.spv rename to shaders/buffer_device_address/glsl/update_vbo.comp.spv diff --git a/shaders/buffer_device_address/slang/render.frag.slang b/shaders/buffer_device_address/slang/render.frag.slang new file mode 100644 index 0000000000..63fd5aa418 --- /dev/null +++ b/shaders/buffer_device_address/slang/render.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + nointerpolation float4 Color; +} + +// Nothing interesting, just interpolate color from vertex. +[shader("fragment")] +float4 main(VSOutput input) +{ + return input.Color; +} diff --git a/shaders/buffer_device_address/slang/render.frag.spv b/shaders/buffer_device_address/slang/render.frag.spv new file mode 100644 index 0000000000..4f70e49851 Binary files /dev/null and b/shaders/buffer_device_address/slang/render.frag.spv differ diff --git a/shaders/buffer_device_address/slang/render.vert.slang b/shaders/buffer_device_address/slang/render.vert.slang new file mode 100644 index 0000000000..23a770d900 --- /dev/null +++ b/shaders/buffer_device_address/slang/render.vert.slang @@ -0,0 +1,73 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + nointerpolation float4 Color; +} + +struct Registers +{ + float4x4 view_projection; + // This is a pointer to an array of pointers, essentially: + // const VBO * const *vbos + float2 **positions; +}; + +[shader("vertex")] +VSOutput main(uint instanceIndex: SV_InstanceID, uint vertexIndex: SV_VertexID, uniform Registers registers) +{ + int slice = instanceIndex; + + // One VBO per instance, load the VBO pointer. + // The cool thing here is that a compute shader could hypothetically + // write the pointer list where vertices are stored. + // With vertex attributes we do not have the luxury to modify VBO bindings on the GPU. + // The best we can do is to just modify the vertexOffset in an indirect draw call, + // but that's not always flexible enough, and enforces a very specific engine design to work. + // We can even modify the attribute layout per slice here, since we can just cast the pointer + // to something else if we want. + float2* positions = registers.positions[slice]; + + // Load the vertex based on VertexIndex instead of an attribute. Fully flexible. + // Only downside is that we do not get format conversion for free like we do with normal vertex attributes. + float2 pos = positions[vertexIndex] * 2.5; + + // Place the quad meshes on screen and center it. + pos += 3.0 * (float2(slice % 8, slice / 8) - 3.5); + + VSOutput output; + // Normal projection. + output.Pos = mul(registers.view_projection, float4(pos, 0.0, 1.0)); + + // Color the vertex. Use a combination of a wave and checkerboard, completely arbitrary. + int index_x = vertexIndex % 16; + int index_y = vertexIndex / 16; + + float r = 0.5 + 0.3 * sin(float(index_x)); + float g = 0.5 + 0.3 * sin(float(index_y)); + + int checkerboard = (index_x ^ index_y) & 1; + r *= float(checkerboard) * 0.8 + 0.2; + g *= float(checkerboard) * 0.8 + 0.2; + + output.Color = float4(r, g, 0.15, 1.0); + + return output; +} diff --git a/shaders/buffer_device_address/slang/render.vert.spv b/shaders/buffer_device_address/slang/render.vert.spv new file mode 100644 index 0000000000..415aa6607d Binary files /dev/null and b/shaders/buffer_device_address/slang/render.vert.spv differ diff --git a/shaders/buffer_device_address/slang/update_vbo.comp.slang b/shaders/buffer_device_address/slang/update_vbo.comp.slang new file mode 100644 index 0000000000..c1b7a76d22 --- /dev/null +++ b/shaders/buffer_device_address/slang/update_vbo.comp.slang @@ -0,0 +1,70 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// If we mark a buffer as buffer_reference, this is treated as a pointer type. +// A variable with the type Position is a 64-bit pointer to the data within. +// We can freely cast between pointer types if we wish, but that is not necessary in this sample. +// buffer_reference_align is used to let the underlying implementation know which alignment to expect. +// The pointer can have scalar alignment, which is something the compiler cannot know unless you tell it. +// It is best to use vector alignment when you can for optimal performance, but scalar alignment is sometimes useful. +// With SSBOs, the API has a minimum offset alignment which guarantees a minimum level of alignment from API side. + +// In push constant we place a pointer to VBO pointers, spicy! +// This way we don't need any descriptor sets, but there's nothing wrong with combining use of descriptor sets and buffer device addresses. +// It is mostly done for convenience here. +struct Registers +{ + float2 **positions; + // A buffer reference is 64-bit, so offset of fract_time is 8 bytes. + float fract_time; +} + +[shader("compute")] +[numthreads(8, 8, 1)] +void main(uint3 globalInvocationID: SV_DispatchThreadID, uint3 workgroupID: SV_GroupID, uniform Registers registers) +{ + uint3 workgroupSize = WorkgroupSize(); + uint3 workgroupCount = WorkgroupCount(); + + // Every slice is a 8x8 grid of vertices which we update here in compute. + uint2 local_offset = globalInvocationID.xy; + uint local_index = local_offset.y * workgroupSize.x * workgroupCount.x + local_offset.x; + uint slice = workgroupID.z; + + float2 *positions = registers.positions[slice]; + + // This is a trivial wave-like function. Arbitrary for demonstration purposes. + const float TWO_PI = 3.1415628 * 2.0; + float offset = TWO_PI * fract(registers.fract_time + float(slice) * 0.1); + + // Simple grid. + float2 pos = float2(local_offset); + + // Wobble, wobble. + pos.x += 0.2 * sin(2.2 * pos.x + offset); + pos.y += 0.2 * sin(2.25 * pos.y + 2.0 * offset); + pos.x += 0.2 * cos(1.8 * pos.y + 3.0 * offset); + pos.y += 0.2 * cos(2.85 * pos.x + 4.0 * offset); + pos.x += 0.5 * sin(offset); + pos.y += 0.5 * sin(offset + 0.3); + + // Center the mesh in [-0.5, 0.5] range. + // Here we write to a raw pointer. + // Be aware, there is no robustness support for buffer_device_address since we don't have a complete descriptor! + positions[local_index] = pos / (float2(workgroupSize.xy) * float2(workgroupCount.xy) - 1.0) - 0.5; +} diff --git a/shaders/buffer_device_address/slang/update_vbo.comp.spv b/shaders/buffer_device_address/slang/update_vbo.comp.spv new file mode 100644 index 0000000000..2f88cdb8c7 Binary files /dev/null and b/shaders/buffer_device_address/slang/update_vbo.comp.spv differ diff --git a/shaders/color_write_enable/slang/composition.frag.slang b/shaders/color_write_enable/slang/composition.frag.slang new file mode 100644 index 0000000000..76a7c9eade --- /dev/null +++ b/shaders/color_write_enable/slang/composition.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::input_attachment_index(0)]] SubpassInput in_color_r; +[[vk::input_attachment_index(1)]] SubpassInput in_color_g; +[[vk::input_attachment_index(2)]] SubpassInput in_color_b; + +[shader("fragment")] +float4 main() +{ + float4 color_r = in_color_r.SubpassLoad(); + float4 color_g = in_color_g.SubpassLoad(); + float4 color_b = in_color_b.SubpassLoad(); + + return color_r + color_g + color_b; +} diff --git a/shaders/color_write_enable/slang/composition.frag.spv b/shaders/color_write_enable/slang/composition.frag.spv new file mode 100644 index 0000000000..acf8a18133 Binary files /dev/null and b/shaders/color_write_enable/slang/composition.frag.spv differ diff --git a/shaders/color_write_enable/slang/composition.vert.slang b/shaders/color_write_enable/slang/composition.vert.slang new file mode 100644 index 0000000000..0c1ebc5a25 --- /dev/null +++ b/shaders/color_write_enable/slang/composition.vert.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex : SV_VertexID) +{ + VSOutput output; + float2 uv = float2((VertexIndex << 1) & 2, VertexIndex & 2); + output.Pos = float4(uv * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} \ No newline at end of file diff --git a/shaders/color_write_enable/slang/composition.vert.spv b/shaders/color_write_enable/slang/composition.vert.spv new file mode 100644 index 0000000000..7ddf817845 Binary files /dev/null and b/shaders/color_write_enable/slang/composition.vert.spv differ diff --git a/shaders/color_write_enable/slang/triangle_separate_channels.frag.slang b/shaders/color_write_enable/slang/triangle_separate_channels.frag.slang new file mode 100644 index 0000000000..663cf89be0 --- /dev/null +++ b/shaders/color_write_enable/slang/triangle_separate_channels.frag.slang @@ -0,0 +1,42 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +struct FSOutput +{ + float4 ColorR; + float4 ColorG; + float4 ColorB; +}; + +// The full color is copied to individual attachments. +// Each attachment has a single component bit (R, G, B) enabled +// via the blend_attachment in ColorWriteEnable::prepare_pipelines. +[shader("fragment")] +FSOutput main(VSOutput Input) +{ + FSOutput output; + output.ColorR = float4(Input.Color, 1.0f); + output.ColorG = float4(Input.Color, 1.0f); + output.ColorB = float4(Input.Color, 1.0f); + return output; +} diff --git a/shaders/color_write_enable/slang/triangle_separate_channels.frag.spv b/shaders/color_write_enable/slang/triangle_separate_channels.frag.spv new file mode 100644 index 0000000000..192626f377 Binary files /dev/null and b/shaders/color_write_enable/slang/triangle_separate_channels.frag.spv differ diff --git a/shaders/color_write_enable/slang/triangle_separate_channels.vert.slang b/shaders/color_write_enable/slang/triangle_separate_channels.vert.slang new file mode 100644 index 0000000000..7710c0656c --- /dev/null +++ b/shaders/color_write_enable/slang/triangle_separate_channels.vert.slang @@ -0,0 +1,44 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +static float2 triangle_positions[3] = { + float2(0.0, -0.5), + float2(0.5, 0.5), + float2(-0.5, 0.5) +}; + +static float3 triangle_colors[3] = { + float3(1.0, 0.0, 0.0), + float3(0.0, 1.0, 0.0), + float3(0.0, 0.0, 1.0) +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex : SV_VertexID) +{ + VSOutput output; + output.Pos = float4(triangle_positions[VertexIndex], 0.0, 1.0); + output.Color = triangle_colors[VertexIndex]; + return output; +} + diff --git a/shaders/color_write_enable/slang/triangle_separate_channels.vert.spv b/shaders/color_write_enable/slang/triangle_separate_channels.vert.spv new file mode 100644 index 0000000000..f9ce52c127 Binary files /dev/null and b/shaders/color_write_enable/slang/triangle_separate_channels.vert.spv differ diff --git a/shaders/compute_nbody/slang/particle.frag.slang b/shaders/compute_nbody/slang/particle.frag.slang new file mode 100644 index 0000000000..1069c0624c --- /dev/null +++ b/shaders/compute_nbody/slang/particle.frag.slang @@ -0,0 +1,33 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Sampler2D samplerColorMap; +Sampler2D samplerGradientRamp; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 PointCoord : SV_PointCoord; + float GradientPos; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float3 color = samplerGradientRamp.Sample(float2(input.GradientPos, 0.0)).rgb; + return float4(samplerColorMap.Sample(input.PointCoord).rgb * color, 1.0); +} \ No newline at end of file diff --git a/shaders/compute_nbody/slang/particle.frag.spv b/shaders/compute_nbody/slang/particle.frag.spv new file mode 100644 index 0000000000..de6ec18895 Binary files /dev/null and b/shaders/compute_nbody/slang/particle.frag.spv differ diff --git a/shaders/compute_nbody/slang/particle.vert.slang b/shaders/compute_nbody/slang/particle.vert.slang new file mode 100644 index 0000000000..15915bd475 --- /dev/null +++ b/shaders/compute_nbody/slang/particle.vert.slang @@ -0,0 +1,51 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float4 Pos; + float4 Vel; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float PointSize : SV_PointSize; + float GradientPos; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float2 screendim; +}; +[[vk::binding(2, 0)]] ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + const float spriteSize = 0.005 * input.Pos.w; // Point size influenced by mass (stored in input.Pos.w); + float4 eyePos = mul(ubo.modelview, float4(input.Pos.x, input.Pos.y, input.Pos.z, 1.0)); + // Use projection to make sure point sizes uniformly scale independent of current projection + float4 projectedCorner = mul(ubo.projection, float4(0.5 * spriteSize, 0.5 * spriteSize, eyePos.z, eyePos.w)); + output.PointSize = clamp(ubo.screendim.x * projectedCorner.x / projectedCorner.w, 1.0, 128.0); + output.Pos = mul(ubo.projection, eyePos); + output.GradientPos = input.Vel.w; + return output; +} \ No newline at end of file diff --git a/shaders/compute_nbody/slang/particle.vert.spv b/shaders/compute_nbody/slang/particle.vert.spv new file mode 100644 index 0000000000..b6ce6c3d8d Binary files /dev/null and b/shaders/compute_nbody/slang/particle.vert.spv differ diff --git a/shaders/compute_nbody/slang/particle_calculate.comp.slang b/shaders/compute_nbody/slang/particle_calculate.comp.slang new file mode 100644 index 0000000000..db54d7e39d --- /dev/null +++ b/shaders/compute_nbody/slang/particle_calculate.comp.slang @@ -0,0 +1,87 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Particle +{ + float4 pos; + float4 vel; +}; +RWStructuredBuffer particles; + +struct UBO +{ + float deltaT; + int particleCount; +}; +ConstantBuffer ubo; + +[[vk::constant_id(1)]] const int SHARED_DATA_SIZE = 1024; +[[vk::constant_id(2)]] const float GRAVITY = 0.002; +[[vk::constant_id(3)]] const float POWER = 0.75; +[[vk::constant_id(4)]] const float SOFTEN = 0.05; + +// Share data between computer shader invocations to speed up caluclations +groupshared float4 sharedData[SHARED_DATA_SIZE]; + +#define TIME_FACTOR 0.05 + +[shader("compute")] +[numthreads(256, 1, 1)] +void main(uint3 GlobalInvocationID : SV_DispatchThreadID, uint3 LocalInvocationID : SV_GroupThreadID) +{ + // Current SSBO index + uint index = GlobalInvocationID.x; + if (index >= ubo.particleCount) + return; + + float4 position = particles[index].pos; + float4 velocity = particles[index].vel; + float4 acceleration = float4(0, 0, 0, 0); + int3 workgroupSize = WorkgroupSize(); + + for (int i = 0; i < ubo.particleCount; i += SHARED_DATA_SIZE) + { + if (i + LocalInvocationID.x < ubo.particleCount) + { + sharedData[LocalInvocationID.x] = particles[i + LocalInvocationID.x].pos; + } + else + { + sharedData[LocalInvocationID.x] = float4(0, 0, 0, 0); + } + + GroupMemoryBarrierWithGroupSync(); + + for (int j = 0; j < workgroupSize.x; j++) + { + float4 other = sharedData[j]; + float3 len = other.xyz - position.xyz; + acceleration.xyz += GRAVITY * len * other.w / pow(dot(len, len) + SOFTEN, POWER); + } + + GroupMemoryBarrierWithGroupSync(); + } + + particles[index].vel.xyz += ubo.deltaT * TIME_FACTOR * acceleration.xyz; + + // Gradient texture position + particles[index].vel.w += 0.1 * TIME_FACTOR * ubo.deltaT; + if (particles[index].vel.w > 1.0) + { + particles[index].vel.w -= 1.0; + } +} \ No newline at end of file diff --git a/shaders/compute_nbody/slang/particle_calculate.comp.spv b/shaders/compute_nbody/slang/particle_calculate.comp.spv new file mode 100644 index 0000000000..1c0b7bfb94 Binary files /dev/null and b/shaders/compute_nbody/slang/particle_calculate.comp.spv differ diff --git a/shaders/compute_nbody/slang/particle_integrate.comp.slang b/shaders/compute_nbody/slang/particle_integrate.comp.slang new file mode 100644 index 0000000000..559a357dff --- /dev/null +++ b/shaders/compute_nbody/slang/particle_integrate.comp.slang @@ -0,0 +1,43 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Particle +{ + float4 pos; + float4 vel; +}; +RWStructuredBuffer particles; + +struct UBO +{ + float deltaT; + int particleCount; +}; +ConstantBuffer ubo; + +#define TIME_FACTOR 0.05 + +[shader("compute")] +[numthreads(256, 1, 1)] +void main(uint3 GlobalInvocationID : SV_DispatchThreadID) +{ + int index = int(GlobalInvocationID.x); + float4 position = particles[index].pos; + float4 velocity = particles[index].vel; + position += ubo.deltaT * TIME_FACTOR * velocity; + particles[index].pos = position; +} \ No newline at end of file diff --git a/shaders/compute_nbody/slang/particle_integrate.comp.spv b/shaders/compute_nbody/slang/particle_integrate.comp.spv new file mode 100644 index 0000000000..325e3af7ae Binary files /dev/null and b/shaders/compute_nbody/slang/particle_integrate.comp.spv differ diff --git a/shaders/conditional_rendering/hlsl/model.vert.hlsl b/shaders/conditional_rendering/hlsl/model.vert.hlsl index b42125304c..da99759d16 100644 --- a/shaders/conditional_rendering/hlsl/model.vert.hlsl +++ b/shaders/conditional_rendering/hlsl/model.vert.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -49,7 +49,8 @@ VSOutput main(VSInput input) { VSOutput output = (VSOutput) 0; float4 localPos = mul(ubo.view, mul(push_constants.model, float4(input.Pos, 1.0))); - output.Normal = input.Normal; + float3x3 nMat = (float3x3) mul(ubo.view, push_constants.model); + output.Normal = mul(nMat, input.Normal); output.Color = push_constants.color.rgb; output.Pos = mul(ubo.projection, localPos); const float3 lightPos = float3(10.0, -10.0, 10.0); diff --git a/shaders/conditional_rendering/hlsl/model.vert.spv b/shaders/conditional_rendering/hlsl/model.vert.spv index 8d18a37e56..d12230845a 100644 Binary files a/shaders/conditional_rendering/hlsl/model.vert.spv and b/shaders/conditional_rendering/hlsl/model.vert.spv differ diff --git a/shaders/conditional_rendering/slang/model.frag.slang b/shaders/conditional_rendering/slang/model.frag.slang new file mode 100644 index 0000000000..a733c67553 --- /dev/null +++ b/shaders/conditional_rendering/slang/model.frag.slang @@ -0,0 +1,38 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 ViewVec; + float3 LightVec; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 ambient = float3(0.25); + float3 diffuse = max(dot(N, L), 0.0) * float3(1.0); + float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75); + return float4((ambient + diffuse) * input.Color.rgb + specular, 1.0); +} \ No newline at end of file diff --git a/shaders/conditional_rendering/slang/model.frag.spv b/shaders/conditional_rendering/slang/model.frag.spv new file mode 100644 index 0000000000..3574a5ecb1 Binary files /dev/null and b/shaders/conditional_rendering/slang/model.frag.spv differ diff --git a/shaders/conditional_rendering/slang/model.vert.slang b/shaders/conditional_rendering/slang/model.vert.slang new file mode 100644 index 0000000000..a88880b913 --- /dev/null +++ b/shaders/conditional_rendering/slang/model.vert.slang @@ -0,0 +1,54 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; + float4x4 model; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4x4 modelMatrix, uniform float4 modelColor) +{ + VSOutput output; + float4 localPos = mul(ubo.view, mul(modelMatrix, float4(input.Pos, 1.0))); + float3x3 nMat = (float3x3)mul(ubo.view, modelMatrix); + output.Normal = mul(nMat, input.Normal); + output.Color = modelColor.rgb; + output.Pos = mul(ubo.projection, localPos); + const float3 lightPos = float3(10.0, -10.0, 10.0); + output.LightVec = lightPos - localPos.xyz; + output.ViewVec = -localPos.xyz; + return output; +} \ No newline at end of file diff --git a/shaders/conditional_rendering/slang/model.vert.spv b/shaders/conditional_rendering/slang/model.vert.spv new file mode 100644 index 0000000000..797b77166d Binary files /dev/null and b/shaders/conditional_rendering/slang/model.vert.spv differ diff --git a/shaders/conservative_rasterization/slang/fullscreen.frag.slang b/shaders/conservative_rasterization/slang/fullscreen.frag.slang new file mode 100644 index 0000000000..173f9c12d7 --- /dev/null +++ b/shaders/conservative_rasterization/slang/fullscreen.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[[vk::binding(1, 0)]] Sampler2D samplerColor; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColor.Sample(input.UV); +} \ No newline at end of file diff --git a/shaders/conservative_rasterization/slang/fullscreen.frag.spv b/shaders/conservative_rasterization/slang/fullscreen.frag.spv new file mode 100644 index 0000000000..7a3e003c10 Binary files /dev/null and b/shaders/conservative_rasterization/slang/fullscreen.frag.spv differ diff --git a/shaders/conservative_rasterization/slang/fullscreen.vert.slang b/shaders/conservative_rasterization/slang/fullscreen.vert.slang new file mode 100644 index 0000000000..fd64a125b8 --- /dev/null +++ b/shaders/conservative_rasterization/slang/fullscreen.vert.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex: SV_VertexID) +{ + VSOutput output; + output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2); + output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} \ No newline at end of file diff --git a/shaders/conservative_rasterization/slang/fullscreen.vert.spv b/shaders/conservative_rasterization/slang/fullscreen.vert.spv new file mode 100644 index 0000000000..26860adcd1 Binary files /dev/null and b/shaders/conservative_rasterization/slang/fullscreen.vert.spv differ diff --git a/shaders/conservative_rasterization/slang/triangle.frag.slang b/shaders/conservative_rasterization/slang/triangle.frag.slang new file mode 100644 index 0000000000..939b207dd9 --- /dev/null +++ b/shaders/conservative_rasterization/slang/triangle.frag.slang @@ -0,0 +1,28 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return float4(input.Color, 1.0); +} \ No newline at end of file diff --git a/shaders/conservative_rasterization/slang/triangle.frag.spv b/shaders/conservative_rasterization/slang/triangle.frag.spv new file mode 100644 index 0000000000..57e6ef985c Binary files /dev/null and b/shaders/conservative_rasterization/slang/triangle.frag.spv differ diff --git a/shaders/conservative_rasterization/slang/triangle.vert.slang b/shaders/conservative_rasterization/slang/triangle.vert.slang new file mode 100644 index 0000000000..5f09c7f334 --- /dev/null +++ b/shaders/conservative_rasterization/slang/triangle.vert.slang @@ -0,0 +1,44 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Color; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Color = input.Color; + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos, 1.0))); + return output; +} \ No newline at end of file diff --git a/shaders/conservative_rasterization/slang/triangle.vert.spv b/shaders/conservative_rasterization/slang/triangle.vert.spv new file mode 100644 index 0000000000..b18139e2a4 Binary files /dev/null and b/shaders/conservative_rasterization/slang/triangle.vert.spv differ diff --git a/shaders/conservative_rasterization/slang/triangleoverlay.frag.slang b/shaders/conservative_rasterization/slang/triangleoverlay.frag.slang new file mode 100644 index 0000000000..f6eee87537 --- /dev/null +++ b/shaders/conservative_rasterization/slang/triangleoverlay.frag.slang @@ -0,0 +1,22 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[shader("fragment")] +float4 main() +{ + return float4(1.0, 1.0, 1.0, 1.0); +} \ No newline at end of file diff --git a/shaders/conservative_rasterization/slang/triangleoverlay.frag.spv b/shaders/conservative_rasterization/slang/triangleoverlay.frag.spv new file mode 100644 index 0000000000..816bfd9ffe Binary files /dev/null and b/shaders/conservative_rasterization/slang/triangleoverlay.frag.spv differ diff --git a/shaders/debug_utils/hlsl/bloom.frag.hlsl b/shaders/debug_utils/hlsl/bloom.frag.hlsl index fda19e15f6..4edc5ca634 100644 --- a/shaders/debug_utils/hlsl/bloom.frag.hlsl +++ b/shaders/debug_utils/hlsl/bloom.frag.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -52,8 +52,8 @@ float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET 0.0024499299678342}; - const float blurScale = 0.003; - const float blurStrength = 1.0; + const float blurScale = 0.004; + const float blurStrength = 0.6; float ar = 1.0; // Aspect ratio for vertical blur pass diff --git a/shaders/debug_utils/hlsl/bloom.frag.spv b/shaders/debug_utils/hlsl/bloom.frag.spv index 53b8873486..a64091b893 100644 Binary files a/shaders/debug_utils/hlsl/bloom.frag.spv and b/shaders/debug_utils/hlsl/bloom.frag.spv differ diff --git a/shaders/debug_utils/slang/bloom.frag.slang b/shaders/debug_utils/slang/bloom.frag.slang new file mode 100644 index 0000000000..6bf579022e --- /dev/null +++ b/shaders/debug_utils/slang/bloom.frag.slang @@ -0,0 +1,76 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Sampler2D samplerColor0; +Sampler2D samplerColor1; + +[[SpecializationConstant]] const int dir = 0; + +[shader("fragment")] +float4 main(float2 inUV : TEXCOORD0) +{ + // From the OpenGL Super bible + const float weights[] = { 0.0024499299678342, + 0.0043538453346397, + 0.0073599963704157, + 0.0118349786570722, + 0.0181026699707781, + 0.0263392293891488, + 0.0364543006660986, + 0.0479932050577658, + 0.0601029809166942, + 0.0715974486241365, + 0.0811305381519717, + 0.0874493212267511, + 0.0896631113333857, + 0.0874493212267511, + 0.0811305381519717, + 0.0715974486241365, + 0.0601029809166942, + 0.0479932050577658, + 0.0364543006660986, + 0.0263392293891488, + 0.0181026699707781, + 0.0118349786570722, + 0.0073599963704157, + 0.0043538453346397, + 0.0024499299678342}; + + + const float blurScale = 0.003; + const float blurStrength = 1.0; + + float ar = 1.0; + // Aspect ratio for vertical blur pass + if (dir == 1) + { + float2 ts; + samplerColor1.GetDimensions(ts.x, ts.y); + ar = ts.y / ts.x; + } + + float2 P = inUV.yx - float2(0, (weights.getCount() >> 1) * ar * blurScale); + + float4 color = float4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < weights.getCount(); i++) + { + float2 dv = float2(0.0, i * blurScale) * ar; + color += samplerColor1.Sample(P + dv) * weights[i] * blurStrength; + } + + return color; +} \ No newline at end of file diff --git a/shaders/debug_utils/slang/bloom.frag.spv b/shaders/debug_utils/slang/bloom.frag.spv new file mode 100644 index 0000000000..e5b9623eb2 Binary files /dev/null and b/shaders/debug_utils/slang/bloom.frag.spv differ diff --git a/shaders/debug_utils/slang/bloom.vert.slang b/shaders/debug_utils/slang/bloom.vert.slang new file mode 100644 index 0000000000..162407b488 --- /dev/null +++ b/shaders/debug_utils/slang/bloom.vert.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex : SV_VertexID) +{ + VSOutput output; + output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2); + output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} diff --git a/shaders/debug_utils/slang/bloom.vert.spv b/shaders/debug_utils/slang/bloom.vert.spv new file mode 100644 index 0000000000..26860adcd1 Binary files /dev/null and b/shaders/debug_utils/slang/bloom.vert.spv differ diff --git a/shaders/debug_utils/slang/composition.frag.slang b/shaders/debug_utils/slang/composition.frag.slang new file mode 100644 index 0000000000..0d7e4a00b3 --- /dev/null +++ b/shaders/debug_utils/slang/composition.frag.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Sampler2D samplerColor0; +Sampler2D samplerColor1; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColor0.Sample(input.UV); +} \ No newline at end of file diff --git a/shaders/debug_utils/slang/composition.frag.spv b/shaders/debug_utils/slang/composition.frag.spv new file mode 100644 index 0000000000..3da8d86bed Binary files /dev/null and b/shaders/debug_utils/slang/composition.frag.spv differ diff --git a/shaders/debug_utils/slang/composition.vert.slang b/shaders/debug_utils/slang/composition.vert.slang new file mode 100644 index 0000000000..162407b488 --- /dev/null +++ b/shaders/debug_utils/slang/composition.vert.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex : SV_VertexID) +{ + VSOutput output; + output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2); + output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} diff --git a/shaders/debug_utils/slang/composition.vert.spv b/shaders/debug_utils/slang/composition.vert.spv new file mode 100644 index 0000000000..26860adcd1 Binary files /dev/null and b/shaders/debug_utils/slang/composition.vert.spv differ diff --git a/shaders/debug_utils/slang/gbuffer.frag.slang b/shaders/debug_utils/slang/gbuffer.frag.slang new file mode 100644 index 0000000000..73fd55d29f --- /dev/null +++ b/shaders/debug_utils/slang/gbuffer.frag.slang @@ -0,0 +1,71 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] Sampler2D samplerEnvMap; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +struct FSOutput +{ + float4 Color0; + float4 Color1; +}; + +[shader("fragment")] +FSOutput main(VSOutput input, uniform float4 offset, uniform float4 color, uniform int object_type) +{ + FSOutput output; + float4 out_color; + + switch (object_type) { + case 0: // Skysphere + { + out_color = samplerEnvMap.Sample(float2(input.UV.x, 1.0 - input.UV.y)); + } + break; + + case 1: // Phong shading + { + float3 ambient = color.rgb * 0.5; + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = max(dot(N, L), 0.0).xxx * color.rgb; + float3 specular = (pow(max(dot(R, V), 0.0), 8.0)).xxx; + out_color = float4(ambient + diffuse + specular, 1.0); + } + break; + } + + // Base color into attachment 0 + output.Color0 = float4(out_color.rgb, 1.0); + + // Bright parts for bloom into attachment 1 + float l = dot(output.Color0.rgb, float3(0.2126, 0.7152, 0.0722)); + float threshold = 0.75; + output.Color1.rgb = (l > threshold) ? output.Color0.rgb : float3(0.0, 0.0, 0.0); + output.Color1.a = 1.0; + return output; +} \ No newline at end of file diff --git a/shaders/debug_utils/slang/gbuffer.frag.spv b/shaders/debug_utils/slang/gbuffer.frag.spv new file mode 100644 index 0000000000..5e51c7a58d Binary files /dev/null and b/shaders/debug_utils/slang/gbuffer.frag.spv differ diff --git a/shaders/debug_utils/slang/gbuffer.vert.slang b/shaders/debug_utils/slang/gbuffer.vert.slang new file mode 100644 index 0000000000..2ff5182828 --- /dev/null +++ b/shaders/debug_utils/slang/gbuffer.vert.slang @@ -0,0 +1,66 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; +}; + +struct UBO { + float4x4 projection; + float4x4 modelview; + float4x4 skyboxModelview; + float modelscale; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4 offset, uniform float4 color, uniform int object_type) +{ + VSOutput output; + float3 worldPos; + + switch(object_type) { + case 0: // Skybox + worldPos = mul((float3x3) ubo.skyboxModelview, input.Pos.xyz); + output.Pos = mul(ubo.projection, float4(worldPos, 1.0)); + break; + case 1: // Object + float3 localPos = input.Pos * ubo.modelscale + offset.xyz; + worldPos = mul(ubo.modelview, float4(localPos, 1.0)).xyz; + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(localPos, 1.0))); + break; + } + output.Normal = mul((float3x3)ubo.modelview, input.Normal); + output.UV = input.UV; + + float3 lightPos = float3(0.0f, -10.0f, 10.0f); + output.LightVec = lightPos.xyz - worldPos.xyz; + output.ViewVec = -worldPos.xyz; + return output; +} diff --git a/shaders/debug_utils/slang/gbuffer.vert.spv b/shaders/debug_utils/slang/gbuffer.vert.spv new file mode 100644 index 0000000000..61f7c1458b Binary files /dev/null and b/shaders/debug_utils/slang/gbuffer.vert.spv differ diff --git a/shaders/descriptor_buffer_basic/glsl/cube.vert b/shaders/descriptor_buffer_basic/glsl/cube.vert index 43a8bdb35b..df6a230c6c 100644 --- a/shaders/descriptor_buffer_basic/glsl/cube.vert +++ b/shaders/descriptor_buffer_basic/glsl/cube.vert @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2023-2024, Sascha Willems +/* Copyright (c) 2023-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -17,8 +17,7 @@ */ layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV; +layout (location = 1) in vec2 inUV; layout (set = 0, binding = 0) uniform UBOScene { mat4 projection; diff --git a/shaders/descriptor_buffer_basic/glsl/cube.vert.spv b/shaders/descriptor_buffer_basic/glsl/cube.vert.spv index fc95678628..6eee67a683 100644 Binary files a/shaders/descriptor_buffer_basic/glsl/cube.vert.spv and b/shaders/descriptor_buffer_basic/glsl/cube.vert.spv differ diff --git a/shaders/descriptor_buffer_basic/hlsl/cube.vert.hlsl b/shaders/descriptor_buffer_basic/hlsl/cube.vert.hlsl index 7afdcdca89..6cd690e60f 100644 --- a/shaders/descriptor_buffer_basic/hlsl/cube.vert.hlsl +++ b/shaders/descriptor_buffer_basic/hlsl/cube.vert.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -18,8 +18,7 @@ struct VSInput { [[vk::location(0)]] float3 Pos : POSITION0; - [[vk::location(1)]] float3 Normal : NORMAL0; - [[vk::location(2)]] float2 UV : TEXCOORD0; + [[vk::location(1)]] float2 UV : TEXCOORD0; }; struct UBOCamera diff --git a/shaders/descriptor_buffer_basic/hlsl/cube.vert.spv b/shaders/descriptor_buffer_basic/hlsl/cube.vert.spv index 580d0d31c5..4e07bc6f0b 100644 Binary files a/shaders/descriptor_buffer_basic/hlsl/cube.vert.spv and b/shaders/descriptor_buffer_basic/hlsl/cube.vert.spv differ diff --git a/shaders/descriptor_buffer_basic/slang/cube.frag.slang b/shaders/descriptor_buffer_basic/slang/cube.frag.slang new file mode 100644 index 0000000000..8d5f117321 --- /dev/null +++ b/shaders/descriptor_buffer_basic/slang/cube.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[[vk::binding(0, 2)]] Sampler2D samplerColorMap; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColorMap.Sample(input.UV); +} \ No newline at end of file diff --git a/shaders/descriptor_buffer_basic/slang/cube.frag.spv b/shaders/descriptor_buffer_basic/slang/cube.frag.spv new file mode 100644 index 0000000000..f7b54d9c1b Binary files /dev/null and b/shaders/descriptor_buffer_basic/slang/cube.frag.spv differ diff --git a/shaders/descriptor_buffer_basic/slang/cube.vert.slang b/shaders/descriptor_buffer_basic/slang/cube.vert.slang new file mode 100644 index 0000000000..7e56262d7d --- /dev/null +++ b/shaders/descriptor_buffer_basic/slang/cube.vert.slang @@ -0,0 +1,48 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +struct UBOCamera { + float4x4 projection; + float4x4 view; +}; +ConstantBuffer uboCamera; + +struct UBOModel { + float4x4 local; +}; +[[vk::binding(0, 1)]] ConstantBuffer uboModel; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(uboCamera.projection, mul(uboCamera.view, mul(uboModel.local, float4(input.Pos.xyz, 1.0)))); + return output; +} \ No newline at end of file diff --git a/shaders/descriptor_buffer_basic/slang/cube.vert.spv b/shaders/descriptor_buffer_basic/slang/cube.vert.spv new file mode 100644 index 0000000000..f22d5c5e9a Binary files /dev/null and b/shaders/descriptor_buffer_basic/slang/cube.vert.spv differ diff --git a/shaders/descriptor_indexing/slang/nonuniform-quads.frag.slang b/shaders/descriptor_indexing/slang/nonuniform-quads.frag.slang new file mode 100644 index 0000000000..8001ffd00b --- /dev/null +++ b/shaders/descriptor_indexing/slang/nonuniform-quads.frag.slang @@ -0,0 +1,94 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + nointerpolation uint TextureIndex; +}; + +[[vk::binding(0, 0)]] Texture2D Textures[]; +[[vk::binding(0, 1)]] SamplerState ImmutableSampler; + +[shader("fragment")] +float4 main(VSOutput input) +{ + // Here we are indexing into the texture array, with a non-uniform index. + // Across the draw-call, there are different instance indices being used, so we must use nonuniformEXT. + // It is important to note that to be 100% correct, we must use: + // nonuniformEXT(sampler2D()). + // It is the final argument to a call like texture() which determines if the access is to be considered non-uniform. + // It is very common in the wild to see code like: + // - sampler2D(Textures[nonuniformEXT(in_texture_index)], ...) + // This looks very similar to HLSL, but it is somewhat wrong. + // Generally, it will work on drivers, but it is not technically correct. + + // To quote GL_EXT_nonuniform_qualifier: + + /* + Only some operations discussed in Chapter 5 (Operators and Expressions) + can be applied to nonuniform value(s) and still yield a result that is + nonuniform. The operations that do so are listed below. When a + nonuniform value is operated on with one of these operators (regardless + of whether any and other operands are nonuniform), the result is + implicitly nonuniform: + + ... + + * Structure and Array Operations in Section 5.7, except for the length + method and assignment operator. + + ... + + Constructors and builtin functions, which all have return types that + are not qualified by nonuniformEXT, will not generate nonuniform results. + Shaders need to use the constructor syntax (or assignment to a + nonuniformEXT-qualified variable) to re-add the nonuniformEXT qualifier + to the result of builtin functions. + + ... + */ + + // sampler2D is such a constructor, so we must add nonuniformEXT afterwards. + return Textures[NonUniformResourceIndex(input.TextureIndex)].Sample(ImmutableSampler, input.UV); + + // For all other use cases of nonuniformEXT however, we can write code like: + // uniform UBO { vec4 data; } UBOs[]; vec4 foo = UBOs[nonuniformEXT(index)].data; + // buffer SSBO { vec4 data; } SSBOs[]; vec4 foo = SSBOs[nonuniformEXT(index)].data; + // uniform sampler2D Tex[]; vec4 foo = texture(Tex[nonuniformEXT(index)], uv); + // uniform uimage2D Img[]; uint count = imageAtomicAdd(Img[nonuniformEXT(index)], uv, val); + // etc. The nonuniform qualifier will propagate up to the final argument which is used in the load/store or atomic operation. + + // Using implicit LOD with nonuniformEXT can be spicy! If the threads in a quad do not have the same index, + // LOD might not be computed correctly. The quadDivergentImplicitLOD property lets you know if it will work. + // In this case however, it is completely fine, since the helper lanes in a quad must come from the same primitive, + // which all have the same flat fragment input. + + // You might consider using subgroup operations to implement nonuniformEXT on your own. + // This is technically out of spec, since the SPIR-V specification states that to avoid nonuniformEXT, + // the shader must guarantee that the index is "dynamically uniform". + // "Dynamically uniform" means the value is the same across all invocations in an "invocation group". + // The invocation group is defined to be all invocations (threads) for: + // - An entire draw command (for graphics) + // - A single workgroup (for compute). + // Avoiding nonuniformEXT with clever programming is far more likely to succeed when writing compute shaders, + // since the workgroup boundary serves as a much easier boundary to control than entire draw commands. + // It is often possible to match workgroup to subgroup 1:1, unlike graphics where you cannot control how + // quads are packed into subgroups at all. + // The recommended approach here is to just let the compiler do its thing to avoid horrible bugs in the future. +} diff --git a/shaders/descriptor_indexing/slang/nonuniform-quads.frag.spv b/shaders/descriptor_indexing/slang/nonuniform-quads.frag.spv new file mode 100644 index 0000000000..889af0c1eb Binary files /dev/null and b/shaders/descriptor_indexing/slang/nonuniform-quads.frag.spv differ diff --git a/shaders/descriptor_indexing/slang/nonuniform-quads.vert.slang b/shaders/descriptor_indexing/slang/nonuniform-quads.vert.slang new file mode 100644 index 0000000000..cbd49042ab --- /dev/null +++ b/shaders/descriptor_indexing/slang/nonuniform-quads.vert.slang @@ -0,0 +1,50 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + nointerpolation uint TextureIndex; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex: SV_VertexID, uint InstanceIndex: SV_VulkanInstanceID, uniform float registers_phase) +{ + VSOutput output; + + float2 local_offset = float2(VertexIndex & 1, VertexIndex >> 1); + output.UV = local_offset; + + // A lazy quad rotation, could easily have been precomputed on CPU. + float cos_phase = cos(registers_phase); + float sin_phase = sin(registers_phase); + local_offset = mul(float2x2(cos_phase, -sin_phase, sin_phase, cos_phase), (local_offset - 0.5)); + + // To keep the sample as simple as possible, use InstanceIndex to move the quads around on screen. + int instance_x = InstanceIndex % 8; + int instance_y = InstanceIndex / 8; + float2 instance_offset = float2(instance_x, instance_y) / float2(15.0, 7.0); + instance_offset = 2.1 * (instance_offset - 0.5); + + output.Pos = float4((0.10 * local_offset) + instance_offset, 0.0, 1.0); + + // Pass down an index which we will use to index into the descriptor array. + output.TextureIndex = InstanceIndex; + + return output; +} diff --git a/shaders/descriptor_indexing/slang/nonuniform-quads.vert.spv b/shaders/descriptor_indexing/slang/nonuniform-quads.vert.spv new file mode 100644 index 0000000000..311fec15ec Binary files /dev/null and b/shaders/descriptor_indexing/slang/nonuniform-quads.vert.spv differ diff --git a/shaders/descriptor_indexing/slang/update-after-bind-quads.frag.slang b/shaders/descriptor_indexing/slang/update-after-bind-quads.frag.slang new file mode 100644 index 0000000000..bc79e2043c --- /dev/null +++ b/shaders/descriptor_indexing/slang/update-after-bind-quads.frag.slang @@ -0,0 +1,44 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[[vk::binding(0, 0)]] Texture2D Textures[]; +[[vk::binding(0, 1)]] SamplerState ImmutableSampler; + +struct Registers +{ + [[vk::offset(4)]] uint table_offset; +}; +[[vk::push_constant]] Registers registers; + +[shader("fragment")] +float4 main(VSOutput input) +{ + // This is a very common usage pattern for streamed descriptors with UPDATE_AFTER_BIND. + // We only need to update push constants, and our materials can access new descriptors. + // This avoids having to allocate and manage individual descriptor sets. + // It does mean that the chance to introduce bugs is higher however ... + + // A push constant must be dynamically uniform over our draw call, so we do not have to do anything here. + // This is simply considered dynamic indexing, which is a feature in core Vulkan 1.0. + return Textures[registers.table_offset].Sample(ImmutableSampler, input.UV); +} diff --git a/shaders/descriptor_indexing/slang/update-after-bind-quads.frag.spv b/shaders/descriptor_indexing/slang/update-after-bind-quads.frag.spv new file mode 100644 index 0000000000..a3db2c71b4 Binary files /dev/null and b/shaders/descriptor_indexing/slang/update-after-bind-quads.frag.spv differ diff --git a/shaders/descriptor_indexing/slang/update-after-bind-quads.vert.slang b/shaders/descriptor_indexing/slang/update-after-bind-quads.vert.slang new file mode 100644 index 0000000000..3a6e4de38d --- /dev/null +++ b/shaders/descriptor_indexing/slang/update-after-bind-quads.vert.slang @@ -0,0 +1,46 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex: SV_VertexID, uint InstanceIndex: SV_VulkanInstanceID, uniform float registers_phase) +{ + VSOutput output; + + float2 local_offset = float2(VertexIndex & 1, VertexIndex >> 1); + output.UV = local_offset; + + // A lazy quad rotation, could easily have been precomputed on CPU. + float cos_phase = cos(registers_phase); + float sin_phase = sin(registers_phase); + local_offset = mul(float2x2(cos_phase, -sin_phase, sin_phase, cos_phase), (local_offset - 0.5)); + + // To keep the sample as simple as possible, use InstanceIndex to move the quads around on screen. + int instance_x = InstanceIndex % 8 + 8; + int instance_y = InstanceIndex / 8; + float2 instance_offset = float2(instance_x, instance_y) / float2(15.0, 7.0); + instance_offset = 2.1 * (instance_offset - 0.5); + + output.Pos = float4((0.10 * local_offset) + instance_offset, 0.0, 1.0); + + return output; +} diff --git a/shaders/descriptor_indexing/slang/update-after-bind-quads.vert.spv b/shaders/descriptor_indexing/slang/update-after-bind-quads.vert.spv new file mode 100644 index 0000000000..1254b1e3e5 Binary files /dev/null and b/shaders/descriptor_indexing/slang/update-after-bind-quads.vert.spv differ diff --git a/shaders/dynamic_blending/slang/blending.frag.slang b/shaders/dynamic_blending/slang/blending.frag.slang new file mode 100644 index 0000000000..ef284ea400 --- /dev/null +++ b/shaders/dynamic_blending/slang/blending.frag.slang @@ -0,0 +1,50 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + nointerpolation uint ColorOffset; +}; + +struct Col +{ + float4 data[8]; +}; +[[vk::binding(1, 0)]] ConstantBuffer color; + +float4 sampleColor(VSOutput input) +{ + float4 c00 = color.data[0 + input.ColorOffset]; + float4 c01 = color.data[1 + input.ColorOffset]; + float4 c02 = color.data[2 + input.ColorOffset]; + float4 c03 = color.data[3 + input.ColorOffset]; + + float4 b0 = lerp(c00, c01, input.UV.x); + float4 b1 = lerp(c02, c03, input.UV.x); + + float4 p0 = lerp(b0, b1, input.UV.y); + + return p0; +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + return sampleColor(input); +} \ No newline at end of file diff --git a/shaders/dynamic_blending/slang/blending.frag.spv b/shaders/dynamic_blending/slang/blending.frag.spv new file mode 100644 index 0000000000..016877f9b4 Binary files /dev/null and b/shaders/dynamic_blending/slang/blending.frag.spv differ diff --git a/shaders/dynamic_blending/slang/blending.vert.slang b/shaders/dynamic_blending/slang/blending.vert.slang new file mode 100644 index 0000000000..0dabab8e40 --- /dev/null +++ b/shaders/dynamic_blending/slang/blending.vert.slang @@ -0,0 +1,47 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; + float4x4 model; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + nointerpolation uint ColorOffset; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.ColorOffset = input.Pos.z == 1.0 ? 4 : 0; + output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos.xyz, 1.0)))); + return output; +} \ No newline at end of file diff --git a/shaders/dynamic_blending/slang/blending.vert.spv b/shaders/dynamic_blending/slang/blending.vert.spv new file mode 100644 index 0000000000..a56e7edf9f Binary files /dev/null and b/shaders/dynamic_blending/slang/blending.vert.spv differ diff --git a/shaders/dynamic_line_rasterization/slang/base.frag.slang b/shaders/dynamic_line_rasterization/slang/base.frag.slang new file mode 100644 index 0000000000..ff902259ea --- /dev/null +++ b/shaders/dynamic_line_rasterization/slang/base.frag.slang @@ -0,0 +1,22 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[shader("fragment")] +float4 main(uniform float4 color) +{ + return color; +} \ No newline at end of file diff --git a/shaders/dynamic_line_rasterization/slang/base.frag.spv b/shaders/dynamic_line_rasterization/slang/base.frag.spv new file mode 100644 index 0000000000..409a30ae53 Binary files /dev/null and b/shaders/dynamic_line_rasterization/slang/base.frag.spv differ diff --git a/shaders/dynamic_line_rasterization/slang/base.vert.slang b/shaders/dynamic_line_rasterization/slang/base.vert.slang new file mode 100644 index 0000000000..50501ddb7b --- /dev/null +++ b/shaders/dynamic_line_rasterization/slang/base.vert.slang @@ -0,0 +1,42 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; + float4x4 model; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Pos = mul(ubo.projection, mul(ubo.view, mul(ubo.model, float4(input.Pos - float3(0.0f, 1.0f, 0.0f), 1.0)))); + return output; +} diff --git a/shaders/dynamic_line_rasterization/slang/base.vert.spv b/shaders/dynamic_line_rasterization/slang/base.vert.spv new file mode 100644 index 0000000000..f620735360 Binary files /dev/null and b/shaders/dynamic_line_rasterization/slang/base.vert.spv differ diff --git a/shaders/dynamic_line_rasterization/slang/grid.frag.slang b/shaders/dynamic_line_rasterization/slang/grid.frag.slang new file mode 100644 index 0000000000..6414c3b58c --- /dev/null +++ b/shaders/dynamic_line_rasterization/slang/grid.frag.slang @@ -0,0 +1,63 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 nearPoint; + float3 farPoint; + float4x4 view; + float4x4 projection; +}; + +float4 grid(float3 pos) { + float2 coord = pos.xz; + float2 derivative = fwidth(coord); + float2 grid = abs(frac(coord - 0.5) - 0.5) / derivative; + float _line = min(grid.x, grid.y); + float minimumz = min(derivative.y, 1); + float minimumx = min(derivative.x, 1); + float4 color = float4(0.5, 0.5, 0.5, 1.0 - min(_line, 1.0)); + + if(abs(pos.x) < minimumx) + color.y = 1; + if(abs(pos.z) < minimumz) + color.x = 1; + return color; +} + +float fadeFactor(float3 pos, VSOutput input) { + float z = mul(input.projection, mul(input.view, float4(pos.xyz, 1.0))).z; + // Empirical values are used to determine when to cut off the grid before moire patterns become visible. + return z * 6 - 0.5; +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + float t = -input.nearPoint.y / (input.farPoint.y - input.nearPoint.y); + float3 pos = input.nearPoint + t * (input.farPoint - input.nearPoint); + + // Display only the lower plane + if(t < 1.0) { + float4 gridColor = grid(pos); + return float4(gridColor.xyz, gridColor.w * fadeFactor(pos, input)); + } + else { + return float4(0.0); + } +} diff --git a/shaders/dynamic_line_rasterization/slang/grid.frag.spv b/shaders/dynamic_line_rasterization/slang/grid.frag.spv new file mode 100644 index 0000000000..5c16cb153f Binary files /dev/null and b/shaders/dynamic_line_rasterization/slang/grid.frag.spv differ diff --git a/shaders/dynamic_line_rasterization/slang/grid.vert.slang b/shaders/dynamic_line_rasterization/slang/grid.vert.slang new file mode 100644 index 0000000000..cc1076e3d0 --- /dev/null +++ b/shaders/dynamic_line_rasterization/slang/grid.vert.slang @@ -0,0 +1,64 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + struct VSInput +{ + float3 Pos : POSITION0; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; + float4x4 model; + float4x4 viewProjectionInverse; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 nearPoint; + float3 farPoint; + float4x4 view; + float4x4 projection; +}; + +float3 unprojectPoint(float x, float y, float z, float4x4 viewProjectionInverse) { + float4 clipSpacePos = float4(x, y, z, 1.0); + float4 eyeSpacePos = mul(viewProjectionInverse, clipSpacePos); + return eyeSpacePos.xyz / eyeSpacePos.w; +} + +static float3 gridPlane[6] = { + float3(1, 1, 0), float3(-1, -1, 0), float3(-1, 1, 0), + float3(-1, -1, 0), float3(1, 1, 0), float3(1, -1, 0) +}; + +[shader("vertex")] +VSOutput main(VSInput input, uint VertexIndex : SV_VertexID) +{ + float3 pos = gridPlane[VertexIndex].xyz; + + VSOutput output; + output.nearPoint = unprojectPoint(pos.x, pos.y, 0.0, ubo.viewProjectionInverse); + output.farPoint = unprojectPoint(pos.x, pos.y, 1.0, ubo.viewProjectionInverse); + output.view = ubo.view; + output.projection = ubo.projection; + output.Pos = float4(pos, 1.0); + return output; +} \ No newline at end of file diff --git a/shaders/dynamic_line_rasterization/slang/grid.vert.spv b/shaders/dynamic_line_rasterization/slang/grid.vert.spv new file mode 100644 index 0000000000..becd1fa84b Binary files /dev/null and b/shaders/dynamic_line_rasterization/slang/grid.vert.spv differ diff --git a/shaders/dynamic_multisample_rasterization/model.frag b/shaders/dynamic_multisample_rasterization/glsl/model.frag similarity index 98% rename from shaders/dynamic_multisample_rasterization/model.frag rename to shaders/dynamic_multisample_rasterization/glsl/model.frag index fce5ad702f..7377a4233e 100644 --- a/shaders/dynamic_multisample_rasterization/model.frag +++ b/shaders/dynamic_multisample_rasterization/glsl/model.frag @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2024, Mobica Limited +/* Copyright (c) 2024-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/dynamic_multisample_rasterization/model.frag.spv b/shaders/dynamic_multisample_rasterization/glsl/model.frag.spv similarity index 100% rename from shaders/dynamic_multisample_rasterization/model.frag.spv rename to shaders/dynamic_multisample_rasterization/glsl/model.frag.spv diff --git a/shaders/dynamic_multisample_rasterization/model.vert b/shaders/dynamic_multisample_rasterization/glsl/model.vert similarity index 98% rename from shaders/dynamic_multisample_rasterization/model.vert rename to shaders/dynamic_multisample_rasterization/glsl/model.vert index 0a44336128..7f337136c9 100644 --- a/shaders/dynamic_multisample_rasterization/model.vert +++ b/shaders/dynamic_multisample_rasterization/glsl/model.vert @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2024, Mobica Limited +/* Copyright (c) 2024-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/dynamic_multisample_rasterization/model.vert.spv b/shaders/dynamic_multisample_rasterization/glsl/model.vert.spv similarity index 100% rename from shaders/dynamic_multisample_rasterization/model.vert.spv rename to shaders/dynamic_multisample_rasterization/glsl/model.vert.spv diff --git a/shaders/dynamic_multisample_rasterization/slang/model.frag.slang b/shaders/dynamic_multisample_rasterization/slang/model.frag.slang new file mode 100644 index 0000000000..18eded5be4 --- /dev/null +++ b/shaders/dynamic_multisample_rasterization/slang/model.frag.slang @@ -0,0 +1,79 @@ +/* Copyright (c) 2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; + float3 ViewVec; + float3 LightVec; + nointerpolation float4 BaseColorFactor; + nointerpolation float MetallicFactor; + nointerpolation float RoughnessFactor; + nointerpolation uint BaseTextureIndex; + nointerpolation uint NormalTextureIndex; + nointerpolation uint MetallicRoughnessTextureIndex; +}; + +[[vk::binding(1, 0)]] Sampler2D Textures[15]; + +float4 getColor(in VSOutput input) +{ + float4 color = input.BaseColorFactor; + + if (input.BaseTextureIndex != -1) + color = Textures[uint(round(input.BaseTextureIndex))].Sample(input.UV); + + return color; +} + +float3 getNormal(in VSOutput input) +{ + float3 normal = input.Normal; + + if (input.NormalTextureIndex != -1) + normal = Textures[uint(round(input.NormalTextureIndex))].Sample(input.UV).xyz * 2.0 - 1.0; + + return normal; +} + +float3 getPBR(in VSOutput input) +{ + float3 pbr = float3(input.MetallicFactor, input.RoughnessFactor, 0.0); + + if (input.MetallicRoughnessTextureIndex != -1) + pbr = Textures[uint(round(input.MetallicRoughnessTextureIndex))].Sample(input.UV).xyz; + + return pbr; +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + float3 N = normalize(getNormal(input)); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 ambient = float3(0.25); + float3 diffuse = max(dot(N, L), 0.0) * float3(0.75) * getPBR(input); + float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.75); + + float4 base_color = getColor(input); + return float4(ambient * base_color.rgb + specular, base_color.a); +} diff --git a/shaders/dynamic_multisample_rasterization/slang/model.frag.spv b/shaders/dynamic_multisample_rasterization/slang/model.frag.spv new file mode 100644 index 0000000000..f616395bd4 Binary files /dev/null and b/shaders/dynamic_multisample_rasterization/slang/model.frag.spv differ diff --git a/shaders/dynamic_multisample_rasterization/slang/model.vert.slang b/shaders/dynamic_multisample_rasterization/slang/model.vert.slang new file mode 100644 index 0000000000..031ae08313 --- /dev/null +++ b/shaders/dynamic_multisample_rasterization/slang/model.vert.slang @@ -0,0 +1,78 @@ +/* Copyright (c) 2024-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; + float3 ViewVec; + float3 LightVec; + nointerpolation float4 BaseColorFactor; + nointerpolation float MetallicFactor; + nointerpolation float RoughnessFactor; + nointerpolation uint BaseTextureIndex; + nointerpolation uint NormalTextureIndex; + nointerpolation uint MetallicRoughnessTextureIndex; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct Push_Constants { + float4x4 model; + + float4 base_color_factor; + float metallic_factor; + float roughness_factor; + + uint baseTextureIndex; + uint normalTextureIndex; + uint metallicRoughnessTextureIndex; +} ; + +[shader("vertex")] +VSOutput main(VSInput input, uniform Push_Constants push_constants) +{ + VSOutput output; + output.UV = input.UV; + float4 localPos = mul(ubo.view, mul(push_constants.model, float4(input.Pos, 1.0))); + output.Pos = mul(ubo.projection, localPos); + output.Normal = mul(float3x3(mul(ubo.view, push_constants.model)), input.Normal); + float3 lightPos = float3(10.0, -10.0, 10.0); + output.LightVec = lightPos.xyz; + output.ViewVec = -localPos.xyz; + output.BaseColorFactor = push_constants.base_color_factor; + output.MetallicFactor = push_constants.metallic_factor; + output.RoughnessFactor = push_constants.roughness_factor; + output.BaseTextureIndex = push_constants.baseTextureIndex; + output.NormalTextureIndex = push_constants.normalTextureIndex; + output.MetallicRoughnessTextureIndex = push_constants.metallicRoughnessTextureIndex; + return output; +} diff --git a/shaders/dynamic_multisample_rasterization/slang/model.vert.spv b/shaders/dynamic_multisample_rasterization/slang/model.vert.spv new file mode 100644 index 0000000000..992280b639 Binary files /dev/null and b/shaders/dynamic_multisample_rasterization/slang/model.vert.spv differ diff --git a/shaders/dynamic_primitive_clipping/slang/primitive_clipping.frag.slang b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.frag.slang new file mode 100644 index 0000000000..5e6717d8c6 --- /dev/null +++ b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.frag.slang @@ -0,0 +1,42 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float ClipDistance : SV_ClipDistance0; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; + float4x4 model; + float4 colorTransformation; + int2 sceneTransformation; + float usePrimitiveClipping; +}; +ConstantBuffer ubo; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float4 outColor = float4(0.5 * input.Normal + 0.5.xxx, 1.0); + outColor.xyz = ubo.colorTransformation.x * outColor.xyz + ubo.colorTransformation.yyy; + return outColor; +} diff --git a/shaders/dynamic_primitive_clipping/slang/primitive_clipping.frag.spv b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.frag.spv new file mode 100644 index 0000000000..3285db4d83 Binary files /dev/null and b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.frag.spv differ diff --git a/shaders/dynamic_primitive_clipping/slang/primitive_clipping.vert.slang b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.vert.slang new file mode 100644 index 0000000000..69f34b27a5 --- /dev/null +++ b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.vert.slang @@ -0,0 +1,116 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; +}; + +// In a fixed pipeline approach which you can still find in OpenGL implementations you could define +// up to maximum 6 clipping half-spaces and a distance to each clipping half-space was stored in gl_ClipDistance. +// That's why gl_ClipDistance[] is an array which maximum size is limited by maxClipDistances. +// +// In our example we show you how to define such half-spaces using plane equation: Ax+By+Cz+D=0 +// You could transmit information about values of A,B,C and D using UBO for example, but for simplicity we will use const declaration: + +static float4 planeValues = float4(0.0, 1.0, 0.0, 0.0); + +struct UBO +{ + float4x4 projection; + float4x4 view; + float4x4 model; + float4 colorTransformation; + int2 sceneTransformation; + float usePrimitiveClipping; +}; +ConstantBuffer ubo; + +// Additionally we will show you that you can use more than half-spaces only. +// We will use some more advanced math functions to calculate gl_ClipDistance. + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float ClipDistance : SV_ClipDistance0; + float3 Normal; +}; + +// Cases 0 and 1 present how to use world space coordinates with more advanced functions +// Case 2 shows how to use half-space in world space coordinates +// Case 3 shows how to use half-space in clip space coordinates +// Cases 4-6 present how to use clip space coordinates with more advanced functions +// Cases 0,1,4,5 use sin() function to create strips in which values of gl_ClipDistance below 0 cause triangle primitives +// to be clipped according to Vulkan specification chapter 27.4 +// Cases 6-8 use different types of distance functions from center of the screen ( Euclidean, Manhattan, Chebyshev ) +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + + float4 worldPosition = mul(ubo.model, float4(input.Pos, 1.0)); + + output.Pos = mul(ubo.projection, mul(ubo.view, worldPosition)); + + float clipResult = 1.0, tmp; + float distance = 0.4; + + // Primitive clipping does not have any vkCmd* command that turns it off. + // If we want to turn it off - we have to transfer this information to shader through UBO variable and + // then use code similar to this: + if(ubo.usePrimitiveClipping > 0.0) + { + switch(ubo.sceneTransformation.x) + { + case 0: + clipResult = sin(worldPosition.x * 0.1 * 2.0 * 3.1415); + break; + case 1: + clipResult = sin(worldPosition.y * 0.1 * 2.0 * 3.1415); + break; + case 2: + clipResult = dot(worldPosition, planeValues ); + break; + case 3: + clipResult = dot(output.Pos, planeValues); + break; + case 4: + clipResult = sin(output.Pos.x / output.Pos.w * 3.0 * 2.0 * 3.1415); + break; + case 5: + clipResult = sin(output.Pos.y / output.Pos.w * 3.0 * 2.0 * 3.1415); + break; + case 6: + clipResult = (output.Pos.x*output.Pos.x + output.Pos.y*output.Pos.y) / (output.Pos.w*output.Pos.w) - distance*distance; + break; + case 7: + clipResult = (abs(output.Pos.x) + abs(output.Pos.y)) / output.Pos.w - distance; + break; + case 8: + clipResult = max(abs(output.Pos.x), abs(output.Pos.y)) / output.Pos.w - distance; + break; + } + + output.ClipDistance = clipResult * float(ubo.sceneTransformation.y); + } + + output.Normal = normalize(mul((float4x3)mul(ubo.view, ubo.model), input.Normal).xyz); + + return output; +} diff --git a/shaders/dynamic_primitive_clipping/slang/primitive_clipping.vert.spv b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.vert.spv new file mode 100644 index 0000000000..07caa265de Binary files /dev/null and b/shaders/dynamic_primitive_clipping/slang/primitive_clipping.vert.spv differ diff --git a/shaders/dynamic_rendering/slang/gbuffer.frag.spv b/shaders/dynamic_rendering/slang/gbuffer.frag.spv index 0472b0e322..a0487c9e3e 100644 Binary files a/shaders/dynamic_rendering/slang/gbuffer.frag.spv and b/shaders/dynamic_rendering/slang/gbuffer.frag.spv differ diff --git a/shaders/dynamic_rendering/slang/gbuffer.vert.spv b/shaders/dynamic_rendering/slang/gbuffer.vert.spv index 8fe6353873..2f43f56ba4 100644 Binary files a/shaders/dynamic_rendering/slang/gbuffer.vert.spv and b/shaders/dynamic_rendering/slang/gbuffer.vert.spv differ diff --git a/shaders/dynamic_rendering_local_read/slang/composition.frag.spv b/shaders/dynamic_rendering_local_read/slang/composition.frag.spv index 74c73a3c98..c81d79c01a 100644 Binary files a/shaders/dynamic_rendering_local_read/slang/composition.frag.spv and b/shaders/dynamic_rendering_local_read/slang/composition.frag.spv differ diff --git a/shaders/dynamic_rendering_local_read/slang/scene_opaque.vert.spv b/shaders/dynamic_rendering_local_read/slang/scene_opaque.vert.spv index 9c5b006f89..a3b727c2c8 100644 Binary files a/shaders/dynamic_rendering_local_read/slang/scene_opaque.vert.spv and b/shaders/dynamic_rendering_local_read/slang/scene_opaque.vert.spv differ diff --git a/shaders/dynamic_rendering_local_read/slang/scene_transparent.frag.slang b/shaders/dynamic_rendering_local_read/slang/scene_transparent.frag.slang index 77fbe951a3..0be49ce3b9 100644 --- a/shaders/dynamic_rendering_local_read/slang/scene_transparent.frag.slang +++ b/shaders/dynamic_rendering_local_read/slang/scene_transparent.frag.slang @@ -43,7 +43,6 @@ float4 main(VSOutput input) // Save the sampled texture color before discarding. // This is to avoid implicit derivatives in non-uniform control flow. - // @todo: reversed depth float4 sampledColor = samplerTexture.Sample(input.UV); if ((depth != 0.0) && (linearDepth(input.Pos.z) < depth)) { diff --git a/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.slang b/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.slang index 0402a1f1b3..0343f3f536 100644 --- a/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.slang +++ b/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.slang @@ -42,8 +42,6 @@ VSOutput main(VSInput input, uniform float4x4 pushMatrix, uniform float4 pushCol { VSOutput output; output.Color = pushColor; - // @todo - // outColor = vec4(1.0); output.Pos = mul(ubo.projection, mul(ubo.view, mul(pushMatrix, float4(input.Pos, 1.0)))); output.UV = input.UV; return output; diff --git a/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.spv b/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.spv index 4f7dc1a02c..35aba50021 100644 Binary files a/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.spv and b/shaders/dynamic_rendering_local_read/slang/scene_transparent.vert.spv differ diff --git a/shaders/dynamic_uniform_buffers/slang/base.frag.slang b/shaders/dynamic_uniform_buffers/slang/base.frag.slang new file mode 100644 index 0000000000..939b207dd9 --- /dev/null +++ b/shaders/dynamic_uniform_buffers/slang/base.frag.slang @@ -0,0 +1,28 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return float4(input.Color, 1.0); +} \ No newline at end of file diff --git a/shaders/dynamic_uniform_buffers/slang/base.frag.spv b/shaders/dynamic_uniform_buffers/slang/base.frag.spv new file mode 100644 index 0000000000..57e6ef985c Binary files /dev/null and b/shaders/dynamic_uniform_buffers/slang/base.frag.spv differ diff --git a/shaders/dynamic_uniform_buffers/slang/base.vert.slang b/shaders/dynamic_uniform_buffers/slang/base.vert.slang new file mode 100644 index 0000000000..e300db2af0 --- /dev/null +++ b/shaders/dynamic_uniform_buffers/slang/base.vert.slang @@ -0,0 +1,52 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Color; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +struct UboView +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer uboView; + +struct UboInstance +{ + float4x4 model; +}; +ConstantBuffer uboInstance; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Color = input.Color; + float4x4 modelView = mul(uboView.view, uboInstance.model); + float3 worldPos = mul(modelView, float4(input.Pos, 1.0)).xyz; + output.Pos = mul(uboView.projection, mul(modelView, float4(input.Pos.xyz, 1.0))); + return output; +} \ No newline at end of file diff --git a/shaders/dynamic_uniform_buffers/slang/base.vert.spv b/shaders/dynamic_uniform_buffers/slang/base.vert.spv new file mode 100644 index 0000000000..cdb30e9312 Binary files /dev/null and b/shaders/dynamic_uniform_buffers/slang/base.vert.spv differ diff --git a/shaders/extended_dynamic_state2/background.frag b/shaders/extended_dynamic_state2/glsl/background.frag similarity index 95% rename from shaders/extended_dynamic_state2/background.frag rename to shaders/extended_dynamic_state2/glsl/background.frag index b93012ca40..6b0acfed8c 100644 --- a/shaders/extended_dynamic_state2/background.frag +++ b/shaders/extended_dynamic_state2/glsl/background.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/background.frag.spv b/shaders/extended_dynamic_state2/glsl/background.frag.spv similarity index 100% rename from shaders/extended_dynamic_state2/background.frag.spv rename to shaders/extended_dynamic_state2/glsl/background.frag.spv diff --git a/shaders/extended_dynamic_state2/background.vert b/shaders/extended_dynamic_state2/glsl/background.vert similarity index 95% rename from shaders/extended_dynamic_state2/background.vert rename to shaders/extended_dynamic_state2/glsl/background.vert index 73b6d10cba..f82528197d 100644 --- a/shaders/extended_dynamic_state2/background.vert +++ b/shaders/extended_dynamic_state2/glsl/background.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/background.vert.spv b/shaders/extended_dynamic_state2/glsl/background.vert.spv similarity index 100% rename from shaders/extended_dynamic_state2/background.vert.spv rename to shaders/extended_dynamic_state2/glsl/background.vert.spv diff --git a/shaders/extended_dynamic_state2/baseline.frag b/shaders/extended_dynamic_state2/glsl/baseline.frag similarity index 97% rename from shaders/extended_dynamic_state2/baseline.frag rename to shaders/extended_dynamic_state2/glsl/baseline.frag index 20733fc8e6..634e6d7f35 100644 --- a/shaders/extended_dynamic_state2/baseline.frag +++ b/shaders/extended_dynamic_state2/glsl/baseline.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/baseline.frag.spv b/shaders/extended_dynamic_state2/glsl/baseline.frag.spv similarity index 100% rename from shaders/extended_dynamic_state2/baseline.frag.spv rename to shaders/extended_dynamic_state2/glsl/baseline.frag.spv diff --git a/shaders/extended_dynamic_state2/baseline.vert b/shaders/extended_dynamic_state2/glsl/baseline.vert similarity index 97% rename from shaders/extended_dynamic_state2/baseline.vert rename to shaders/extended_dynamic_state2/glsl/baseline.vert index 42687a5def..18b925218d 100644 --- a/shaders/extended_dynamic_state2/baseline.vert +++ b/shaders/extended_dynamic_state2/glsl/baseline.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/baseline.vert.spv b/shaders/extended_dynamic_state2/glsl/baseline.vert.spv similarity index 100% rename from shaders/extended_dynamic_state2/baseline.vert.spv rename to shaders/extended_dynamic_state2/glsl/baseline.vert.spv diff --git a/shaders/extended_dynamic_state2/tess.frag b/shaders/extended_dynamic_state2/glsl/tess.frag similarity index 94% rename from shaders/extended_dynamic_state2/tess.frag rename to shaders/extended_dynamic_state2/glsl/tess.frag index c0131da033..38227abbc9 100644 --- a/shaders/extended_dynamic_state2/tess.frag +++ b/shaders/extended_dynamic_state2/glsl/tess.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/tess.frag.spv b/shaders/extended_dynamic_state2/glsl/tess.frag.spv similarity index 100% rename from shaders/extended_dynamic_state2/tess.frag.spv rename to shaders/extended_dynamic_state2/glsl/tess.frag.spv diff --git a/shaders/extended_dynamic_state2/tess.tesc b/shaders/extended_dynamic_state2/glsl/tess.tesc similarity index 97% rename from shaders/extended_dynamic_state2/tess.tesc rename to shaders/extended_dynamic_state2/glsl/tess.tesc index e35671a0de..bdebb6cae6 100644 --- a/shaders/extended_dynamic_state2/tess.tesc +++ b/shaders/extended_dynamic_state2/glsl/tess.tesc @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/tess.tesc.spv b/shaders/extended_dynamic_state2/glsl/tess.tesc.spv similarity index 100% rename from shaders/extended_dynamic_state2/tess.tesc.spv rename to shaders/extended_dynamic_state2/glsl/tess.tesc.spv diff --git a/shaders/extended_dynamic_state2/tess.tese b/shaders/extended_dynamic_state2/glsl/tess.tese similarity index 97% rename from shaders/extended_dynamic_state2/tess.tese rename to shaders/extended_dynamic_state2/glsl/tess.tese index 1b67100f83..7ce98aab8d 100644 --- a/shaders/extended_dynamic_state2/tess.tese +++ b/shaders/extended_dynamic_state2/glsl/tess.tese @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/tess.tese.spv b/shaders/extended_dynamic_state2/glsl/tess.tese.spv similarity index 100% rename from shaders/extended_dynamic_state2/tess.tese.spv rename to shaders/extended_dynamic_state2/glsl/tess.tese.spv diff --git a/shaders/extended_dynamic_state2/tess.vert b/shaders/extended_dynamic_state2/glsl/tess.vert similarity index 95% rename from shaders/extended_dynamic_state2/tess.vert rename to shaders/extended_dynamic_state2/glsl/tess.vert index 2884fa2ba8..f7a447c89c 100644 --- a/shaders/extended_dynamic_state2/tess.vert +++ b/shaders/extended_dynamic_state2/glsl/tess.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/extended_dynamic_state2/tess.vert.spv b/shaders/extended_dynamic_state2/glsl/tess.vert.spv similarity index 100% rename from shaders/extended_dynamic_state2/tess.vert.spv rename to shaders/extended_dynamic_state2/glsl/tess.vert.spv diff --git a/shaders/extended_dynamic_state2/slang/background.frag.slang b/shaders/extended_dynamic_state2/slang/background.frag.slang new file mode 100644 index 0000000000..83068291d2 --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/background.frag.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] SamplerCube samplerEnvMap; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return float4(samplerEnvMap.Sample(normalize(input.UVW)).rgb, 1.0); +} diff --git a/shaders/extended_dynamic_state2/slang/background.frag.spv b/shaders/extended_dynamic_state2/slang/background.frag.spv new file mode 100644 index 0000000000..99dfa9a720 Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/background.frag.spv differ diff --git a/shaders/extended_dynamic_state2/slang/background.vert.slang b/shaders/extended_dynamic_state2/slang/background.vert.slang new file mode 100644 index 0000000000..c035090d9c --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/background.vert.slang @@ -0,0 +1,45 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UVW = input.Pos; + output.Pos = mul(ubo.projection, mul(ubo.view, float4(input.Pos * 10.0, 1.0))); + return output; +} diff --git a/shaders/extended_dynamic_state2/slang/background.vert.spv b/shaders/extended_dynamic_state2/slang/background.vert.spv new file mode 100644 index 0000000000..37a4e3df46 Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/background.vert.spv differ diff --git a/shaders/extended_dynamic_state2/slang/baseline.frag.slang b/shaders/extended_dynamic_state2/slang/baseline.frag.slang new file mode 100644 index 0000000000..67b27128d2 --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/baseline.frag.slang @@ -0,0 +1,46 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float4 FragColor; + float3 LightVec; + float3 LightColor[2]; + float3 ViewVec; + float LightIntensity; +}; + +[[SpecializationConstant]] const int type = 0; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float attenuation = 1.0 / dot(input.LightVec, input.LightVec); + + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + + float3 diffuse = input.LightColor[0] * attenuation * max(dot(N, L), 0) * input.LightIntensity; + float3 ambient = input.LightColor[1]; + float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.65); + return float4((ambient + diffuse) * input.FragColor.rgb + (specular * input.LightIntensity / 50.0), input.FragColor.a); +} diff --git a/shaders/extended_dynamic_state2/slang/baseline.frag.spv b/shaders/extended_dynamic_state2/slang/baseline.frag.spv new file mode 100644 index 0000000000..8fd12532cc Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/baseline.frag.spv differ diff --git a/shaders/extended_dynamic_state2/slang/baseline.vert.slang b/shaders/extended_dynamic_state2/slang/baseline.vert.slang new file mode 100644 index 0000000000..88edc13bdc --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/baseline.vert.slang @@ -0,0 +1,69 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float4 FragColor; + float3 LightVec; + float3 LightColor[2]; + float3 ViewVec; + float LightIntensity; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct UBOBaseline +{ + float4 ambientLightColor; + float4 lightPosition; + float4 lightColor; + float lightIntensity; +}; +ConstantBuffer ubo_baseline; + +[[SpecializationConstant]] const int type = 0; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4x4 model, uniform float4 color) +{ + VSOutput output; + output.FragColor = color; + float4 localPos = mul(ubo.view, mul(model, float4(input.Pos, 1.0))); + output.Pos = mul(ubo.projection, localPos); + output.Normal = mul((float3x3)mul(ubo.view, model), input.Normal); + float4 positionWorld = mul(model, float4(input.Pos, 1.0)); + output.LightVec = ubo_baseline.lightPosition.xyz - positionWorld.xyz; + output.LightColor[0] = ubo_baseline.lightColor.xyz * ubo_baseline.lightColor.w; + output.LightColor[1] = ubo_baseline.ambientLightColor.xyz * ubo_baseline.ambientLightColor.w; + output.ViewVec = -localPos.xyz; + output.LightIntensity = ubo_baseline.lightIntensity; + return output; +} diff --git a/shaders/extended_dynamic_state2/slang/baseline.vert.spv b/shaders/extended_dynamic_state2/slang/baseline.vert.spv new file mode 100644 index 0000000000..2c1b4ab357 Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/baseline.vert.spv differ diff --git a/shaders/extended_dynamic_state2/slang/tess.frag.slang b/shaders/extended_dynamic_state2/slang/tess.frag.slang new file mode 100644 index 0000000000..d05b6f5392 --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/tess.frag.slang @@ -0,0 +1,23 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[shader("fragment")] +float4 main() +{ + return float4(0.6667, 0.1176, 0.1176, 1.0); +} diff --git a/shaders/extended_dynamic_state2/slang/tess.frag.spv b/shaders/extended_dynamic_state2/slang/tess.frag.spv new file mode 100644 index 0000000000..40ff486d8a Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/tess.frag.spv differ diff --git a/shaders/extended_dynamic_state2/slang/tess.tesc.slang b/shaders/extended_dynamic_state2/slang/tess.tesc.slang new file mode 100644 index 0000000000..f1ace2e7ac --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/tess.tesc.slang @@ -0,0 +1,75 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 LocPos; + float3 Normal; +}; + +struct HSOutput +{ + float3 Pos : SV_POSITION; + float3 Normal; +}; + +struct ConstantsHSOutput +{ + float TessLevelOuter[3] : SV_TessFactor; + float TessLevelInner[2] : SV_InsideTessFactor; +}; + +struct UBO +{ + float tessellationFactor; +}; +[[vk::binding(1, 0)]] ConstantBuffer ubo; + +ConstantsHSOutput ConstantsHS(InputPatch patch) +{ + ConstantsHSOutput output; + if (ubo.tessellationFactor > 0.0) { + output.TessLevelInner[0] = ubo.tessellationFactor; + output.TessLevelInner[1] = ubo.tessellationFactor; + output.TessLevelOuter[0] = ubo.tessellationFactor; + output.TessLevelOuter[1] = ubo.tessellationFactor; + output.TessLevelOuter[2] = ubo.tessellationFactor; + } else { + output.TessLevelInner[0] = 1; + output.TessLevelInner[1] = 1; + output.TessLevelOuter[0] = 1; + output.TessLevelOuter[1] = 1; + output.TessLevelOuter[2] = 1; + } + return output; +} + +[shader("hull")] +[domain("tri")] +[partitioning("integer")] +[outputtopology("triangle_cw")] +[outputcontrolpoints(3)] +[patchconstantfunc("ConstantsHS")] +HSOutput main(InputPatch patch, uint InvocationID: SV_OutputControlPointID) +{ + HSOutput output; + output.Pos = patch[InvocationID].Pos.xyz; + output.Normal = patch[InvocationID].Normal; + return output; +} diff --git a/shaders/extended_dynamic_state2/slang/tess.tesc.spv b/shaders/extended_dynamic_state2/slang/tess.tesc.spv new file mode 100644 index 0000000000..ad8bd95a03 Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/tess.tesc.spv differ diff --git a/shaders/extended_dynamic_state2/slang/tess.tese.slang b/shaders/extended_dynamic_state2/slang/tess.tese.slang new file mode 100644 index 0000000000..0dd9b1ff47 --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/tess.tese.slang @@ -0,0 +1,63 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 LocPos; + float3 Normal; +}; + +struct HSOutput +{ + float3 Pos : SV_POSITION; + float3 Normal; +}; + +struct DSOutput +{ + float4 Pos : SV_POSITION; +}; + +struct ConstantsHSOutput +{ + float TessLevelOuter[3] : SV_TessFactor; + float TessLevelInner[2] : SV_InsideTessFactor; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +float3 interpolate3D(float3 v0, float3 v1, float3 v2, float3 tessCoord) +{ + return float3(tessCoord.x) * v0 + float3(tessCoord.y) * v1 + float3(tessCoord.z) * v2; +} + +[domain("tri")] +[shader("domain")] +DSOutput main(ConstantsHSOutput input, float3 tessCoord: SV_DomainLocation, const OutputPatch patch, uniform float4x4 model, uniform float3 color) +{ + DSOutput output; + float4 pos = float4(interpolate3D(patch[0].Pos, patch[1].Pos, patch[2].Pos, tessCoord), 1.0); + output.Pos = mul(ubo.projection, mul(ubo.view, mul(model, pos))); + return output; +} diff --git a/shaders/extended_dynamic_state2/slang/tess.tese.spv b/shaders/extended_dynamic_state2/slang/tess.tese.spv new file mode 100644 index 0000000000..2b4c16ac13 Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/tess.tese.spv differ diff --git a/shaders/extended_dynamic_state2/slang/tess.vert.slang b/shaders/extended_dynamic_state2/slang/tess.vert.slang new file mode 100644 index 0000000000..3aeb984895 --- /dev/null +++ b/shaders/extended_dynamic_state2/slang/tess.vert.slang @@ -0,0 +1,47 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 LocPos; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Pos = float4(input.Pos, 1.0); + output.Normal = mul(float3x3(ubo.view), input.Normal); + output.LocPos = input.Pos; + return output; +} diff --git a/shaders/extended_dynamic_state2/slang/tess.vert.spv b/shaders/extended_dynamic_state2/slang/tess.vert.spv new file mode 100644 index 0000000000..9ab23591be Binary files /dev/null and b/shaders/extended_dynamic_state2/slang/tess.vert.spv differ diff --git a/shaders/fragment_shader_barycentric/object.frag b/shaders/fragment_shader_barycentric/glsl/object.frag similarity index 98% rename from shaders/fragment_shader_barycentric/object.frag rename to shaders/fragment_shader_barycentric/glsl/object.frag index 7d46a336c1..a5fffdc544 100644 --- a/shaders/fragment_shader_barycentric/object.frag +++ b/shaders/fragment_shader_barycentric/glsl/object.frag @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/fragment_shader_barycentric/object.frag.spv b/shaders/fragment_shader_barycentric/glsl/object.frag.spv similarity index 100% rename from shaders/fragment_shader_barycentric/object.frag.spv rename to shaders/fragment_shader_barycentric/glsl/object.frag.spv diff --git a/shaders/fragment_shader_barycentric/object.vert b/shaders/fragment_shader_barycentric/glsl/object.vert similarity index 96% rename from shaders/fragment_shader_barycentric/object.vert rename to shaders/fragment_shader_barycentric/glsl/object.vert index 0fcc57210d..09d190d16f 100644 --- a/shaders/fragment_shader_barycentric/object.vert +++ b/shaders/fragment_shader_barycentric/glsl/object.vert @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/fragment_shader_barycentric/object.vert.spv b/shaders/fragment_shader_barycentric/glsl/object.vert.spv similarity index 100% rename from shaders/fragment_shader_barycentric/object.vert.spv rename to shaders/fragment_shader_barycentric/glsl/object.vert.spv diff --git a/shaders/fragment_shader_barycentric/skybox.frag b/shaders/fragment_shader_barycentric/glsl/skybox.frag similarity index 94% rename from shaders/fragment_shader_barycentric/skybox.frag rename to shaders/fragment_shader_barycentric/glsl/skybox.frag index dec0532d72..a2bcd172dc 100644 --- a/shaders/fragment_shader_barycentric/skybox.frag +++ b/shaders/fragment_shader_barycentric/glsl/skybox.frag @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/fragment_shader_barycentric/skybox.frag.spv b/shaders/fragment_shader_barycentric/glsl/skybox.frag.spv similarity index 100% rename from shaders/fragment_shader_barycentric/skybox.frag.spv rename to shaders/fragment_shader_barycentric/glsl/skybox.frag.spv diff --git a/shaders/fragment_shader_barycentric/skybox.vert b/shaders/fragment_shader_barycentric/glsl/skybox.vert similarity index 95% rename from shaders/fragment_shader_barycentric/skybox.vert rename to shaders/fragment_shader_barycentric/glsl/skybox.vert index 97e54f9a32..14282682d1 100644 --- a/shaders/fragment_shader_barycentric/skybox.vert +++ b/shaders/fragment_shader_barycentric/glsl/skybox.vert @@ -1,5 +1,5 @@ #version 450 -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/fragment_shader_barycentric/skybox.vert.spv b/shaders/fragment_shader_barycentric/glsl/skybox.vert.spv similarity index 100% rename from shaders/fragment_shader_barycentric/skybox.vert.spv rename to shaders/fragment_shader_barycentric/glsl/skybox.vert.spv diff --git a/shaders/fragment_shader_barycentric/slang/object.frag.slang b/shaders/fragment_shader_barycentric/slang/object.frag.slang new file mode 100644 index 0000000000..ceab9fff28 --- /dev/null +++ b/shaders/fragment_shader_barycentric/slang/object.frag.slang @@ -0,0 +1,74 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +[[vk::binding(1, 0)]] Sampler2D samplerColorMap; + +[shader("fragment")] +float4 main(VSOutput input, float3 baryCoords: SV_Barycentrics, noperspective float3 baryCoordsAffine: SV_Barycentrics, uint vertexIndex: SV_VertexID, uniform int type) +{ + float3 vColor0 = GetAttributeAtVertex(input.Color, 0); + float3 vColor1 = GetAttributeAtVertex(input.Color, 1); + float3 vColor2 = GetAttributeAtVertex(input.Color, 2); + + float4 outColor = 0.0; + switch (type) { + case 0: + { + outColor.rgb = vColor0 * baryCoords.x + + vColor1 * baryCoords.y + + vColor2 * baryCoords.z; + outColor.a = 1.0; + break; + } + case 1: + { + outColor.rgb = baryCoords - baryCoordsAffine; + const float exposure = 10.f; + outColor = float4(float3(1.0) - exp(-outColor.rgb * exposure), 1.0); + break; + } + case 2: + { + if (baryCoords.x < 0.01 || baryCoords.y < 0.01 || baryCoords.z < 0.01) + outColor = float4(0.0, 0.0, 0.0, 1.0); + else + outColor = float4(0.5, 0.5, 0.5, 1.0); + break; + } + case 3: + { + if (baryCoords.x <= baryCoords.y && baryCoords.x <= baryCoords.z) + outColor = float4(vColor0.rgb * baryCoords.x, 1.0); + else if (baryCoords.y < baryCoords.x && baryCoords.y <= baryCoords.z) + outColor = float4(vColor1.rgb * baryCoords.y, 1.0); + else + outColor = float4(vColor2.rgb * baryCoords.z, 1.0); + break; + } + case 4: + { + outColor = samplerColorMap.Sample(float2(sin(baryCoords.x) + cos(2 * baryCoords.z), sin(baryCoords.x) + cos(2 * baryCoords.y))); + } + } + return outColor; +} diff --git a/shaders/fragment_shader_barycentric/slang/object.frag.spv b/shaders/fragment_shader_barycentric/slang/object.frag.spv new file mode 100644 index 0000000000..b6dce4b67c Binary files /dev/null and b/shaders/fragment_shader_barycentric/slang/object.frag.spv differ diff --git a/shaders/fragment_shader_barycentric/slang/object.vert.slang b/shaders/fragment_shader_barycentric/slang/object.vert.slang new file mode 100644 index 0000000000..f62036dae3 --- /dev/null +++ b/shaders/fragment_shader_barycentric/slang/object.vert.slang @@ -0,0 +1,51 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +struct UBO { + float4x4 projection; + float4x4 modelview; +}; +ConstantBuffer ubo; + +static float3 triangleColors[6] = { + float3(1.0, 0.0, 0.0), + float3(0.0, 1.0, 0.0), + float3(0.0, 0.0, 1.0), + float3(0.0, 0.0, 1.0), + float3(0.0, 1.0, 0.0), + float3(1.0, 0.0, 0.0) +}; + +[shader("vertex")] +VSOutput main(VSInput input, uint VertexIndex: SV_VertexID) +{ + VSOutput output; + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz, 1.0))); + output.Color = triangleColors[VertexIndex % 6]; + return output; +} diff --git a/shaders/fragment_shader_barycentric/slang/object.vert.spv b/shaders/fragment_shader_barycentric/slang/object.vert.spv new file mode 100644 index 0000000000..c0304c811d Binary files /dev/null and b/shaders/fragment_shader_barycentric/slang/object.vert.spv differ diff --git a/shaders/fragment_shader_barycentric/slang/skybox.frag.slang b/shaders/fragment_shader_barycentric/slang/skybox.frag.slang new file mode 100644 index 0000000000..ce762ea41f --- /dev/null +++ b/shaders/fragment_shader_barycentric/slang/skybox.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +[[vk::binding(1, 0)]] SamplerCube samplerEnvMap; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerEnvMap.Sample(input.UVW); +} diff --git a/shaders/fragment_shader_barycentric/slang/skybox.frag.spv b/shaders/fragment_shader_barycentric/slang/skybox.frag.spv new file mode 100644 index 0000000000..7d67132ace Binary files /dev/null and b/shaders/fragment_shader_barycentric/slang/skybox.frag.spv differ diff --git a/shaders/fragment_shader_barycentric/slang/skybox.vert.slang b/shaders/fragment_shader_barycentric/slang/skybox.vert.slang new file mode 100644 index 0000000000..7bc9115621 --- /dev/null +++ b/shaders/fragment_shader_barycentric/slang/skybox.vert.slang @@ -0,0 +1,42 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +struct UBO { + float4x4 projection; + float4x4 modelview; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Pos = mul(ubo.projection, float4(mul((float3x3)ubo.modelview, input.Pos), 1.0)); + output.UVW = input.Pos; + return output; +} \ No newline at end of file diff --git a/shaders/fragment_shader_barycentric/slang/skybox.vert.spv b/shaders/fragment_shader_barycentric/slang/skybox.vert.spv new file mode 100644 index 0000000000..8952701f42 Binary files /dev/null and b/shaders/fragment_shader_barycentric/slang/skybox.vert.spv differ diff --git a/shaders/fragment_shading_rate/slang/scene.frag.slang b/shaders/fragment_shading_rate/slang/scene.frag.slang new file mode 100644 index 0000000000..25c8020505 --- /dev/null +++ b/shaders/fragment_shading_rate/slang/scene.frag.slang @@ -0,0 +1,107 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4x4 skybox_modelview; + int color_shading_rates; +}; +ConstantBuffer ubo; + +[[vk::binding(1, 0)]] Sampler2D samplerEnvMap; +[[vk::binding(2, 0)]] Sampler2D samplerSphere; + +static const uint SHADING_RATE_PER_PIXEL = 0; +static const uint SHADING_RATE_PER_2X1_PIXELS = 6; +static const uint SHADING_RATE_PER_1X2_PIXELS = 7; +static const uint SHADING_RATE_PER_2X2_PIXELS = 8; +static const uint SHADING_RATE_PER_4X2_PIXELS = 9; +static const uint SHADING_RATE_PER_2X4_PIXELS = 10; + +[shader("fragment")] +float4 main(VSOutput input, uint shadingRate: SV_ShadingRate, uniform float4 offset, uniform int object_type) +{ + float4 color; + + switch (object_type) { + case 0: // Skysphere + { + color = samplerEnvMap.Sample(float2(input.UV.x, 1.0 - input.UV.y)); + } + break; + + case 1: // Phong shading + { + float3 ambient = samplerSphere.Sample(input.UV).rgb; + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = float3(max(dot(N, L), (0.0).xxx)); + float3 specular = float3(pow(max(dot(R, V), (0.0).xxx), 8.0)); + color = float4(ambient + diffuse + specular, 1.0); + } + break; + } + + if (ubo.color_shading_rates == 1) { + // Visualize fragment shading rates + + const uint SHADING_RATE_1X1 = 0; + const uint SHADING_RATE_1X2 = 0x1; + const uint SHADING_RATE_2X1 = 0x4; + const uint SHADING_RATE_2X2 = 0x5; + const uint SHADING_RATE_2X4 = 0x6; + const uint SHADING_RATE_4X2 = 0x9; + const uint SHADING_RATE_4X4 = 0xa; + + int v = 1; + int h = 1; + + if ((shadingRate == SHADING_RATE_1X2) || (shadingRate == SHADING_RATE_2X2) || (shadingRate == SHADING_RATE_4X2)) { + v = 2; + } + if ((shadingRate == SHADING_RATE_2X4) || (shadingRate == SHADING_RATE_4X4)) { + v = 4; + } + if ((shadingRate == SHADING_RATE_2X1) || (shadingRate == SHADING_RATE_2X2) || (shadingRate == SHADING_RATE_2X4)) { + h = 2; + } + if ((shadingRate == SHADING_RATE_4X2) || (shadingRate == SHADING_RATE_4X4)) { + h = 4; + } + + if (v == 1 && h == 1) { + return float4(color.rrr * 1.0, 1.0); + } else { + return float4(color.rrr * 1.0 - ((v + h) * 0.05), 1.0); + } + } else { + return float4(color.rgb, 1.0); + } +} \ No newline at end of file diff --git a/shaders/fragment_shading_rate/slang/scene.frag.spv b/shaders/fragment_shading_rate/slang/scene.frag.spv new file mode 100644 index 0000000000..54d7cd15bc Binary files /dev/null and b/shaders/fragment_shading_rate/slang/scene.frag.spv differ diff --git a/shaders/fragment_shading_rate/slang/scene.vert.slang b/shaders/fragment_shading_rate/slang/scene.vert.slang new file mode 100644 index 0000000000..5fe17a1d87 --- /dev/null +++ b/shaders/fragment_shading_rate/slang/scene.vert.slang @@ -0,0 +1,66 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4x4 skybox_modelview; + int color_shading_rates; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4 offset, uniform int object_type) +{ + VSOutput output; + float3 outPos; + + switch (object_type) { + case 0: // Skysphere + outPos = mul((float3x3)ubo.skybox_modelview, input.Pos); + output.Pos = float4(mul(ubo.projection, float4(outPos, 1.0))); + break; + case 1: // Object + float3 localPos = input.Pos + offset.xyz; + outPos = mul((float3x3)ubo.modelview, localPos); + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(localPos, 1.0))); + break; + } + output.UV = input.UV; + output.Normal = mul((float3x3)ubo.modelview, input.Normal); + float3 lightPos = mul((float3x3)ubo.modelview, float3(0.0, -10.0, -10.0)); + output.LightVec = lightPos.xyz - outPos.xyz; + output.ViewVec = -outPos.xyz; + return output; +} \ No newline at end of file diff --git a/shaders/fragment_shading_rate/slang/scene.vert.spv b/shaders/fragment_shading_rate/slang/scene.vert.spv new file mode 100644 index 0000000000..a1c9b15ac6 Binary files /dev/null and b/shaders/fragment_shading_rate/slang/scene.vert.spv differ diff --git a/shaders/graphics_pipeline_library/slang/shared.vert.slang b/shaders/graphics_pipeline_library/slang/shared.vert.slang new file mode 100644 index 0000000000..fd667312f8 --- /dev/null +++ b/shaders/graphics_pipeline_library/slang/shared.vert.slang @@ -0,0 +1,54 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; + float3 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 ViewVec; + float3 LightVec; + nointerpolation float3 FlatNormal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; + float4 lightPos; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4 color) +{ + VSOutput output; + float3 vecPos = mul((float3x3)ubo.model, input.Pos.xyz).xyz; + output.Color = color.rgb; + output.Normal = mul((float3x3)ubo.model, input.Normal); + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0))); + output.LightVec = ubo.lightPos.xyz - vecPos; + output.ViewVec = -vecPos; + return output; +} \ No newline at end of file diff --git a/shaders/graphics_pipeline_library/slang/shared.vert.spv b/shaders/graphics_pipeline_library/slang/shared.vert.spv new file mode 100644 index 0000000000..153d1379f4 Binary files /dev/null and b/shaders/graphics_pipeline_library/slang/shared.vert.spv differ diff --git a/shaders/graphics_pipeline_library/slang/uber.frag.slang b/shaders/graphics_pipeline_library/slang/uber.frag.slang new file mode 100644 index 0000000000..8219d54805 --- /dev/null +++ b/shaders/graphics_pipeline_library/slang/uber.frag.slang @@ -0,0 +1,70 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 ViewVec; + float3 LightVec; +}; + + +// We use this constant to control the flow of the shader depending on the +// lighting model selected at pipeline creation time +[[SpecializationConstant]] const int LIGHTING_MODEL = 0; + +[shader("fragment")] +float4 main(VSOutput input) +{ + switch (LIGHTING_MODEL) { + case 0: // Phong + { + float3 ambient = input.Color * (0.25).xxx; + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = max(dot(N, L), (0.0).xxx) * input.Color; + float3 specular = pow(max(dot(R, V), (0.0).xxx), 32.0) * (0.75).xxx; + return float4(ambient + diffuse * 1.75 + specular, 1.0); + } + case 1: // Toon + { + + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float intensity = dot(N, L); + float3 color; + if (intensity > 0.98) + color = input.Color * 1.5; + else if (intensity > 0.9) + color = input.Color * 1.0; + else if (intensity > 0.5) + color = input.Color * 0.6; + else if (intensity > 0.25) + color = input.Color * 0.4; + else + color = input.Color * 0.2; + // Desaturate a bit + color = float3(lerp(color, float3(dot(float3(0.2126, 0.7152, 0.0722), color).xxx), 0.25)); + return float4(color, 1.0); + } + } + return float4(input.Color, 1.0); +} \ No newline at end of file diff --git a/shaders/graphics_pipeline_library/slang/uber.frag.spv b/shaders/graphics_pipeline_library/slang/uber.frag.spv new file mode 100644 index 0000000000..3eb4f79972 Binary files /dev/null and b/shaders/graphics_pipeline_library/slang/uber.frag.spv differ diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.frag b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.frag similarity index 96% rename from shaders/gshader_to_mshader/gshader_to_mshader.frag rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.frag index 5b7a0d480b..4460cb7441 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader.frag +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.frag.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.frag.spv similarity index 100% rename from shaders/gshader_to_mshader/gshader_to_mshader.frag.spv rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.frag.spv diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.geom b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.geom similarity index 97% rename from shaders/gshader_to_mshader/gshader_to_mshader.geom rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.geom index daa64a9a93..7de58bf055 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader.geom +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.geom @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.geom.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.geom.spv similarity index 100% rename from shaders/gshader_to_mshader/gshader_to_mshader.geom.spv rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.geom.spv diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.mesh b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.mesh similarity index 98% rename from shaders/gshader_to_mshader/gshader_to_mshader.mesh rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.mesh index 92d7fe365f..d99a4616ba 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader.mesh +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.mesh @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.mesh.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.mesh.spv similarity index 100% rename from shaders/gshader_to_mshader/gshader_to_mshader.mesh.spv rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.mesh.spv diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.vert b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.vert similarity index 92% rename from shaders/gshader_to_mshader/gshader_to_mshader.vert rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader.vert index 45585ae6fc..e6f0d54772 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader.vert +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * @@ -20,6 +20,7 @@ layout(set = 0, binding = 0) uniform UniformBufferObject { mat4 model; mat4 view; mat4 proj; + mat4 normal; } ubo; layout(location = 0) in vec3 inPosition; @@ -38,7 +39,7 @@ void main() vec4 FragPos = ubo.model * vec4(inPosition, 1.0f); vec3 lightPos = vec3(-20.0f, 5.0f, 5.0f); vec3 lPos = mat3(ubo.model) * lightPos.xyz; - outNormal = mat3(transpose(inverse( ubo.view *ubo.model))) * inNormal; + outNormal = mat3(ubo.normal) * inNormal; outLightVec = lPos.xyz - FragPos.xyz; outViewVec = - (ubo.view * ubo.model * vec4(inPosition, 1.0f)).xyz; diff --git a/shaders/gshader_to_mshader/glsl/gshader_to_mshader.vert.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.vert.spv new file mode 100644 index 0000000000..eb2852e78b Binary files /dev/null and b/shaders/gshader_to_mshader/glsl/gshader_to_mshader.vert.spv differ diff --git a/shaders/gshader_to_mshader/gshader_to_mshader_base.frag b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.frag similarity index 94% rename from shaders/gshader_to_mshader/gshader_to_mshader_base.frag rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.frag index 622cdfc0d8..c4a34be539 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader_base.frag +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/gshader_to_mshader/gshader_to_mshader_base.frag.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.frag.spv similarity index 100% rename from shaders/gshader_to_mshader/gshader_to_mshader_base.frag.spv rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.frag.spv diff --git a/shaders/gshader_to_mshader/gshader_to_mshader_base.vert b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.vert similarity index 95% rename from shaders/gshader_to_mshader/gshader_to_mshader_base.vert rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.vert index 36050c745b..283e64af1f 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader_base.vert +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/gshader_to_mshader/gshader_to_mshader_base.vert.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.vert.spv similarity index 100% rename from shaders/gshader_to_mshader/gshader_to_mshader_base.vert.spv rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader_base.vert.spv diff --git a/shaders/gshader_to_mshader/gshader_to_mshader_mesh.frag b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_mesh.frag similarity index 94% rename from shaders/gshader_to_mshader/gshader_to_mshader_mesh.frag rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader_mesh.frag index 5d1625ef19..1f40549f0e 100644 --- a/shaders/gshader_to_mshader/gshader_to_mshader_mesh.frag +++ b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_mesh.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2023, Mobica Limited +/* Copyright (c) 2023-2025, Mobica Limited * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/gshader_to_mshader/gshader_to_mshader_mesh.frag.spv b/shaders/gshader_to_mshader/glsl/gshader_to_mshader_mesh.frag.spv similarity index 100% rename from shaders/gshader_to_mshader/gshader_to_mshader_mesh.frag.spv rename to shaders/gshader_to_mshader/glsl/gshader_to_mshader_mesh.frag.spv diff --git a/shaders/gshader_to_mshader/gshader_to_mshader.vert.spv b/shaders/gshader_to_mshader/gshader_to_mshader.vert.spv deleted file mode 100644 index a05fd4d5f4..0000000000 Binary files a/shaders/gshader_to_mshader/gshader_to_mshader.vert.spv and /dev/null differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.frag.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader.frag.slang new file mode 100644 index 0000000000..b1248ca076 --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader.frag.slang @@ -0,0 +1,45 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + float3 Normal; + float3 Color; + float3 ViewVec; + float3 LightVec; +} +[shader("fragment")] +float4 main(VSOutput input) +{ + float ambientStrength = 0.2; + float3 ambient = ambientStrength * float3(1.0); + + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + + float3 diffuse = max(dot(N,L), 0.0) * float3(1.0); + + float3 specular = pow(max(dot(R, V), 0.0), 64.0) * float3(0.65); + + float3 result = (ambient + diffuse) * input.Color + specular; + + return float4(result, 1.0f); +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.frag.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader.frag.spv new file mode 100644 index 0000000000..bbd30b3a53 Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader.frag.spv differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.geom.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader.geom.slang new file mode 100644 index 0000000000..439a4b24c1 --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader.geom.slang @@ -0,0 +1,60 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + float3 Normal; +}; + +struct GSOutput +{ + float4 Pos : SV_Position; + float3 Color; +}; + +struct UBO { + float4x4 model; + float4x4 view; + float4x4 proj; +}; +[[vk::binding(1, 0)]] ConstantBuffer ubo; + +[shader("geometry")] +[maxvertexcount(2)] +void main(triangle VSOutput input[3], inout LineStream outStream) +{ + float normalLength = 0.1f; + + // middle point of triangle + float3 pos = (input[0].Pos.xyz + input[1].Pos.xyz + input[2].Pos.xyz) / 3.0; + float3 normal = input[0].Normal.xyz; + + GSOutput output; + + // line vertices + output.Pos = mul(ubo.proj, mul(ubo.view, mul(ubo.model, float4(pos, 1.0)))); + output.Color = float3(1.0, 0.0, 0.0); + outStream.Append(output); + + output.Pos = mul(ubo.proj, mul(ubo.view, mul(ubo.model, float4(pos + normal * normalLength, 1.0)))); + output.Color = float3(0.0, 0.0, 1.0); + outStream.Append(output); + + outStream.RestartStrip(); +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.geom.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader.geom.spv new file mode 100644 index 0000000000..a2525eb65c Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader.geom.spv differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.slang new file mode 100644 index 0000000000..269dce1630 --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.slang @@ -0,0 +1,95 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct UBO +{ + float4x4 model; + float4x4 view; + float4x4 proj; +}; +[[vk::binding(2, 0)]] ConstantBuffer ubo; + +struct s_meshlet +{ + uint vertices[64]; + uint indices[126]; + uint vertex_count; + uint index_count; +}; +[[vk::binding(3, 0)]] StructuredBuffer meshlets; + +struct s_vertex +{ + float4 position; + float4 normal; +}; +[[vk::binding(4, 0)]] StructuredBuffer vertices; + +struct VertexOut { + float4 Pos : SV_Position; + float4 color; +} + +[shader("mesh")] +[outputtopology("line")] +[numthreads(1, 1, 1)] +void main(out indices uint2 outIndices[64], out vertices VertexOut outVertices[126], uint3 groupId: SV_GroupID, uint3 groupThreadId: SV_GroupThreadID) +{ + uint meshlet_index = groupId.x; + uint thread_id = groupThreadId.x; + uint vertex_count = meshlets[meshlet_index].vertex_count; + uint index_count = meshlets[meshlet_index].index_count; + uint primitive_count = index_count/3; + SetMeshOutputCounts(primitive_count * 2, primitive_count); + + float normalLength = 0.1; + + float4x4 MVP = mul(ubo.proj, mul(ubo.view, ubo.model)); + + uint j = 0; + uint k = 0; + for (uint i = 0; i < primitive_count; ++i) + { + //triangle indices + uint vi1 = meshlets[meshlet_index].indices[j]; + uint vi2 = meshlets[meshlet_index].indices[j + 1]; + uint vi3 = meshlets[meshlet_index].indices[j + 2]; + + //middle point of triangle + float3 pos = (vertices[vi1].position.xyz + vertices[vi2].position.xyz + vertices[vi3].position.xyz) / 3.0; + float3 normal = vertices[vi1].normal.xyz; + + // line vertices + outVertices[k].Pos = mul(MVP, float4(pos, 1.0)); + outVertices[k].color = float4(0.0, 0.0, 1.0, 1.0); + + outVertices[k + 1].Pos = mul(MVP, float4(pos + normal * normalLength, 1.0)); + outVertices[k + 1].color = float4(1.0, 0.0, 0.0, 1.0); + + k = k + 2; + j= j + 3; + } + + //indices for line vertices + k = 0; + for (uint i = 0; i < primitive_count; i++) + { + outIndices[i] = uint2(k, k+1); + k = k + 2; + } +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.spv new file mode 100644 index 0000000000..e3be80d38c Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader.mesh.spv differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.vert.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader.vert.slang new file mode 100644 index 0000000000..01f23cf6dd --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader.vert.slang @@ -0,0 +1,57 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO { + float4x4 model; + float4x4 view; + float4x4 proj; + float4x4 normal; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Color = float3(0.0f, 1.0f, 1.0f); + output.Pos = mul(ubo.proj, mul(ubo.view, mul(ubo.model, float4(input.Pos, 1.0f)))); + + float4 FragPos = mul(ubo.model, float4(input.Pos, 1.0f)); + float3 lightPos = float3(-20.0f, 5.0f, 5.0f); + float3 lPos = mul(float3x3(ubo.model), lightPos.xyz); + output.Normal = mul(float3x3(ubo.normal), input.Normal); + + output.LightVec = lPos.xyz - FragPos.xyz; + output.ViewVec = -mul(ubo.view, mul(ubo.model, float4(input.Pos, 1.0f))).xyz; + return output; +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader.vert.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader.vert.spv new file mode 100644 index 0000000000..fdf81d885d Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader.vert.spv differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.frag.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.frag.slang new file mode 100644 index 0000000000..5f4ebe2f00 --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.frag.slang @@ -0,0 +1,29 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + float3 Color; +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + return float4(input.Color, 1.0f); +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.frag.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.frag.spv new file mode 100644 index 0000000000..57e6ef985c Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.frag.spv differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.vert.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.vert.slang new file mode 100644 index 0000000000..55e202897b --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.vert.slang @@ -0,0 +1,38 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float4 Pos; + float3 Normal; +} + +struct VSOutput +{ + float4 Pos : SV_Position; + float3 Normal; +} + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Normal = input.Normal; + output.Pos = float4(input.Pos.xyz, 1.0); + return output; +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.vert.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.vert.spv new file mode 100644 index 0000000000..a81a2a5598 Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader_base.vert.spv differ diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.slang b/shaders/gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.slang new file mode 100644 index 0000000000..cf009f07c9 --- /dev/null +++ b/shaders/gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.slang @@ -0,0 +1,29 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + float4 Color; +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + return input.Color; +} diff --git a/shaders/gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.spv b/shaders/gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.spv new file mode 100644 index 0000000000..d6f2503d7d Binary files /dev/null and b/shaders/gshader_to_mshader/slang/gshader_to_mshader_mesh.frag.spv differ diff --git a/shaders/hdr/hlsl/gbuffer.frag.hlsl b/shaders/hdr/hlsl/gbuffer.frag.hlsl index de0355b5ae..4a09800df0 100644 --- a/shaders/hdr/hlsl/gbuffer.frag.hlsl +++ b/shaders/hdr/hlsl/gbuffer.frag.hlsl @@ -1,4 +1,4 @@ -/* Copyright (c) 2024, Sascha Willems +/* Copyright (c) 2024-2025, Sascha Willems * * SPDX-License-Identifier: Apache-2.0 * @@ -97,7 +97,8 @@ FSOutput main(VSOutput input) fresnel *= (1.0 - F0); fresnel += F0; - float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14); + // Note: clamp to zero to mitigate any divide by zero + float spec = max((fresnel * geoAtt) / (NdotV * NdotL * 3.14), 0.0); color = textureEnvMap.Sample(samplerEnvMap, reflect(-wViewVec, wNormal)); diff --git a/shaders/hdr/hlsl/gbuffer.frag.spv b/shaders/hdr/hlsl/gbuffer.frag.spv index 94eab50e35..722cb6d711 100644 Binary files a/shaders/hdr/hlsl/gbuffer.frag.spv and b/shaders/hdr/hlsl/gbuffer.frag.spv differ diff --git a/shaders/hdr/slang/bloom.frag.slang b/shaders/hdr/slang/bloom.frag.slang new file mode 100644 index 0000000000..5ab45958a7 --- /dev/null +++ b/shaders/hdr/slang/bloom.frag.slang @@ -0,0 +1,82 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +Sampler2D samplerColor0; +Sampler2D samplerColor1; + +[[SpecializationConstant]] const int dir = 0; + +[shader("fragment")] +float4 main(VSOutput input) +{ + // From the OpenGL Super bible + const float weights[] = { 0.0024499299678342, + 0.0043538453346397, + 0.0073599963704157, + 0.0118349786570722, + 0.0181026699707781, + 0.0263392293891488, + 0.0364543006660986, + 0.0479932050577658, + 0.0601029809166942, + 0.0715974486241365, + 0.0811305381519717, + 0.0874493212267511, + 0.0896631113333857, + 0.0874493212267511, + 0.0811305381519717, + 0.0715974486241365, + 0.0601029809166942, + 0.0479932050577658, + 0.0364543006660986, + 0.0263392293891488, + 0.0181026699707781, + 0.0118349786570722, + 0.0073599963704157, + 0.0043538453346397, + 0.0024499299678342}; + + + const float blurScale = 0.003; + const float blurStrength = 1.0; + + float ar = 1.0; + // Aspect ratio for vertical blur pass + if (dir == 1) + { + float2 ts; + samplerColor1.GetDimensions(ts.x, ts.y); + ar = ts.y / ts.x; + } + + float2 P = input.UV.yx - float2(0, (weights.getCount() >> 1) * ar * blurScale); + + float4 color = float4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < weights.getCount(); i++) + { + float2 dv = float2(0.0, i * blurScale) * ar; + color += samplerColor1.Sample(P + dv) * weights[i] * blurStrength; + } + + return color; +} \ No newline at end of file diff --git a/shaders/hdr/slang/bloom.frag.spv b/shaders/hdr/slang/bloom.frag.spv new file mode 100644 index 0000000000..23cc325c64 Binary files /dev/null and b/shaders/hdr/slang/bloom.frag.spv differ diff --git a/shaders/hdr/slang/bloom.vert.slang b/shaders/hdr/slang/bloom.vert.slang new file mode 100644 index 0000000000..fd64a125b8 --- /dev/null +++ b/shaders/hdr/slang/bloom.vert.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex: SV_VertexID) +{ + VSOutput output; + output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2); + output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} \ No newline at end of file diff --git a/shaders/hdr/slang/bloom.vert.spv b/shaders/hdr/slang/bloom.vert.spv new file mode 100644 index 0000000000..26860adcd1 Binary files /dev/null and b/shaders/hdr/slang/bloom.vert.spv differ diff --git a/shaders/hdr/slang/composition.frag.slang b/shaders/hdr/slang/composition.frag.slang new file mode 100644 index 0000000000..263cb5cb73 --- /dev/null +++ b/shaders/hdr/slang/composition.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +Sampler2D samplerColor; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColor.Sample(input.UV); +} \ No newline at end of file diff --git a/shaders/hdr/slang/composition.frag.spv b/shaders/hdr/slang/composition.frag.spv new file mode 100644 index 0000000000..40782f9691 Binary files /dev/null and b/shaders/hdr/slang/composition.frag.spv differ diff --git a/shaders/hdr/slang/composition.vert.slang b/shaders/hdr/slang/composition.vert.slang new file mode 100644 index 0000000000..fd64a125b8 --- /dev/null +++ b/shaders/hdr/slang/composition.vert.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex: SV_VertexID) +{ + VSOutput output; + output.UV = float2((VertexIndex << 1) & 2, VertexIndex & 2); + output.Pos = float4(output.UV * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} \ No newline at end of file diff --git a/shaders/hdr/slang/composition.vert.spv b/shaders/hdr/slang/composition.vert.spv new file mode 100644 index 0000000000..26860adcd1 Binary files /dev/null and b/shaders/hdr/slang/composition.vert.spv differ diff --git a/shaders/hdr/slang/gbuffer.frag.slang b/shaders/hdr/slang/gbuffer.frag.slang new file mode 100644 index 0000000000..a45e6d995a --- /dev/null +++ b/shaders/hdr/slang/gbuffer.frag.slang @@ -0,0 +1,122 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +struct FSOutput +{ + float4 Color0; + float4 Color1; +}; + +struct UBOMatrices +{ + float4x4 projection; + float4x4 modelview; + float4x4 skyboxModelview; + float4x4 inverseModelView; + float modelscale; +}; +ConstantBuffer uboMatrices; + +SamplerCube samplerEnvMap; + +struct UBO { + float exposure; +}; +ConstantBuffer ubo; + +[[SpecializationConstant]] const int type = 0; + +[shader("fragment")] +FSOutput main(VSOutput input) +{ + FSOutput output; + float4 color; + float3 wcNormal; + + switch (type) { + case 0: // Skybox + { + float3 normal = normalize(input.UVW); + color = samplerEnvMap.Sample(normal); + } + break; + + case 1: // Reflect + { + float3 wViewVec = mul((float3x3)uboMatrices.inverseModelView, normalize(input.ViewVec)); + float3 normal = normalize(input.Normal); + float3 wNormal = mul((float3x3)uboMatrices.inverseModelView, normal); + + float NdotL = max(dot(normal, input.LightVec), 0.0); + + float3 eyeDir = normalize(input.ViewVec); + float3 halfVec = normalize(input.LightVec + eyeDir); + float NdotH = max(dot(normal, halfVec), 0.0); + float NdotV = max(dot(normal, eyeDir), 0.0); + float VdotH = max(dot(eyeDir, halfVec), 0.0); + + // Geometric attenuation + float NH2 = 2.0 * NdotH; + float g1 = (NH2 * NdotV) / VdotH; + float g2 = (NH2 * NdotL) / VdotH; + float geoAtt = min(1.0, min(g1, g2)); + + const float F0 = 0.6; + const float k = 0.2; + + // Fresnel (schlick approximation) + float fresnel = pow(1.0 - VdotH, 5.0); + fresnel *= (1.0 - F0); + fresnel += F0; + + // Note: clamp to zero to mitigate any divide by zero + float spec = max((fresnel * geoAtt) / (NdotV * NdotL * 3.14), 0.0); + + color = samplerEnvMap.Sample(reflect(-wViewVec, wNormal)); + + color = float4(color.rgb * NdotL * (k + spec * (1.0 - k)), 1.0); + } + break; + + case 2: // Refract + { + float3 wViewVec = mul((float3x3)uboMatrices.inverseModelView, normalize(input.ViewVec)); + float3 wNormal = mul((float3x3)uboMatrices.inverseModelView, input.Normal); + color = samplerEnvMap.Sample(refract(-wViewVec, wNormal, 1.0 / 1.6)); + } + break; + } + + // Color with manual exposure into attachment 0 + output.Color0.rgb = float3(1.0, 1.0, 1.0) - exp(-color.rgb * ubo.exposure); + + // Bright parts for bloom into attachment 1 + float l = dot(output.Color0.rgb, float3(0.2126, 0.7152, 0.0722)); + float threshold = 0.75; + output.Color1.rgb = (l > threshold) ? output.Color0.rgb : float3(0.0, 0.0, 0.0); + output.Color1.a = 1.0; + return output; +} \ No newline at end of file diff --git a/shaders/hdr/slang/gbuffer.frag.spv b/shaders/hdr/slang/gbuffer.frag.spv new file mode 100644 index 0000000000..6a0f2b79da Binary files /dev/null and b/shaders/hdr/slang/gbuffer.frag.spv differ diff --git a/shaders/hdr/slang/gbuffer.vert.slang b/shaders/hdr/slang/gbuffer.vert.slang new file mode 100644 index 0000000000..b72ba05338 --- /dev/null +++ b/shaders/hdr/slang/gbuffer.vert.slang @@ -0,0 +1,65 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO { + float4x4 projection; + float4x4 modelview; + float4x4 skyboxModelview; + float4x4 inverseModelView; + float modelscale; +}; +ConstantBuffer ubo; + +[[SpecializationConstant]] const int type = 0; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UVW = input.Pos; + float3 worldPos; + switch (type) { + case 0: // Skybox + worldPos = mul((float3x3)ubo.skyboxModelview, input.Pos); + output.Pos = mul(ubo.projection, float4(worldPos, 1.0)); + break; + case 1: // Object + worldPos = mul(ubo.modelview, float4(input.Pos * ubo.modelscale, 1.0)).xyz; + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz * ubo.modelscale, 1.0))); + break; + } + output.Normal = mul((float3x3)ubo.modelview, input.Normal); + float3 lightPos = float3(0.0f, -5.0f, 5.0f); + output.LightVec = lightPos.xyz - worldPos.xyz; + output.ViewVec = -worldPos.xyz; + return output; +} \ No newline at end of file diff --git a/shaders/hdr/slang/gbuffer.vert.spv b/shaders/hdr/slang/gbuffer.vert.spv new file mode 100644 index 0000000000..a580e3fbb4 Binary files /dev/null and b/shaders/hdr/slang/gbuffer.vert.spv differ diff --git a/shaders/instancing/slang/instancing.frag.slang b/shaders/instancing/slang/instancing.frag.slang new file mode 100644 index 0000000000..9b17ad0125 --- /dev/null +++ b/shaders/instancing/slang/instancing.frag.slang @@ -0,0 +1,41 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 UV; + float3 ViewVec; + float3 LightVec; +}; + +[[vk::binding(1,0)]] Sampler2DArray samplerArray; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float4 color = samplerArray.Sample(input.UV) * float4(input.Color, 1.0); + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = max(dot(N, L), 0.1) * input.Color; + float3 specular = (dot(N,L) > 0.0) ? pow(max(dot(R, V), 0.0), 16.0) * float3(0.75, 0.75, 0.75) * color.r : float3(0.0, 0.0, 0.0); + return float4(diffuse * color.rgb + specular, 1.0); +} \ No newline at end of file diff --git a/shaders/instancing/slang/instancing.frag.spv b/shaders/instancing/slang/instancing.frag.spv new file mode 100644 index 0000000000..2de9a2cfbe Binary files /dev/null and b/shaders/instancing/slang/instancing.frag.spv differ diff --git a/shaders/instancing/slang/instancing.vert.slang b/shaders/instancing/slang/instancing.vert.slang new file mode 100644 index 0000000000..383c6cc7bc --- /dev/null +++ b/shaders/instancing/slang/instancing.vert.slang @@ -0,0 +1,103 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +struct VSInput +{ + // Vertex attributes + float3 Pos : POSITION0; + float3 Normal : NORMAL0; + float2 UV : TEXCOORD0; + + // Instanced attributes + float3 instancePos : POSITION1; + float3 instanceRot : TEXCOORD1; + float instanceScale : TEXCOORD2; + int instanceTexIndex : TEXCOORD3; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float3 UV; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4 lightPos; + float locSpeed; + float globSpeed; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Color = float3(1.0); + output.UV = float3(input.UV, input.instanceTexIndex); + + // rotate around x + float s = sin(input.instanceRot.x + ubo.locSpeed); + float c = cos(input.instanceRot.x + ubo.locSpeed); + + float3x3 mx = { c, -s, 0.0, + s, c, 0.0, + 0.0, 0.0, 1.0 }; + + // rotate around y + s = sin(input.instanceRot.y + ubo.locSpeed); + c = cos(input.instanceRot.y + ubo.locSpeed); + + float3x3 my = { c, 0.0, -s, + 0.0, 1.0, 0.0, + s, 0.0, c }; + + // rot around z + s = sin(input.instanceRot.z + ubo.locSpeed); + c = cos(input.instanceRot.z + ubo.locSpeed); + + float3x3 mz = { 1.0, 0.0, 0.0, + 0.0, c, -s, + 0.0, s, c }; + + float3x3 rotMat = mul(mz, mul(my, mx)); + + float4x4 gRotMat; + s = sin(input.instanceRot.y + ubo.globSpeed); + c = cos(input.instanceRot.y + ubo.globSpeed); + gRotMat[0] = float4(c, 0.0, -s, 0.0); + gRotMat[1] = float4(0.0, 1.0, 0.0, 0.0); + gRotMat[2] = float4(s, 0.0, c, 0.0); + gRotMat[3] = float4(0.0, 0.0, 0.0, 1.0); + + float4 locPos = float4(mul(rotMat, input.Pos.xyz), 1.0); + float4 pos = float4((locPos.xyz * input.instanceScale) + input.instancePos, 1.0); + + output.Pos = mul(ubo.projection, mul(ubo.modelview, mul(gRotMat, pos))); + output.Normal = mul((float3x3)mul(ubo.modelview, gRotMat), mul(rotMat, input.Normal)); + + pos = mul(ubo.modelview, float4(input.Pos.xyz + input.instancePos, 1.0)); + float3 lPos = mul((float3x3)ubo.modelview, ubo.lightPos.xyz); + output.LightVec = lPos - pos.xyz; + output.ViewVec = -pos.xyz; + return output; +} \ No newline at end of file diff --git a/shaders/instancing/slang/instancing.vert.spv b/shaders/instancing/slang/instancing.vert.spv new file mode 100644 index 0000000000..1fa6f49172 Binary files /dev/null and b/shaders/instancing/slang/instancing.vert.spv differ diff --git a/shaders/instancing/slang/planet.frag.slang b/shaders/instancing/slang/planet.frag.slang new file mode 100644 index 0000000000..67209a5ada --- /dev/null +++ b/shaders/instancing/slang/planet.frag.slang @@ -0,0 +1,41 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float2 UV; + float3 ViewVec; + float3 LightVec; +}; + +[[vk::binding(1,0)]] Sampler2D samplerColorMap; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float4 color = samplerColorMap.Sample(input.UV) * float4(input.Color, 1.0) * 1.5; + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = max(dot(N, L), 0.0) * input.Color; + float3 specular = pow(max(dot(R, V), 0.0), 4.0) * float3(0.5, 0.5, 0.5) * color.r; + return float4(diffuse * color.rgb + specular, 1.0); +} \ No newline at end of file diff --git a/shaders/instancing/slang/planet.frag.spv b/shaders/instancing/slang/planet.frag.spv new file mode 100644 index 0000000000..1751e06ed9 Binary files /dev/null and b/shaders/instancing/slang/planet.frag.spv differ diff --git a/shaders/instancing/slang/planet.vert.slang b/shaders/instancing/slang/planet.vert.slang new file mode 100644 index 0000000000..6d8ba75e96 --- /dev/null +++ b/shaders/instancing/slang/planet.vert.slang @@ -0,0 +1,56 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos; + float3 Normal; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float3 Color; + float2 UV; + float3 ViewVec; + float3 LightVec; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4 lightPos; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Color = float3(1.0); + output.UV = input.UV * float2(10.0, 6.0); + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz, 1.0))); + float4 pos = mul(ubo.modelview, float4(input.Pos, 1.0)); + output.Normal = mul((float3x3)ubo.modelview, input.Normal); + float3 lPos = mul((float3x3)ubo.modelview, ubo.lightPos.xyz); + output.LightVec = lPos - pos.xyz; + output.ViewVec = -pos.xyz; + return output; +} \ No newline at end of file diff --git a/shaders/instancing/slang/planet.vert.spv b/shaders/instancing/slang/planet.vert.spv new file mode 100644 index 0000000000..983490f69c Binary files /dev/null and b/shaders/instancing/slang/planet.vert.spv differ diff --git a/shaders/instancing/slang/starfield.frag.slang b/shaders/instancing/slang/starfield.frag.slang new file mode 100644 index 0000000000..a56f89d841 --- /dev/null +++ b/shaders/instancing/slang/starfield.frag.slang @@ -0,0 +1,52 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define HASHSCALE3 float3(443.897, 441.423, 437.195) +#define STARFREQUENCY 0.01 + +// Hash function by Dave Hoskins (https://www.shadertoy.com/view/4djSRW) +float hash33(float3 p3) +{ + p3 = frac(p3 * HASHSCALE3); + p3 += dot(p3, p3.yxz+float3(19.19, 19.19, 19.19)); + return frac((p3.x + p3.y)*p3.z + (p3.x+p3.z)*p3.y + (p3.y+p3.z)*p3.x); +} + +float3 starField(float3 pos) +{ + float3 color = float3(0.0, 0.0, 0.0); + float threshhold = (1.0 - STARFREQUENCY); + float rnd = hash33(pos); + if (rnd >= threshhold) + { + float starCol = pow((rnd - threshhold) / (1.0 - threshhold), 16.0); + color += starCol.xxx; + } + return color; +} + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return float4(starField(input.UVW), 1.0); +} \ No newline at end of file diff --git a/shaders/instancing/slang/starfield.frag.spv b/shaders/instancing/slang/starfield.frag.spv new file mode 100644 index 0000000000..2e3b7d4110 Binary files /dev/null and b/shaders/instancing/slang/starfield.frag.spv differ diff --git a/shaders/instancing/slang/starfield.vert.slang b/shaders/instancing/slang/starfield.vert.slang new file mode 100644 index 0000000000..24eecdbcf6 --- /dev/null +++ b/shaders/instancing/slang/starfield.vert.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +[shader("vertex")] +VSOutput main(uint VertexIndex: SV_VertexID) +{ + VSOutput output; + output.UVW = float3((VertexIndex << 1) & 2, VertexIndex & 2, VertexIndex & 2); + output.Pos = float4(output.UVW.xy * 2.0f - 1.0f, 0.0f, 1.0f); + return output; +} \ No newline at end of file diff --git a/shaders/instancing/slang/starfield.vert.spv b/shaders/instancing/slang/starfield.vert.spv new file mode 100644 index 0000000000..35d8c6a8bc Binary files /dev/null and b/shaders/instancing/slang/starfield.vert.spv differ diff --git a/shaders/logic_op_dynamic_state/slang/background.frag.slang b/shaders/logic_op_dynamic_state/slang/background.frag.slang new file mode 100644 index 0000000000..06558eddfd --- /dev/null +++ b/shaders/logic_op_dynamic_state/slang/background.frag.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +[[vk::binding(1,0)]] SamplerCube samplerEnvMap; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float3 normal = normalize(input.UVW); + float4 color = samplerEnvMap.Sample(normal); + return float4(color.rgb, 1.0); +} \ No newline at end of file diff --git a/shaders/logic_op_dynamic_state/slang/background.frag.spv b/shaders/logic_op_dynamic_state/slang/background.frag.spv new file mode 100644 index 0000000000..99dfa9a720 Binary files /dev/null and b/shaders/logic_op_dynamic_state/slang/background.frag.spv differ diff --git a/shaders/logic_op_dynamic_state/slang/background.vert.slang b/shaders/logic_op_dynamic_state/slang/background.vert.slang new file mode 100644 index 0000000000..02353a18ea --- /dev/null +++ b/shaders/logic_op_dynamic_state/slang/background.vert.slang @@ -0,0 +1,44 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UVW = input.Pos; + output.Pos = mul(ubo.projection, mul(ubo.view, float4(input.Pos * 10.0, 1.0))); + return output; +} \ No newline at end of file diff --git a/shaders/logic_op_dynamic_state/slang/background.vert.spv b/shaders/logic_op_dynamic_state/slang/background.vert.spv new file mode 100644 index 0000000000..37a4e3df46 Binary files /dev/null and b/shaders/logic_op_dynamic_state/slang/background.vert.spv differ diff --git a/shaders/logic_op_dynamic_state/slang/baseline.frag.slang b/shaders/logic_op_dynamic_state/slang/baseline.frag.slang new file mode 100644 index 0000000000..6e6787ff68 --- /dev/null +++ b/shaders/logic_op_dynamic_state/slang/baseline.frag.slang @@ -0,0 +1,44 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float4 Color; + float3 LightVec; + float3 LightColor[2]; + float3 ViewVec; + float LightIntensity; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float attenuation = 1.0 / dot(input.LightVec, input.LightVec); + + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + + float3 diffuse = input.LightColor[0] * attenuation * max(dot(N, L), 0) * input.LightIntensity; + float3 ambient = input.LightColor[1]; + float3 specular = pow(max(dot(R, V), 0.0), 16.0) * float3(0.65); + + return float4((ambient + diffuse) * input.Color.rgb + (specular * input.LightIntensity / 50), input.Color.a); +} diff --git a/shaders/logic_op_dynamic_state/slang/baseline.frag.spv b/shaders/logic_op_dynamic_state/slang/baseline.frag.spv new file mode 100644 index 0000000000..d226fee113 Binary files /dev/null and b/shaders/logic_op_dynamic_state/slang/baseline.frag.spv differ diff --git a/shaders/logic_op_dynamic_state/slang/baseline.vert.slang b/shaders/logic_op_dynamic_state/slang/baseline.vert.slang new file mode 100644 index 0000000000..8270f15a4c --- /dev/null +++ b/shaders/logic_op_dynamic_state/slang/baseline.vert.slang @@ -0,0 +1,69 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct UBOBaseline +{ + float4 ambientLightColor; + float4 lightPosition; + float4 lightColor; + float lightIntensity; +}; +ConstantBuffer ubo_baseline; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float4 Color; + float3 LightVec; + float3 LightColor[2]; + float3 ViewVec; + float LightIntensity; +}; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4x4 model, uniform float4 color) +{ + VSOutput output; + + float4 localPos = mul(ubo.view, mul(model, float4(input.Pos, 1.0))); + float4 positionWorld = mul(model, float4(input.Pos, 1.0)); + + output.Color = color; + output.Pos = mul(ubo.projection, localPos); + output.Normal = mul((float3x3)(mul(ubo.view, model)), input.Normal); + output.LightVec = ubo_baseline.lightPosition.xyz - positionWorld.xyz; + output.LightColor[0] = ubo_baseline.lightColor.xyz * ubo_baseline.lightColor.w; + output.LightColor[1] = ubo_baseline.ambientLightColor.xyz * ubo_baseline.ambientLightColor.w; + output.ViewVec = -localPos.xyz; + output.LightIntensity = ubo_baseline.lightIntensity; + + return output; +} diff --git a/shaders/logic_op_dynamic_state/slang/baseline.vert.spv b/shaders/logic_op_dynamic_state/slang/baseline.vert.spv new file mode 100644 index 0000000000..fa1016e955 Binary files /dev/null and b/shaders/logic_op_dynamic_state/slang/baseline.vert.spv differ diff --git a/shaders/mesh_shading/slang/ms.mesh.slang b/shaders/mesh_shading/slang/ms.mesh.slang new file mode 100644 index 0000000000..84dc914bd8 --- /dev/null +++ b/shaders/mesh_shading/slang/ms.mesh.slang @@ -0,0 +1,33 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VertexOutput +{ + float4 position : SV_Position; +}; + +[shader("mesh")] +[outputtopology("triangle")] +[numthreads(1, 1, 1)] +void main(out indices uint3 triangles[1], out vertices VertexOutput vertices[3], uint3 DispatchThreadID: SV_DispatchThreadID) +{ + SetMeshOutputCounts(3, 1); + vertices[0].position = float4(0.5, -0.5, 0, 1); + vertices[1].position = float4(0.5, 0.5, 0, 1); + vertices[2].position = float4(-0.5, 0.5, 0, 1); + triangles[0] = uint3(0, 1, 2); +} \ No newline at end of file diff --git a/shaders/mesh_shading/slang/ms.mesh.spv b/shaders/mesh_shading/slang/ms.mesh.spv new file mode 100644 index 0000000000..10a5b827f3 Binary files /dev/null and b/shaders/mesh_shading/slang/ms.mesh.spv differ diff --git a/shaders/mesh_shading/slang/ps.frag.slang b/shaders/mesh_shading/slang/ps.frag.slang new file mode 100644 index 0000000000..f9be0d8335 --- /dev/null +++ b/shaders/mesh_shading/slang/ps.frag.slang @@ -0,0 +1,22 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[shader("fragment")] +float4 main() +{ + return float4(1.0, 0.0, 0.0, 1.0); +} diff --git a/shaders/mesh_shading/slang/ps.frag.spv b/shaders/mesh_shading/slang/ps.frag.spv new file mode 100644 index 0000000000..f9fb85491a Binary files /dev/null and b/shaders/mesh_shading/slang/ps.frag.spv differ diff --git a/shaders/open_cl_interop/slang/texture_display.frag.slang b/shaders/open_cl_interop/slang/texture_display.frag.slang new file mode 100644 index 0000000000..f346ba0e8f --- /dev/null +++ b/shaders/open_cl_interop/slang/texture_display.frag.slang @@ -0,0 +1,31 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] +Sampler2D samplerColor; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColor.Sample(input.UV); +} \ No newline at end of file diff --git a/shaders/open_cl_interop/slang/texture_display.frag.spv b/shaders/open_cl_interop/slang/texture_display.frag.spv new file mode 100644 index 0000000000..7a3e003c10 Binary files /dev/null and b/shaders/open_cl_interop/slang/texture_display.frag.spv differ diff --git a/shaders/open_cl_interop/slang/texture_display.vert.slang b/shaders/open_cl_interop/slang/texture_display.vert.slang new file mode 100644 index 0000000000..6721698bd4 --- /dev/null +++ b/shaders/open_cl_interop/slang/texture_display.vert.slang @@ -0,0 +1,46 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; + float4 viewPos; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0))); + return output; +}; diff --git a/shaders/open_cl_interop/slang/texture_display.vert.spv b/shaders/open_cl_interop/slang/texture_display.vert.spv new file mode 100644 index 0000000000..57f4e47837 Binary files /dev/null and b/shaders/open_cl_interop/slang/texture_display.vert.spv differ diff --git a/shaders/patch_control_points/slang/tess.frag.slang b/shaders/patch_control_points/slang/tess.frag.slang new file mode 100644 index 0000000000..7d07812901 --- /dev/null +++ b/shaders/patch_control_points/slang/tess.frag.slang @@ -0,0 +1,28 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct DSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +[shader("fragment")] +float4 main(DSOutput input) +{ + return float4(input.Color, 1.0); +} \ No newline at end of file diff --git a/shaders/patch_control_points/slang/tess.frag.spv b/shaders/patch_control_points/slang/tess.frag.spv new file mode 100644 index 0000000000..57e6ef985c Binary files /dev/null and b/shaders/patch_control_points/slang/tess.frag.spv differ diff --git a/shaders/patch_control_points/slang/tess.tesc.slang b/shaders/patch_control_points/slang/tess.tesc.slang new file mode 100644 index 0000000000..b46afac291 --- /dev/null +++ b/shaders/patch_control_points/slang/tess.tesc.slang @@ -0,0 +1,136 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct UBOTessellation +{ + float tessellationFactor; +}; +ConstantBuffer ubo_tessellation; + +struct VSOutput +{ + float4 Pos : SV_POSITION; +}; + +struct HSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +struct ConstantsHSOutput +{ + float TessLevelOuter[4] : SV_TessFactor; + float TessLevelInner[2] : SV_InsideTessFactor; +}; + +float getTessLevel(float4 p0, float4 p1) +{ + float tessellationLevel = 0.0f; + const float midDistance = 1.6f; + const float shortDistance = 1.0f; + + // Calculate edge mid point + float4 centerPoint = 0.5f * (p0 + p1); + + // Calculate vector from camera to mid point + float4 vCam = mul(ubo.view, centerPoint); + + // Calculate vector for camera projection + float4 vCamView = mul(ubo.projection, vCam); + + // Calculate the vector length + float centerDistance = length(vCamView); + + // Adjusting the size of the tessellation depending on the length of the vector + if (centerDistance >= midDistance) + { + tessellationLevel = 1.0f; + } + else if (centerDistance >= shortDistance && centerDistance < midDistance) + { + tessellationLevel = ubo_tessellation.tessellationFactor * 0.4f; + } + else + { + tessellationLevel = ubo_tessellation.tessellationFactor; + } + + return tessellationLevel; +} + +float3 getColor(float tessellationLevel) +{ + float3 outColor; + if (tessellationLevel == 1.0f) + { + outColor = float3(1.0f, 0.0f, 0.0f); // red color + } + else if (tessellationLevel == ubo_tessellation.tessellationFactor * 0.4f) + { + outColor = float3(0.0f, 0.0f, 1.0f); // blue color + } + else if (tessellationLevel == ubo_tessellation.tessellationFactor) + { + outColor = float3(0.0f, 1.0f, 0.0f); // green color + } + + return outColor; +} + +ConstantsHSOutput ConstantsHS(InputPatch patch) +{ + ConstantsHSOutput output; + + if (ubo_tessellation.tessellationFactor > 1.0) + { + output.TessLevelOuter[0] = getTessLevel(patch[2].Pos, patch[0].Pos); + output.TessLevelOuter[1] = getTessLevel(patch[0].Pos, patch[1].Pos); + output.TessLevelOuter[2] = getTessLevel(patch[1].Pos, patch[2].Pos); + output.TessLevelInner[0] = lerp(output.TessLevelOuter[0], output.TessLevelOuter[2], 0.5); + } + else + { + output.TessLevelOuter[0] = 1; + output.TessLevelOuter[1] = 1; + output.TessLevelOuter[2] = 1; + output.TessLevelInner[0] = 1; + } + + return output; +} + +[domain("tri")] +[partitioning("integer")] +[outputtopology("triangle_cw")] +[outputcontrolpoints(3)] +[patchconstantfunc("ConstantsHS")] +[maxtessfactor(20.0)] +[shader("hull")] +HSOutput main(InputPatch patch, uint InvocationID : SV_OutputControlPointID) +{ + HSOutput output; + output.Pos = patch[InvocationID].Pos; + output.Color = getColor(getTessLevel(patch[2].Pos, patch[0].Pos)); + return output; +} diff --git a/shaders/patch_control_points/slang/tess.tesc.spv b/shaders/patch_control_points/slang/tess.tesc.spv new file mode 100644 index 0000000000..13ab6a18fa Binary files /dev/null and b/shaders/patch_control_points/slang/tess.tesc.spv differ diff --git a/shaders/patch_control_points/slang/tess.tese.slang b/shaders/patch_control_points/slang/tess.tese.slang new file mode 100644 index 0000000000..21399a34dd --- /dev/null +++ b/shaders/patch_control_points/slang/tess.tese.slang @@ -0,0 +1,60 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct HSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +struct ConstantsHSOutput +{ + float TessLevelOuter[4] : SV_TessFactor; + float TessLevelInner[2] : SV_InsideTessFactor; +}; + +struct DSOutput +{ + float4 Pos : SV_POSITION; + float3 Color; +}; + +float4 interpolate3D(float4 v0, float4 v1, float4 v2, float3 TessCoord) +{ + return TessCoord.x * v0 + TessCoord.y * v1 + TessCoord.z * v2; +} + +[domain("tri")] +[shader("domain")] +DSOutput main(ConstantsHSOutput input, float3 TessCoord : SV_DomainLocation, const OutputPatch patch) +{ + DSOutput output; + + float4 pos = interpolate3D(patch[0].Pos, patch[1].Pos, patch[2].Pos, TessCoord); + + output.Pos = mul(ubo.projection, mul(ubo.view, pos)); + output.Color = patch[0].Color; + + return output; +} \ No newline at end of file diff --git a/shaders/patch_control_points/slang/tess.tese.spv b/shaders/patch_control_points/slang/tess.tese.spv new file mode 100644 index 0000000000..827dfbf21b Binary files /dev/null and b/shaders/patch_control_points/slang/tess.tese.spv differ diff --git a/shaders/patch_control_points/slang/tess.vert.slang b/shaders/patch_control_points/slang/tess.vert.slang new file mode 100644 index 0000000000..88e6e01fbb --- /dev/null +++ b/shaders/patch_control_points/slang/tess.vert.slang @@ -0,0 +1,51 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; +}; + +struct UBO +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; +}; + +#define PI 3.14159 + +[shader("vertex")] +VSOutput main(VSInput input, uniform float3 direction) +{ + VSOutput output; + + float4x4 rotX = float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + rotX[1][1] = cos(PI); + rotX[1][2] = sin(PI); + rotX[2][1] = -sin(PI); + rotX[2][2] = cos(PI); + + output.Pos = mul(rotX, float4(input.Pos + direction, 1.0f)); + + return output; +} \ No newline at end of file diff --git a/shaders/patch_control_points/slang/tess.vert.spv b/shaders/patch_control_points/slang/tess.vert.spv new file mode 100644 index 0000000000..77babe7be6 Binary files /dev/null and b/shaders/patch_control_points/slang/tess.vert.spv differ diff --git a/shaders/profiles/slang/profiles.frag.slang b/shaders/profiles/slang/profiles.frag.slang index a43120569b..5beb6d2901 100644 --- a/shaders/profiles/slang/profiles.frag.slang +++ b/shaders/profiles/slang/profiles.frag.slang @@ -16,17 +16,17 @@ */ [[vk::binding(1, 0)]] -Sampler2D textures[] : register(t1, space0); +Sampler2D textures[]; struct VSOutput { float4 Pos : SV_POSITION; - [[vk::location(0)]] float2 UV : TEXCOORD0; - [[vk::location(1)]] nointerpolation int TexIndex : TEXCOORD1; + float2 UV; + nointerpolation int TexIndex; }; [shader("fragment")] -float4 main(VSOutput input) : SV_TARGET +float4 main(VSOutput input) { return textures[NonUniformResourceIndex(input.TexIndex)].Sample(input.UV); } \ No newline at end of file diff --git a/shaders/profiles/slang/profiles.frag.spv b/shaders/profiles/slang/profiles.frag.spv new file mode 100644 index 0000000000..b0c2dd78e1 Binary files /dev/null and b/shaders/profiles/slang/profiles.frag.spv differ diff --git a/shaders/profiles/slang/profiles.vert.slang b/shaders/profiles/slang/profiles.vert.slang index f918105474..ebff20ce2a 100644 --- a/shaders/profiles/slang/profiles.vert.slang +++ b/shaders/profiles/slang/profiles.vert.slang @@ -19,8 +19,8 @@ struct VSInput { [[vk::location(0)]] float3 Pos : POSITION0; - [[vk::location(1)]] float2 UV : TEXCOORD0; - [[vk::location(2)]] int TexIndex : TEXCOORD1; + [[vk::location(1)]] float2 UV; + [[vk::location(2)]] int TexIndex; }; struct UBO @@ -28,20 +28,19 @@ struct UBO float4x4 projection; float4x4 view; }; -[[vk::binding(0, 0)]] -ConstantBuffer ubo : register(b0, space0); +ConstantBuffer ubo; struct VSOutput { float4 Pos : SV_POSITION; - [[vk::location(0)]] float2 UV : TEXCOORD0; - [[vk::location(1)]] nointerpolation int TexIndex : TEXCOORD1; + [[vk::location(0)]] float2 UV; + [[vk::location(1)]] nointerpolation int TexIndex; }; [shader("vertex")] VSOutput main(VSInput input) { - VSOutput output = (VSOutput) 0; + VSOutput output; output.UV = input.UV; output.TexIndex = input.TexIndex; output.Pos = mul(ubo.projection, mul(ubo.view, float4(input.Pos.xyz, 1.0))); diff --git a/shaders/profiles/slang/profiles.vert.spv b/shaders/profiles/slang/profiles.vert.spv new file mode 100644 index 0000000000..cda2e0efaa Binary files /dev/null and b/shaders/profiles/slang/profiles.vert.spv differ diff --git a/shaders/push_descriptors/slang/cube.frag.slang b/shaders/push_descriptors/slang/cube.frag.slang new file mode 100644 index 0000000000..99d03c74c4 --- /dev/null +++ b/shaders/push_descriptors/slang/cube.frag.slang @@ -0,0 +1,29 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(2, 0)]] Sampler2D samplerColorMap; + +struct VSOutput +{ + float2 UV; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColorMap.Sample(input.UV); +} \ No newline at end of file diff --git a/shaders/push_descriptors/slang/cube.frag.spv b/shaders/push_descriptors/slang/cube.frag.spv new file mode 100644 index 0000000000..97942b5e29 Binary files /dev/null and b/shaders/push_descriptors/slang/cube.frag.spv differ diff --git a/shaders/push_descriptors/slang/cube.vert.slang b/shaders/push_descriptors/slang/cube.vert.slang new file mode 100644 index 0000000000..11adefd56f --- /dev/null +++ b/shaders/push_descriptors/slang/cube.vert.slang @@ -0,0 +1,51 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; +}; + +struct UBOCamera +{ + float4x4 projection; + float4x4 view; +}; +ConstantBuffer uboCamera; + +struct UBOModel +{ + float4x4 local; +}; +ConstantBuffer uboModel; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(uboCamera.projection, mul(uboCamera.view, mul(uboModel.local, float4(input.Pos.xyz, 1.0)))); + return output; +} \ No newline at end of file diff --git a/shaders/push_descriptors/slang/cube.vert.spv b/shaders/push_descriptors/slang/cube.vert.spv new file mode 100644 index 0000000000..2248b16322 Binary files /dev/null and b/shaders/push_descriptors/slang/cube.vert.spv differ diff --git a/shaders/ray_queries/slang/ray_shadow.frag.slang b/shaders/ray_queries/slang/ray_shadow.frag.slang new file mode 100644 index 0000000000..164e3c77eb --- /dev/null +++ b/shaders/ray_queries/slang/ray_shadow.frag.slang @@ -0,0 +1,132 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +RaytracingAccelerationStructure topLevelAS; + +struct GlobalUniform +{ + float4x4 view; + float4x4 proj; + float4 camera_position; + float4 light_position; +}; +ConstantBuffer global_uniform; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float4 O_Pos; + float3 O_Normal; + float4 Scene_pos; // scene with respect to BVH coordinates +}; + +/** +Calculate ambient occlusion +*/ +float calculate_ambient_occlusion(float3 object_point, float3 object_normal) +{ + const float PI = float.getPi(); + const float ao_mult = 1; + uint max_ao_each = 3; + uint max_ao = max_ao_each * max_ao_each; + const float max_dist = 2; + const float tmin = 0.01, tmax = max_dist; + float accumulated_ao = 0.f; + float3 u = abs(dot(object_normal, float3(0, 0, 1))) > 0.9 ? cross(object_normal, float3(1, 0, 0)) : cross(object_normal, float3(0, 0, 1)); + float3 v = cross(object_normal, u); + float accumulated_factor = 0; + for (uint j = 0; j < max_ao_each; ++j) + { + float phi = 0.5*(-PI + 2 * PI * (float(j + 1) / float(max_ao_each + 2))); + for (uint k = 0; k < max_ao_each; ++k){ + float theta = 0.5*(-PI + 2 * PI * (float(k + 1) / float(max_ao_each + 2))); + float x = cos(phi) * sin(theta); + float y = sin(phi) * sin(theta); + float z = cos(theta); + float3 direction = x * u + y * v + z * object_normal; + + RayDesc ray; + ray.TMin = tmin; + ray.TMax = tmax; + ray.Origin = object_point; + ray.Direction = direction.xyz; + + RayQuery query; + query.TraceRayInline(topLevelAS, 0, 0xFF, ray); + query.Proceed(); + float dist = max_dist; + if (query.CommittedStatus() == COMMITTED_TRIANGLE_HIT) + { + dist = query.CommittedRayT(); + } + float ao = min(dist, max_dist); + float factor = 0.2 + 0.8 * z * z; + accumulated_factor += factor; + accumulated_ao += ao * factor; + } + } + accumulated_ao /= (max_dist * accumulated_factor); + accumulated_ao *= accumulated_ao; + accumulated_ao = max(min((accumulated_ao) * ao_mult, 1), 0); + return accumulated_ao; +} + +/** +Apply ray tracing to determine whether the point intersects light +*/ +bool intersects_light(float3 light_origin, float3 pos) +{ + const float tmin = 0.01, tmax = 1.0; + const float3 direction = light_origin - pos; + + RayQuery query; + + RayDesc ray; + ray.TMin = tmin; + ray.TMax = tmax; + ray.Origin = pos; + ray.Direction = direction.xyz; + + // The following runs the actual ray query + // For performance, use gl_RayFlagsTerminateOnFirstHitEXT, since we only need to know + // whether an intersection exists, and not necessarily any particular intersection + query.TraceRayInline(topLevelAS, 0, 0xFF, ray); + + // The following is the canonical way of using ray Queries from the fragment shader when + // there's more than one bounce or hit to traverse: + // while (rayQueryProceedEXT(query)) { } + // This sample has set flags to gl_RayFlagsTerminateOnFirstHitEXT which means that there + // will never be a bounce and no need for an expensive while loop. (i.e. we only need to call it once). + query.Proceed(); + if (query.CommittedStatus() == COMMITTED_TRIANGLE_HIT) + { + // e.g. to get distance: + // const float dist = rayQueryGetIntersectionTEXT(query, false); + return true; + } + + return false; +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + // this is where we apply the shadow + const float ao = calculate_ambient_occlusion(input.Scene_pos.xyz, input.O_Normal); + const float4 lighting = intersects_light(global_uniform.light_position.xyz, input.Scene_pos.xyz) ? float4(0.2, 0.2, 0.2, 1.0) : float4(1.0); + return lighting * float4(ao * float3(1), 1); +} diff --git a/shaders/ray_queries/slang/ray_shadow.frag.spv b/shaders/ray_queries/slang/ray_shadow.frag.spv new file mode 100644 index 0000000000..727d4d4c81 Binary files /dev/null and b/shaders/ray_queries/slang/ray_shadow.frag.spv differ diff --git a/shaders/ray_queries/slang/ray_shadow.vert.slang b/shaders/ray_queries/slang/ray_shadow.vert.slang new file mode 100644 index 0000000000..7195bbf9f0 --- /dev/null +++ b/shaders/ray_queries/slang/ray_shadow.vert.slang @@ -0,0 +1,53 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + struct VSInput +{ + float3 Position : POSITION0; + float3 Normal; +}; + +RaytracingAccelerationStructure topLevelAS; + +struct GlobalUniform +{ + float4x4 view; + float4x4 proj; + float4 camera_position; + float4 light_position; +}; +ConstantBuffer global_uniform; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float4 O_Pos; + float3 O_Normal; + float4 Scene_pos; // scene with respect to BVH coordinates +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + // We want to be able to perform ray tracing, so don't apply any matrix to scene_pos + output.Scene_pos = float4(input.Position, 1.0); + output.O_Pos = mul(global_uniform.view, float4(input.Position, 1.0)); + output.O_Normal = input.Normal; + output.Pos = mul(global_uniform.proj, mul(global_uniform.view, float4(input.Position, 1.0))); + return output; +} diff --git a/shaders/ray_queries/slang/ray_shadow.vert.spv b/shaders/ray_queries/slang/ray_shadow.vert.spv new file mode 100644 index 0000000000..af2d5ca6c5 Binary files /dev/null and b/shaders/ray_queries/slang/ray_shadow.vert.spv differ diff --git a/shaders/ray_tracing_basic/slang/closesthit.rchit.slang b/shaders/ray_tracing_basic/slang/closesthit.rchit.slang new file mode 100644 index 0000000000..f720fe6f50 --- /dev/null +++ b/shaders/ray_tracing_basic/slang/closesthit.rchit.slang @@ -0,0 +1,33 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Attributes +{ + float2 bary; +}; + +struct Payload +{ + float3 hitValue; +}; + +[shader("closesthit")] +void main(inout Payload p, in Attributes attribs) +{ + const float3 barycentricCoords = float3(1.0f - attribs.bary.x - attribs.bary.y, attribs.bary.x, attribs.bary.y); + p.hitValue = barycentricCoords; +} diff --git a/shaders/ray_tracing_basic/slang/closesthit.rchit.spv b/shaders/ray_tracing_basic/slang/closesthit.rchit.spv new file mode 100644 index 0000000000..345241992a Binary files /dev/null and b/shaders/ray_tracing_basic/slang/closesthit.rchit.spv differ diff --git a/shaders/ray_tracing_basic/slang/miss.rmiss.slang b/shaders/ray_tracing_basic/slang/miss.rmiss.slang new file mode 100644 index 0000000000..b5c5e3b871 --- /dev/null +++ b/shaders/ray_tracing_basic/slang/miss.rmiss.slang @@ -0,0 +1,27 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Payload +{ + float3 hitValue; +}; + +[shader("miss")] +void main(inout Payload p) +{ + p.hitValue = float3(0.0, 0.0, 0.2); +} \ No newline at end of file diff --git a/shaders/ray_tracing_basic/slang/miss.rmiss.spv b/shaders/ray_tracing_basic/slang/miss.rmiss.spv new file mode 100644 index 0000000000..3f89fc305a Binary files /dev/null and b/shaders/ray_tracing_basic/slang/miss.rmiss.spv differ diff --git a/shaders/ray_tracing_basic/slang/raygen.rgen.slang b/shaders/ray_tracing_basic/slang/raygen.rgen.slang new file mode 100644 index 0000000000..973ef77f87 --- /dev/null +++ b/shaders/ray_tracing_basic/slang/raygen.rgen.slang @@ -0,0 +1,54 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +RaytracingAccelerationStructure accelStruct; +RWTexture2D image; + +struct CameraProperties +{ + float4x4 viewInverse; + float4x4 projInverse; +}; +ConstantBuffer camera; + +struct Payload +{ + float3 hitValue; +}; + +[shader("raygeneration")] +void main() +{ + uint3 LaunchID = DispatchRaysIndex(); + uint3 LaunchSize = DispatchRaysDimensions(); + + const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5); + const float2 inUV = pixelCenter / float2(LaunchSize.xy); + float2 d = inUV * 2.0 - 1.0; + float4 target = mul(camera.projInverse, float4(d.x, d.y, 1, 1)); + + RayDesc rayDesc; + rayDesc.Origin = mul(camera.viewInverse, float4(0, 0, 0, 1)).xyz; + rayDesc.Direction = mul(camera.viewInverse, float4(normalize(target.xyz), 0)).xyz; + rayDesc.TMin = 0.001; + rayDesc.TMax = 10000.0; + + Payload payload; + TraceRay(accelStruct, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload); + + image[int2(LaunchID.xy)] = float4(payload.hitValue, 0.0); +} \ No newline at end of file diff --git a/shaders/ray_tracing_basic/slang/raygen.rgen.spv b/shaders/ray_tracing_basic/slang/raygen.rgen.spv new file mode 100644 index 0000000000..9b8d490ae7 Binary files /dev/null and b/shaders/ray_tracing_basic/slang/raygen.rgen.spv differ diff --git a/shaders/ray_tracing_extended/slang/closesthit.rchit.slang b/shaders/ray_tracing_extended/slang/closesthit.rchit.slang new file mode 100644 index 0000000000..5139fdad59 --- /dev/null +++ b/shaders/ray_tracing_extended/slang/closesthit.rchit.slang @@ -0,0 +1,148 @@ +/* Copyright (c) 2025, Sascha Willems +* +* SPDX-License-Identifier: Apache-2.0 +* +* Licensed under the Apache License, Version 2.0 the "License"; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +#define RENDER_DEFAULT 0 +#define RENDER_BARYCENTRIC 1 +#define RENDER_INSTANCE_ID 2 +#define RENDER_DISTANCE 3 +#define RENDER_GLOBAL_XYZ 4 +#define RENDER_SHADOW_MAP 5 +#define RENDER_AO 6 + +struct Payload +{ + float4 color; + float4 intersection; // {x, y, z, intersectionType} + float4 normal; // {nx, ny, nz, distance} +}; + +struct Attributes +{ + float2 bary; +}; + +[[vk::binding(4, 0)]] StructuredBuffer vertex_buffer; +[[vk::binding(5, 0)]] StructuredBuffer index_buffer; +[[vk::binding(6, 0)]] StructuredBuffer data_map; +[[vk::binding(7, 0)]] Sampler2D samplers[26]; +[[vk::binding(8, 0)]] StructuredBuffer dynamic_vertex_buffer; +[[vk::binding(9, 0)]] StructuredBuffer dynamic_index_buffer; + +[[SpecializationConstant]] const int render_mode = RENDER_DEFAULT; + +float3 heatmap(float value, float minValue, float maxValue) +{ + float scaled = (min(max(value, minValue), maxValue) - minValue) / (maxValue - minValue); + float r = scaled * (3.14159265359 / 2.); + return float3(sin(r), sin(2 * r), cos(r)); +} + +struct Vertex +{ + float3 pt; + float3 normal; + float2 coordinate; +}; + +Vertex getVertex(uint vertexOffset, uint index, bool is_static) +{ + uint base_index = 2 * (vertexOffset + index); + float4 A = is_static ? vertex_buffer[base_index] : dynamic_vertex_buffer[base_index]; + float4 B = is_static ? vertex_buffer[base_index + 1] : dynamic_vertex_buffer[base_index + 1]; + + Vertex v; + v.pt = A.xyz; + v.normal = float3(A.w, B.x, B.y); + v.coordinate = float2(B.z, B.w); + return v; +} + +uint3 getIndices(uint triangle_offset, uint primitive_id, bool is_static) +{ + uint base_index = 3 * (triangle_offset + primitive_id); + uint index0 = is_static ? index_buffer[base_index] : dynamic_index_buffer[base_index]; + uint index1 = is_static ? index_buffer[base_index + 1] : dynamic_index_buffer[base_index + 1]; + uint index2 = is_static ? index_buffer[base_index + 2] : dynamic_index_buffer[base_index + 2]; + + return uint3(index0, index1, index2); +} + +void handleDraw(inout Payload hitValue, float2 attribs) +{ + uint index = InstanceID(); + + uint vertexOffset = data_map[4 * index]; + uint triangleOffset = data_map[4*index + 1]; + uint imageOffset = data_map[4 * index + 2]; + uint objectType = data_map[4 * index + 3]; + bool is_static = objectType != 1; + + uint3 indices = getIndices(triangleOffset, PrimitiveIndex(), is_static); + Vertex A = getVertex(vertexOffset, indices.x, is_static), B = getVertex(vertexOffset, indices.y, is_static), C = getVertex(vertexOffset, indices.z, is_static); + + // interpolate and obtain world point + const float3 barycentricCoords = float3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y); + float alpha = barycentricCoords.x, beta = barycentricCoords.y, gamma = barycentricCoords.z; + float3 pt = alpha * A.pt + beta * B.pt + gamma * C.pt; + float4x3 transform = WorldToObject4x3(); + float3 worldPt = WorldRayOrigin() + RayTCurrent() * WorldRayDirection();//transform * float4(pt, 0) + float3(transform[3][0], transform[3][1], transform[3][2]); + float3 normal = normalize(alpha * A.normal + beta * B.normal + gamma * C.normal); + float3 worldNormal = normalize(cross(B.pt - A.pt, C.pt - A.pt)); + + float2 texcoord = alpha * A.coordinate + beta * B.coordinate + gamma * C.coordinate; + + hitValue.intersection = float4(worldPt.xyz, objectType); + hitValue.normal = float4(worldNormal.xyz, RayTCurrent()); + if (render_mode == RENDER_GLOBAL_XYZ) { // global xyz + hitValue.color = float4(heatmap(worldPt.x, -10, 10), 1); + return; + } + if ((objectType == 0 || objectType == 2)){ + if (imageOffset >= 26){ + return; // this shouldn't happen + } + // obtain texture coordinate + // NB: texture() is valid here as well as mipmaps are not used in this demo. + float4 tex_value = samplers[NonUniformResourceIndex(imageOffset)].SampleLevel(texcoord, 0); + hitValue.color = tex_value; + } else { + // the refraction itself is colorless, so + // encode the index of refraction in the color + const float base_IOR = 1.01; + const float x = texcoord.x, y = texcoord.y; + const float t = min(min(min(min(x, 1-x), y), 1-y), 0.5) / 0.5; + const float IOR = t * base_IOR + (1 - t) * 1; + hitValue.color = float4(IOR, 0, 0, 0); + hitValue.normal = float4(normal.x, normal.y, normal.z, RayTCurrent()); + } +} + +[shader("closesthit")] +void main(inout Payload hitValue, in Attributes attribs) +{ + const float3 barycentricCoords = float3(1.0f - attribs.bary.x - attribs.bary.y, attribs.bary.x, attribs.bary.y); + if (render_mode == RENDER_BARYCENTRIC ){ + hitValue.color = float4(barycentricCoords, 1); + } else if (render_mode == RENDER_INSTANCE_ID){ + hitValue.color = float4(heatmap(InstanceID(), 0, 25), 1); + } else if (render_mode == RENDER_DISTANCE){ + hitValue.color = float4(heatmap(log(1 + RayTCurrent()), 0, log(1 + 25)), 1); + } else { + handleDraw(hitValue, attribs.bary); + } +} diff --git a/shaders/ray_tracing_extended/slang/closesthit.rchit.spv b/shaders/ray_tracing_extended/slang/closesthit.rchit.spv new file mode 100644 index 0000000000..db3e2ad290 Binary files /dev/null and b/shaders/ray_tracing_extended/slang/closesthit.rchit.spv differ diff --git a/shaders/ray_tracing_extended/slang/miss.rmiss.slang b/shaders/ray_tracing_extended/slang/miss.rmiss.slang new file mode 100644 index 0000000000..026c3fcf95 --- /dev/null +++ b/shaders/ray_tracing_extended/slang/miss.rmiss.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Payload +{ + float4 color; + float4 intersection; // {x, y, z, intersectionType} + float4 normal; // {nx, ny, nz, distance} +}; + +[shader("miss")] +void main(inout Payload hitValue) +{ + hitValue.intersection.w = 100.0; + hitValue.normal.w = 10000.0; +} \ No newline at end of file diff --git a/shaders/ray_tracing_extended/slang/miss.rmiss.spv b/shaders/ray_tracing_extended/slang/miss.rmiss.spv new file mode 100644 index 0000000000..e4bfe75356 Binary files /dev/null and b/shaders/ray_tracing_extended/slang/miss.rmiss.spv differ diff --git a/shaders/ray_tracing_extended/slang/raygen.rgen.slang b/shaders/ray_tracing_extended/slang/raygen.rgen.slang new file mode 100644 index 0000000000..4cfac503eb --- /dev/null +++ b/shaders/ray_tracing_extended/slang/raygen.rgen.slang @@ -0,0 +1,185 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define RENDER_DEFAULT 0 +#define RENDER_BARYCENTRIC 1 +#define RENDER_INSTANCE_ID 2 +#define RENDER_DISTANCE 3 +#define RENDER_GLOBAL_XYZ 4 +#define RENDER_SHADOW_MAP 5 +#define RENDER_AO 6 + +RaytracingAccelerationStructure accelStruct; +RWTexture2D image; + +struct CameraProperties +{ + float4x4 viewInverse; + float4x4 projInverse; +}; +ConstantBuffer cam; + +struct Payload +{ + float4 color; + float4 intersection; // {x, y, z, intersectionType} + float4 normal; // {nx, ny, nz, distance} +}; + +[[SpecializationConstant]] const int render_mode = 0; +[[SpecializationConstant]] const int maxRays = 12; + +[shader("raygeneration")] +void main() +{ + uint3 LaunchID = DispatchRaysIndex(); + uint3 LaunchSize = DispatchRaysDimensions(); + + const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5); + const float2 inUV = pixelCenter/float2(LaunchSize.xy); + float2 d = inUV * 2.0 - 1.0; + + float4 origin = mul(cam.viewInverse, float4(0,0,0,1)); + float4 target = mul(cam.projInverse, float4(d.x, d.y, 1, 1)); + float4 direction = mul(cam.viewInverse, float4(normalize(target.xyz), 0)); + + float tmin = 0.001; + float tmax = 10000.0; + + uint max_rays = maxRays; + if (render_mode != RENDER_DEFAULT) + { + max_rays = 1; + } + + uint object_type = 100; + float4 color = float4(0, 0, 0, 0); + // 0 = normal, 1 = shadow, 2 = AO + uint current_mode = 0; + float expectedDistance = -1; + + RayDesc rayDesc; + rayDesc.TMin = tmin; + rayDesc.TMax = tmax; + + Payload hitValue; + + for (uint i = 0; i < max_rays && current_mode < 100 && color.a < 0.95 && (color.r < 0.99 || color.b < 0.99 || color.g < 0.99); ++i) + { + rayDesc.Origin = origin.xyz; + rayDesc.Direction = direction.xyz; + TraceRay(accelStruct, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, hitValue); + object_type = uint(hitValue.intersection.w); + const float3 object_intersection_pt = hitValue.intersection.xyz; + const float3 object_normal = hitValue.normal.xyz; + if (render_mode != RENDER_DEFAULT) + { + color = hitValue.color; + break; + } + if (object_type == 0) + { + float4 newColor = hitValue.color; + + //shadow + { + const float shadow_mult = 2; + const float shadow_scale = 0.25; + float3 lightPt = float3(0, -20, 0); + float3 currentDirection = lightPt - hitValue.intersection.xyz; + expectedDistance = sqrt(dot(currentDirection, currentDirection)); + currentDirection = normalize(currentDirection); + rayDesc.Origin = object_intersection_pt; + rayDesc.Direction = currentDirection; + TraceRay(accelStruct, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, hitValue); + float r = expectedDistance; + float actDistance = hitValue.normal.w; + float scale = actDistance < expectedDistance ? shadow_scale : 1; + scale = min(scale * shadow_mult, 1); + newColor.xyz *= scale; + current_mode = 101; + if (render_mode == RENDER_SHADOW_MAP) + { + color = float4(scale, scale, scale, 1); + break; + } + } + + // ambient occlusion + { + const float ao_mult = 1; + uint max_ao_each = 2; + uint max_ao = max_ao_each * max_ao_each; + const float max_dist = 2; + float accumulated_ao = 0.f; + float3 u = abs(dot(object_normal, float3(0, 0, 1))) > 0.9 ? cross(object_normal, float3(1, 0, 0)) : cross(object_normal, float3(0, 0, 1)); + float3 v = cross(object_normal, u); + float accumulated_factor = 0; + for (uint j = 0; j < max_ao_each; ++j) + { + float phi = 0.5*(-3.14159 + 2 * 3.14159 * (float(j + 1) / float(max_ao_each + 2))); + for (uint k = 0; k < max_ao_each; ++k){ + float theta = 0.5*(-3.14159 + 2 * 3.14159 * (float(k + 1) / float(max_ao_each + 2))); + float x = cos(phi) * sin(theta); + float y = sin(phi) * sin(theta); + float z = cos(theta); + float3 direction = x * u + y * v + z * object_normal; + rayDesc.Origin = object_intersection_pt; + rayDesc.Direction = direction; + TraceRay(accelStruct, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, hitValue); + float ao = min(hitValue.normal.w, max_dist); + float factor = 0.2 + 0.8 * z * z; + accumulated_factor += factor; + accumulated_ao += ao * factor; + } + } + accumulated_ao /= (max_dist * accumulated_factor); + accumulated_ao *= accumulated_ao; + accumulated_ao = max(min((accumulated_ao) * ao_mult, 1), 0); + if (render_mode == RENDER_AO) + { + color = float4(accumulated_ao, accumulated_ao, accumulated_ao, 1); + break; + } + + newColor.xyz *= accumulated_ao; + + const float r = max(0, 1 - color.a); + color += r * float4(newColor.rgb, 1); + } + + } else if (object_type == 1) + { + origin = float4(hitValue.intersection.xyz, 0); + const float IOR = hitValue.color.x; + const float max_IOR = 1.01; + float eta = 1 / IOR; + float c = abs(dot(object_normal, direction.xyz)); + float t = (IOR - 1) / (max_IOR - 1); + direction = normalize((1 - t) * direction + t * (eta * direction + (eta * c - (1 - eta*eta*(1 - c*c))))); + } else if (object_type == 2) + { + float4 newColor = hitValue.color; + float r = 1 - color.a; + color.rgb += r * newColor.rgb * newColor.a; + color.a += 0.1 * r * newColor.a; + origin = float4(hitValue.intersection.xyz, 0); + } + } + + image[int2(LaunchID.xy)] = color; +} \ No newline at end of file diff --git a/shaders/ray_tracing_extended/slang/raygen.rgen.spv b/shaders/ray_tracing_extended/slang/raygen.rgen.spv new file mode 100644 index 0000000000..16a44a134f Binary files /dev/null and b/shaders/ray_tracing_extended/slang/raygen.rgen.spv differ diff --git a/shaders/ray_tracing_position_fetch/slang/closesthit.rchit.slang b/shaders/ray_tracing_position_fetch/slang/closesthit.rchit.slang new file mode 100644 index 0000000000..11ddf7f984 --- /dev/null +++ b/shaders/ray_tracing_position_fetch/slang/closesthit.rchit.slang @@ -0,0 +1,65 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Attributes +{ + float2 bary; +}; + +struct Payload +{ + float3 hitValue; +}; + +struct UBO +{ + float4x4 viewInverse; + float4x4 projInverse; + int displayMode; +}; +[[vk::binding(2,0)]] ConstantBuffer ubo; + +[shader("closesthit")] +void main(inout Payload p, in Attributes attribs) +{ + // We need the barycentric coordinates to calculate data for the current position + const float3 barycentricCoords = float3(1.0f - attribs.bary.x - attribs.bary.y, attribs.bary.x, attribs.bary.y); + + // With VK_KHR_ray_tracing_position_fetch we can access the vertices for the hit triangle in the shader + float3 pos0 = HitTriangleVertexPosition(0); + float3 pos1 = HitTriangleVertexPosition(1); + float3 pos2 = HitTriangleVertexPosition(2); + float3 currentPos = pos0 * barycentricCoords.x + pos1 * barycentricCoords.y + pos2 * barycentricCoords.z; + + p.hitValue = float3(0.0, 0.0, 0.0); + + switch (ubo.displayMode) + { + case (0):{ + // Visualize the geometric normal + float3 normal = normalize(cross(pos1 - pos0, pos2 - pos0)); + normal = normalize(mul(float4(normal, 1.0), WorldToObject4x3())); + p.hitValue = normal; + break; + } + case (1):{ + // Visualize the vertex position + p.hitValue = currentPos; + break; + } + } +} \ No newline at end of file diff --git a/shaders/ray_tracing_position_fetch/slang/closesthit.rchit.spv b/shaders/ray_tracing_position_fetch/slang/closesthit.rchit.spv new file mode 100644 index 0000000000..1604e06fea Binary files /dev/null and b/shaders/ray_tracing_position_fetch/slang/closesthit.rchit.spv differ diff --git a/shaders/ray_tracing_position_fetch/slang/miss.rmiss.slang b/shaders/ray_tracing_position_fetch/slang/miss.rmiss.slang new file mode 100644 index 0000000000..b5c5e3b871 --- /dev/null +++ b/shaders/ray_tracing_position_fetch/slang/miss.rmiss.slang @@ -0,0 +1,27 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Payload +{ + float3 hitValue; +}; + +[shader("miss")] +void main(inout Payload p) +{ + p.hitValue = float3(0.0, 0.0, 0.2); +} \ No newline at end of file diff --git a/shaders/ray_tracing_position_fetch/slang/miss.rmiss.spv b/shaders/ray_tracing_position_fetch/slang/miss.rmiss.spv new file mode 100644 index 0000000000..3f89fc305a Binary files /dev/null and b/shaders/ray_tracing_position_fetch/slang/miss.rmiss.spv differ diff --git a/shaders/ray_tracing_position_fetch/slang/raygen.rgen.slang b/shaders/ray_tracing_position_fetch/slang/raygen.rgen.slang new file mode 100644 index 0000000000..f0718e9c32 --- /dev/null +++ b/shaders/ray_tracing_position_fetch/slang/raygen.rgen.slang @@ -0,0 +1,54 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +RaytracingAccelerationStructure accelStruct; +RWTexture2D image; + +struct CameraProperties +{ + float4x4 viewInverse; + float4x4 projInverse; +}; +ConstantBuffer cam; + +struct Payload +{ + float3 hitValue; +}; + +[shader("raygeneration")] +void main() +{ + uint3 LaunchID = DispatchRaysIndex(); + uint3 LaunchSize = DispatchRaysDimensions(); + + const float2 pixelCenter = float2(LaunchID.xy) + float2(0.5, 0.5); + const float2 inUV = pixelCenter/float2(LaunchSize.xy); + float2 d = inUV * 2.0 - 1.0; + float4 target = mul(cam.projInverse, float4(d.x, d.y, 1, 1)); + + RayDesc rayDesc; + rayDesc.Origin = mul(cam.viewInverse, float4(0,0,0,1)).xyz; + rayDesc.Direction = mul(cam.viewInverse, float4(normalize(target.xyz), 0)).xyz; + rayDesc.TMin = 0.001; + rayDesc.TMax = 10000.0; + + Payload payload = {}; + TraceRay(accelStruct, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload); + + image[int2(LaunchID.xy)] = float4(payload.hitValue, 0.0); +} diff --git a/shaders/ray_tracing_position_fetch/slang/raygen.rgen.spv b/shaders/ray_tracing_position_fetch/slang/raygen.rgen.spv new file mode 100644 index 0000000000..477ae44ffe Binary files /dev/null and b/shaders/ray_tracing_position_fetch/slang/raygen.rgen.spv differ diff --git a/shaders/separate_image_sampler/slang/separate_image_sampler.frag.slang b/shaders/separate_image_sampler/slang/separate_image_sampler.frag.slang new file mode 100644 index 0000000000..0d93156c0a --- /dev/null +++ b/shaders/separate_image_sampler/slang/separate_image_sampler.frag.slang @@ -0,0 +1,32 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] Texture2D _texture; +[[vk::binding(0, 1)]] SamplerState _sampler; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + // Sample the texture by combining the sampled image and selected sampler + return _texture.Sample(_sampler, input.UV); +} \ No newline at end of file diff --git a/shaders/separate_image_sampler/slang/separate_image_sampler.frag.spv b/shaders/separate_image_sampler/slang/separate_image_sampler.frag.spv new file mode 100644 index 0000000000..460a065a20 Binary files /dev/null and b/shaders/separate_image_sampler/slang/separate_image_sampler.frag.spv differ diff --git a/shaders/separate_image_sampler/slang/separate_image_sampler.vert.slang b/shaders/separate_image_sampler/slang/separate_image_sampler.vert.slang new file mode 100644 index 0000000000..61dbe40744 --- /dev/null +++ b/shaders/separate_image_sampler/slang/separate_image_sampler.vert.slang @@ -0,0 +1,46 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; + float4 viewPos; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0))); + return output; +} diff --git a/shaders/separate_image_sampler/slang/separate_image_sampler.vert.spv b/shaders/separate_image_sampler/slang/separate_image_sampler.vert.spv new file mode 100644 index 0000000000..57f4e47837 Binary files /dev/null and b/shaders/separate_image_sampler/slang/separate_image_sampler.vert.spv differ diff --git a/shaders/shader_debugprintf/slang/scene.frag.slang b/shaders/shader_debugprintf/slang/scene.frag.slang new file mode 100644 index 0000000000..510978acbf --- /dev/null +++ b/shaders/shader_debugprintf/slang/scene.frag.slang @@ -0,0 +1,56 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +[[vk::binding(1, 0)]] Sampler2D samplerEnvMap; + +[shader("fragment")] +float4 main(VSOutput input, uniform float4 offset, uniform float4 color, uniform int object_type) +{ + float4 out_color; + + switch (object_type) { + case 0: // Skysphere + { + out_color = samplerEnvMap.Sample(float2(input.UV.x, 1.0 - input.UV.y)); + } + break; + + case 1: // Phong shaded objects + { + float3 ambient = color.rgb * (0.5).xxx; + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = max(dot(N, L), 0.0) * color.rgb; + float3 specular = (pow(max(dot(R, V), 0.0), 8.0)).xxx; + out_color = float4(ambient + diffuse + specular, 1.0); + } + break; + } + + return float4(out_color.rgb, 1.0); +} \ No newline at end of file diff --git a/shaders/shader_debugprintf/slang/scene.frag.spv b/shaders/shader_debugprintf/slang/scene.frag.spv new file mode 100644 index 0000000000..a5c82f6695 Binary files /dev/null and b/shaders/shader_debugprintf/slang/scene.frag.spv differ diff --git a/shaders/shader_debugprintf/slang/scene.vert.slang b/shaders/shader_debugprintf/slang/scene.vert.slang new file mode 100644 index 0000000000..d3b3d8aaef --- /dev/null +++ b/shaders/shader_debugprintf/slang/scene.vert.slang @@ -0,0 +1,73 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; + uint VertexIndex : SV_VertexID; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4x4 skybox_modelview; + float modelscale; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +[shader("vertex")] +VSOutput main(VSInput input, uniform float4 offset, uniform float4 color, uniform int object_type) +{ + VSOutput output; + float3 tmpPos; + + switch(object_type) { + case 0: // Skysphere + tmpPos = mul((float3x3) ubo.skybox_modelview, input.Pos); + output.Pos = mul(ubo.projection, float4(tmpPos, 1.0)); + break; + case 1: // Object + float3 localPos = input.Pos * ubo.modelscale + offset.xyz; + tmpPos = mul(ubo.modelview, float4(localPos, 1.0)).xyz; + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(localPos, 1.0))); + break; + } + output.UV = input.UV; + output.Normal = mul((float3x3) ubo.modelview, input.Normal); + float3 lightPos = mul((float3x3) ubo.modelview, float3(0.0, -10.0, -10.0)); + output.LightVec = lightPos - tmpPos; + output.ViewVec = -tmpPos; + + // Output the vertex position using debug printf + if (input.VertexIndex == 0) { + printf("Position = %v3f", output.Pos.xyz); + } + + return output; +} diff --git a/shaders/shader_debugprintf/slang/scene.vert.spv b/shaders/shader_debugprintf/slang/scene.vert.spv new file mode 100644 index 0000000000..2013524459 Binary files /dev/null and b/shaders/shader_debugprintf/slang/scene.vert.spv differ diff --git a/shaders/sparse_image/slang/sparse.frag.slang b/shaders/sparse_image/slang/sparse.frag.slang new file mode 100644 index 0000000000..9c481e0e10 --- /dev/null +++ b/shaders/sparse_image/slang/sparse.frag.slang @@ -0,0 +1,65 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + struct VSOutput + { + float4 Pos : SV_POSITION; + float2 UV; +}; + +[[vk::binding(1, 0)]] Sampler2D samplerColor; + +struct SettingsData +{ + bool color_highlight; + int minLOD; + int maxLOD; +}; +[[vk::binding(2, 0)]] ConstantBuffer settings; + +static float3 color_blend_table[5] = +{ + {1.00, 1.00, 1.00}, + {0.80, 0.60, 0.40}, + {0.60, 0.80, 0.60}, + {0.40, 0.60, 0.80}, + {0.20, 0.20, 0.20}, +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float4 color = float4(0.0, 0.0, 0.0, 1.0); + + int lod = settings.minLOD; + uint residencyCode; + + do + { + color = samplerColor.SampleLevel(input.UV, lod, 0, residencyCode); + lod += 1; + } while (!CheckAccessFullyMapped(residencyCode)); + + if (settings.color_highlight) + { + lod -= 1; + color.xyz = (color.xyz * color_blend_table[lod]); + } + + return color; +} \ No newline at end of file diff --git a/shaders/sparse_image/slang/sparse.frag.spv b/shaders/sparse_image/slang/sparse.frag.spv new file mode 100644 index 0000000000..d36c1ce1e9 Binary files /dev/null and b/shaders/sparse_image/slang/sparse.frag.spv differ diff --git a/shaders/sparse_image/slang/sparse.vert.slang b/shaders/sparse_image/slang/sparse.vert.slang new file mode 100644 index 0000000000..2b56155dd9 --- /dev/null +++ b/shaders/sparse_image/slang/sparse.vert.slang @@ -0,0 +1,45 @@ +/* Copyright (c) 2023-2025, Mobica Limited + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float2 Pos : POSITION0; + float2 UV; +}; + +struct MvpTransform +{ + float4x4 model; + float4x4 view; + float4x4 proj; +}; +ConstantBuffer mvp; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(mvp.proj, mul(mvp.view, mul(mvp.model, float4(input.Pos, 0.0, 1.0)))); + return output; +} \ No newline at end of file diff --git a/shaders/sparse_image/slang/sparse.vert.spv b/shaders/sparse_image/slang/sparse.vert.spv new file mode 100644 index 0000000000..333d64a5b6 Binary files /dev/null and b/shaders/sparse_image/slang/sparse.vert.spv differ diff --git a/shaders/synchronization_2/slang/particle.frag.slang b/shaders/synchronization_2/slang/particle.frag.slang new file mode 100644 index 0000000000..1069c0624c --- /dev/null +++ b/shaders/synchronization_2/slang/particle.frag.slang @@ -0,0 +1,33 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Sampler2D samplerColorMap; +Sampler2D samplerGradientRamp; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 PointCoord : SV_PointCoord; + float GradientPos; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float3 color = samplerGradientRamp.Sample(float2(input.GradientPos, 0.0)).rgb; + return float4(samplerColorMap.Sample(input.PointCoord).rgb * color, 1.0); +} \ No newline at end of file diff --git a/shaders/synchronization_2/slang/particle.frag.spv b/shaders/synchronization_2/slang/particle.frag.spv new file mode 100644 index 0000000000..de6ec18895 Binary files /dev/null and b/shaders/synchronization_2/slang/particle.frag.spv differ diff --git a/shaders/synchronization_2/slang/particle.vert.slang b/shaders/synchronization_2/slang/particle.vert.slang new file mode 100644 index 0000000000..50b324b25b --- /dev/null +++ b/shaders/synchronization_2/slang/particle.vert.slang @@ -0,0 +1,51 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float4 Pos : POSITION0; + float4 Vel; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float PointSize : SV_PointSize; + float GradientPos; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float2 screendim; +}; +[[vk::binding(2, 0)]] ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + const float spriteSize = 0.005 * input.Pos.w; // Point size influenced by mass (stored in input.Pos.w); + float4 eyePos = mul(ubo.modelview, float4(input.Pos.x, input.Pos.y, input.Pos.z, 1.0)); + // Use projection to make sure point sizes uniformly scale independent of current projection + float4 projectedCorner = mul(ubo.projection, float4(0.5 * spriteSize, 0.5 * spriteSize, eyePos.z, eyePos.w)); + output.PointSize = clamp(ubo.screendim.x * projectedCorner.x / projectedCorner.w, 1.0, 128.0); + output.Pos = mul(ubo.projection, eyePos); + output.GradientPos = input.Vel.w; + return output; +} \ No newline at end of file diff --git a/shaders/synchronization_2/slang/particle.vert.spv b/shaders/synchronization_2/slang/particle.vert.spv new file mode 100644 index 0000000000..b6ce6c3d8d Binary files /dev/null and b/shaders/synchronization_2/slang/particle.vert.spv differ diff --git a/shaders/synchronization_2/slang/particle_calculate.comp.slang b/shaders/synchronization_2/slang/particle_calculate.comp.slang new file mode 100644 index 0000000000..db54d7e39d --- /dev/null +++ b/shaders/synchronization_2/slang/particle_calculate.comp.slang @@ -0,0 +1,87 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Particle +{ + float4 pos; + float4 vel; +}; +RWStructuredBuffer particles; + +struct UBO +{ + float deltaT; + int particleCount; +}; +ConstantBuffer ubo; + +[[vk::constant_id(1)]] const int SHARED_DATA_SIZE = 1024; +[[vk::constant_id(2)]] const float GRAVITY = 0.002; +[[vk::constant_id(3)]] const float POWER = 0.75; +[[vk::constant_id(4)]] const float SOFTEN = 0.05; + +// Share data between computer shader invocations to speed up caluclations +groupshared float4 sharedData[SHARED_DATA_SIZE]; + +#define TIME_FACTOR 0.05 + +[shader("compute")] +[numthreads(256, 1, 1)] +void main(uint3 GlobalInvocationID : SV_DispatchThreadID, uint3 LocalInvocationID : SV_GroupThreadID) +{ + // Current SSBO index + uint index = GlobalInvocationID.x; + if (index >= ubo.particleCount) + return; + + float4 position = particles[index].pos; + float4 velocity = particles[index].vel; + float4 acceleration = float4(0, 0, 0, 0); + int3 workgroupSize = WorkgroupSize(); + + for (int i = 0; i < ubo.particleCount; i += SHARED_DATA_SIZE) + { + if (i + LocalInvocationID.x < ubo.particleCount) + { + sharedData[LocalInvocationID.x] = particles[i + LocalInvocationID.x].pos; + } + else + { + sharedData[LocalInvocationID.x] = float4(0, 0, 0, 0); + } + + GroupMemoryBarrierWithGroupSync(); + + for (int j = 0; j < workgroupSize.x; j++) + { + float4 other = sharedData[j]; + float3 len = other.xyz - position.xyz; + acceleration.xyz += GRAVITY * len * other.w / pow(dot(len, len) + SOFTEN, POWER); + } + + GroupMemoryBarrierWithGroupSync(); + } + + particles[index].vel.xyz += ubo.deltaT * TIME_FACTOR * acceleration.xyz; + + // Gradient texture position + particles[index].vel.w += 0.1 * TIME_FACTOR * ubo.deltaT; + if (particles[index].vel.w > 1.0) + { + particles[index].vel.w -= 1.0; + } +} \ No newline at end of file diff --git a/shaders/synchronization_2/slang/particle_calculate.comp.spv b/shaders/synchronization_2/slang/particle_calculate.comp.spv new file mode 100644 index 0000000000..1c0b7bfb94 Binary files /dev/null and b/shaders/synchronization_2/slang/particle_calculate.comp.spv differ diff --git a/shaders/synchronization_2/slang/particle_integrate.comp.slang b/shaders/synchronization_2/slang/particle_integrate.comp.slang new file mode 100644 index 0000000000..559a357dff --- /dev/null +++ b/shaders/synchronization_2/slang/particle_integrate.comp.slang @@ -0,0 +1,43 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct Particle +{ + float4 pos; + float4 vel; +}; +RWStructuredBuffer particles; + +struct UBO +{ + float deltaT; + int particleCount; +}; +ConstantBuffer ubo; + +#define TIME_FACTOR 0.05 + +[shader("compute")] +[numthreads(256, 1, 1)] +void main(uint3 GlobalInvocationID : SV_DispatchThreadID) +{ + int index = int(GlobalInvocationID.x); + float4 position = particles[index].pos; + float4 velocity = particles[index].vel; + position += ubo.deltaT * TIME_FACTOR * velocity; + particles[index].pos = position; +} \ No newline at end of file diff --git a/shaders/synchronization_2/slang/particle_integrate.comp.spv b/shaders/synchronization_2/slang/particle_integrate.comp.spv new file mode 100644 index 0000000000..325e3af7ae Binary files /dev/null and b/shaders/synchronization_2/slang/particle_integrate.comp.spv differ diff --git a/shaders/terrain_tessellation/slang/skysphere.frag.slang b/shaders/terrain_tessellation/slang/skysphere.frag.slang new file mode 100644 index 0000000000..dc61d4f605 --- /dev/null +++ b/shaders/terrain_tessellation/slang/skysphere.frag.slang @@ -0,0 +1,25 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] Sampler2D samplerColorMap; + +[shader("fragment")] +float4 main(float2 inUV) +{ + float4 color = samplerColorMap.Sample(inUV); + return float4(color.rgb, 1.0); +} diff --git a/shaders/terrain_tessellation/slang/skysphere.frag.spv b/shaders/terrain_tessellation/slang/skysphere.frag.spv new file mode 100644 index 0000000000..0f4614a050 Binary files /dev/null and b/shaders/terrain_tessellation/slang/skysphere.frag.spv differ diff --git a/shaders/terrain_tessellation/slang/skysphere.vert.slang b/shaders/terrain_tessellation/slang/skysphere.vert.slang new file mode 100644 index 0000000000..0317834ac0 --- /dev/null +++ b/shaders/terrain_tessellation/slang/skysphere.vert.slang @@ -0,0 +1,45 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +struct UBO +{ + float4x4 mvp; +}; +ConstantBuffer ubo; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Pos = mul(ubo.mvp, float4(input.Pos, 1.0)); + output.UV = input.UV; + output.UV.y = 1.0 - output.UV.y; + return output; +} diff --git a/shaders/terrain_tessellation/slang/skysphere.vert.spv b/shaders/terrain_tessellation/slang/skysphere.vert.spv new file mode 100644 index 0000000000..67e4cc8db0 Binary files /dev/null and b/shaders/terrain_tessellation/slang/skysphere.vert.spv differ diff --git a/shaders/terrain_tessellation/slang/terrain.frag.slang b/shaders/terrain_tessellation/slang/terrain.frag.slang new file mode 100644 index 0000000000..e67fb67458 --- /dev/null +++ b/shaders/terrain_tessellation/slang/terrain.frag.slang @@ -0,0 +1,79 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] Sampler2D samplerHeight; +[[vk::binding(2, 0)]] Sampler2DArray samplerLayers; + +struct DSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; + float3 ViewVec; + float3 LightVec; + float3 EyePos; + float3 WorldPos; +}; + +float3 sampleTerrainLayer(float2 inUV) +{ + // Define some layer ranges for sampling depending on terrain height + float2 layers[6]; + layers[0] = float2(-10.0, 10.0); + layers[1] = float2(5.0, 45.0); + layers[2] = float2(45.0, 80.0); + layers[3] = float2(75.0, 100.0); + layers[4] = float2(95.0, 150.0); + layers[5] = float2(140.0, 290.0); + + float3 color = float3(0.0, 0.0, 0.0); + + // Get height from displacement map + float height = samplerHeight.SampleLevel(inUV, 0.0).r * 255.0; + + for (int i = 0; i < 6; i++) + { + float range = layers[i].y - layers[i].x; + float weight = (range - abs(height - layers[i].y)) / range; + weight = max(0.0, weight); + color += weight * samplerLayers.Sample(float3(inUV * 16.0, i)).rgb; + } + + return color; +} + +float fog(float density, float4 FragCoord) +{ + const float LOG2 = -1.442695; + float dist = FragCoord.z / FragCoord.w * 0.1; + float d = density * dist; + return 1.0 - clamp(exp2(d * d * LOG2), 0.0, 1.0); +} + +[shader("fragment")] +float4 main(DSOutput input) +{ + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 ambient = float3(0.5, 0.5, 0.5); + float3 diffuse = max(dot(N, L), 0.0) * float3(1.0, 1.0, 1.0); + + float4 color = float4((ambient + diffuse) * sampleTerrainLayer(input.UV), 1.0); + + const float4 fogColor = float4(0.47, 0.5, 0.67, 0.0); + return lerp(color, fogColor, fog(0.25, input.Pos)); +} diff --git a/shaders/terrain_tessellation/slang/terrain.frag.spv b/shaders/terrain_tessellation/slang/terrain.frag.spv new file mode 100644 index 0000000000..7ac894a2ef Binary files /dev/null and b/shaders/terrain_tessellation/slang/terrain.frag.spv differ diff --git a/shaders/terrain_tessellation/slang/terrain.tesc.slang b/shaders/terrain_tessellation/slang/terrain.tesc.slang new file mode 100644 index 0000000000..8c9a1c16f7 --- /dev/null +++ b/shaders/terrain_tessellation/slang/terrain.tesc.slang @@ -0,0 +1,156 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4 lightPos; + float4 frustumPlanes[6]; + float displacementFactor; + float tessellationFactor; + float2 viewportDim; + float tessellatedEdgeSize; +}; +ConstantBuffer ubo; + +Sampler2D samplerHeight; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; +}; + +struct HSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; +}; + +struct ConstantsHSOutput +{ + float TessLevelOuter[4] : SV_TessFactor; + float TessLevelInner[2] : SV_InsideTessFactor; +}; + +// Calculate the tessellation factor based on screen space +// dimensions of the edge +float screenSpaceTessFactor(float4 p0, float4 p1) +{ + // Calculate edge mid point + float4 midPoint = 0.5 * (p0 + p1); + // Sphere radius as distance between the control points + float radius = distance(p0, p1) / 2.0; + + // View space + float4 v0 = mul(ubo.modelview, midPoint); + + // Project into clip space + float4 clip0 = mul(ubo.projection, (v0 - float4(radius, float3(0.0, 0.0, 0.0)))); + float4 clip1 = mul(ubo.projection, (v0 + float4(radius, float3(0.0, 0.0, 0.0)))); + + // Get normalized device coordinates + clip0 /= clip0.w; + clip1 /= clip1.w; + + // Convert to viewport coordinates + clip0.xy *= ubo.viewportDim; + clip1.xy *= ubo.viewportDim; + + // Return the tessellation factor based on the screen size + // given by the distance of the two edge control points in screen space + // and a reference (min.) tessellation size for the edge set by the application + return clamp(distance(clip0, clip1) / ubo.tessellatedEdgeSize * ubo.tessellationFactor, 1.0, 64.0); +} + +// Checks the current's patch visibility against the frustum using a sphere check +// Sphere radius is given by the patch size +bool frustumCheck(float4 Pos, float2 inUV) +{ + // Fixed radius (increase if patch size is increased in example) + const float radius = 8.0f; + float4 pos = Pos; + pos.y -= samplerHeight.SampleLevel(inUV, 0.0).r * ubo.displacementFactor; + + // Check sphere against frustum planes + for (int i = 0; i < 6; i++) { + if (dot(pos, ubo.frustumPlanes[i]) + radius < 0.0) + { + return false; + } + } + return true; +} + +ConstantsHSOutput ConstantsHS(InputPatch patch) +{ + ConstantsHSOutput output; + + if (!frustumCheck(patch[0].Pos, patch[0].UV)) + { + output.TessLevelInner[0] = 0.0; + output.TessLevelInner[1] = 0.0; + output.TessLevelOuter[0] = 0.0; + output.TessLevelOuter[1] = 0.0; + output.TessLevelOuter[2] = 0.0; + output.TessLevelOuter[3] = 0.0; + } + else + { + if (ubo.tessellationFactor > 0.0) + { + output.TessLevelOuter[0] = screenSpaceTessFactor(patch[3].Pos, patch[0].Pos); + output.TessLevelOuter[1] = screenSpaceTessFactor(patch[0].Pos, patch[1].Pos); + output.TessLevelOuter[2] = screenSpaceTessFactor(patch[1].Pos, patch[2].Pos); + output.TessLevelOuter[3] = screenSpaceTessFactor(patch[2].Pos, patch[3].Pos); + output.TessLevelInner[0] = lerp(output.TessLevelOuter[0], output.TessLevelOuter[3], 0.5); + output.TessLevelInner[1] = lerp(output.TessLevelOuter[2], output.TessLevelOuter[1], 0.5); + } + else + { + // Tessellation factor can be set to zero by example + // to demonstrate a simple passthrough + output.TessLevelInner[0] = 1.0; + output.TessLevelInner[1] = 1.0; + output.TessLevelOuter[0] = 1.0; + output.TessLevelOuter[1] = 1.0; + output.TessLevelOuter[2] = 1.0; + output.TessLevelOuter[3] = 1.0; + } + } + + return output; +} + +[domain("quad")] +[partitioning("integer")] +[outputtopology("triangle_cw")] +[outputcontrolpoints(4)] +[patchconstantfunc("ConstantsHS")] +[maxtessfactor(20.0f)] +[shader("hull")] +HSOutput main(InputPatch patch, uint InvocationID : SV_OutputControlPointID) +{ + HSOutput output; + output.Pos = patch[InvocationID].Pos; + output.Normal = patch[InvocationID].Normal; + output.UV = patch[InvocationID].UV; + return output; +} diff --git a/shaders/terrain_tessellation/slang/terrain.tesc.spv b/shaders/terrain_tessellation/slang/terrain.tesc.spv new file mode 100644 index 0000000000..3962ddcc05 Binary files /dev/null and b/shaders/terrain_tessellation/slang/terrain.tesc.spv differ diff --git a/shaders/terrain_tessellation/slang/terrain.tese.slang b/shaders/terrain_tessellation/slang/terrain.tese.slang new file mode 100644 index 0000000000..c35d1d5987 --- /dev/null +++ b/shaders/terrain_tessellation/slang/terrain.tese.slang @@ -0,0 +1,86 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4 lightPos; + float4 frustumPlanes[6]; + float displacementFactor; + float tessellationFactor; + float2 viewportDim; + float tessellatedEdgeSize; +}; +ConstantBuffer ubo; + +Sampler2D displacementMapSampler; + +struct HSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; +}; + +struct ConstantsHSOutput +{ + float TessLevelOuter[4] : SV_TessFactor; + float TessLevelInner[2] : SV_InsideTessFactor; +}; + +struct DSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; + float3 ViewVec; + float3 LightVec; + float3 EyePos; + float3 WorldPos; +}; + +[domain("quad")] +[shader("domain")] +DSOutput main(ConstantsHSOutput input, float2 TessCoord : SV_DomainLocation, const OutputPatch patch) +{ + // Interpolate UV coordinates + DSOutput output; + float2 uv1 = lerp(patch[0].UV, patch[1].UV, TessCoord.x); + float2 uv2 = lerp(patch[3].UV, patch[2].UV, TessCoord.x); + output.UV = lerp(uv1, uv2, TessCoord.y); + + float3 n1 = lerp(patch[0].Normal, patch[1].Normal, TessCoord.x); + float3 n2 = lerp(patch[3].Normal, patch[2].Normal, TessCoord.x); + output.Normal = lerp(n1, n2, TessCoord.y); + + // Interpolate positions + float4 pos1 = lerp(patch[0].Pos, patch[1].Pos, TessCoord.x); + float4 pos2 = lerp(patch[3].Pos, patch[2].Pos, TessCoord.x); + float4 pos = lerp(pos1, pos2, TessCoord.y); + // Displace + pos.y -= displacementMapSampler.SampleLevel(output.UV, 0.0).r * ubo.displacementFactor; + // Perspective projection + output.Pos = mul(ubo.projection, mul(ubo.modelview, pos)); + + // Calculate vectors for lighting based on tessellated position + output.ViewVec = -pos.xyz; + output.LightVec = normalize(ubo.lightPos.xyz + output.ViewVec); + output.WorldPos = pos.xyz; + output.EyePos = mul(ubo.modelview, pos).xyz; + return output; +} \ No newline at end of file diff --git a/shaders/terrain_tessellation/slang/terrain.tese.spv b/shaders/terrain_tessellation/slang/terrain.tese.spv new file mode 100644 index 0000000000..35edf75f84 Binary files /dev/null and b/shaders/terrain_tessellation/slang/terrain.tese.spv differ diff --git a/shaders/terrain_tessellation/slang/terrain.vert.slang b/shaders/terrain_tessellation/slang/terrain.vert.slang new file mode 100644 index 0000000000..0a79a9f08c --- /dev/null +++ b/shaders/terrain_tessellation/slang/terrain.vert.slang @@ -0,0 +1,40 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; + float2 UV; +}; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 Normal; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.Pos = float4(input.Pos.xyz, 1.0); + output.UV = input.UV; + output.Normal = input.Normal; + return output; +} \ No newline at end of file diff --git a/shaders/terrain_tessellation/slang/terrain.vert.spv b/shaders/terrain_tessellation/slang/terrain.vert.spv new file mode 100644 index 0000000000..019baffd30 Binary files /dev/null and b/shaders/terrain_tessellation/slang/terrain.vert.spv differ diff --git a/shaders/texture_compression_basisu/slang/texture.frag.slang b/shaders/texture_compression_basisu/slang/texture.frag.slang new file mode 100644 index 0000000000..e83631d2a3 --- /dev/null +++ b/shaders/texture_compression_basisu/slang/texture.frag.slang @@ -0,0 +1,30 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] Sampler2D samplerColor; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + return samplerColor.Sample( input.UV); +} \ No newline at end of file diff --git a/shaders/texture_compression_basisu/slang/texture.frag.spv b/shaders/texture_compression_basisu/slang/texture.frag.spv new file mode 100644 index 0000000000..7a3e003c10 Binary files /dev/null and b/shaders/texture_compression_basisu/slang/texture.frag.spv differ diff --git a/shaders/texture_compression_basisu/slang/texture.vert.slang b/shaders/texture_compression_basisu/slang/texture.vert.slang new file mode 100644 index 0000000000..406f5d5bb2 --- /dev/null +++ b/shaders/texture_compression_basisu/slang/texture.vert.slang @@ -0,0 +1,44 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos.xyz, 1.0))); + return output; +} \ No newline at end of file diff --git a/shaders/texture_compression_basisu/slang/texture.vert.spv b/shaders/texture_compression_basisu/slang/texture.vert.spv new file mode 100644 index 0000000000..eb626139ce Binary files /dev/null and b/shaders/texture_compression_basisu/slang/texture.vert.spv differ diff --git a/shaders/texture_loading/slang/texture.frag.slang b/shaders/texture_loading/slang/texture.frag.slang new file mode 100644 index 0000000000..b1cf7750f4 --- /dev/null +++ b/shaders/texture_loading/slang/texture.frag.slang @@ -0,0 +1,41 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] Sampler2D samplerColor; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float LodBias; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float4 color = samplerColor.SampleBias(input.UV, input.LodBias); + float3 N = normalize(input.Normal); + float3 L = normalize(input.LightVec); + float3 V = normalize(input.ViewVec); + float3 R = reflect(-L, N); + float3 diffuse = max(dot(N, L), 0.0); + float3 specular = (pow(max(dot(R, V), 0.0), 16.0)) * color.a; + return float4(diffuse * color.rgb + specular, 1.0); +} \ No newline at end of file diff --git a/shaders/texture_loading/slang/texture.frag.spv b/shaders/texture_loading/slang/texture.frag.spv new file mode 100644 index 0000000000..55fdbcb2cc Binary files /dev/null and b/shaders/texture_loading/slang/texture.frag.spv differ diff --git a/shaders/texture_loading/slang/texture.vert.slang b/shaders/texture_loading/slang/texture.vert.slang new file mode 100644 index 0000000000..0437516015 --- /dev/null +++ b/shaders/texture_loading/slang/texture.vert.slang @@ -0,0 +1,57 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; + float3 Normal; +}; + +struct UBO +{ + float4x4 projection; + float4x4 model; + float4 viewPos; + float lodBias; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; + float LodBias; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + float3 vecPos = mul((float3x3) ubo.model, input.Pos); + float3 lightPos = mul((float3x3) ubo.model, (1.0).xxx); + output.UV = input.UV; + output.LodBias = ubo.lodBias; + output.Pos = mul(ubo.projection, mul(ubo.model, float4(input.Pos, 1.0))); + output.Normal = mul((float3x3) ubo.model, input.Normal); + output.LightVec = lightPos - vecPos; + output.ViewVec = ubo.viewPos.xyz - vecPos; + return output; +} \ No newline at end of file diff --git a/shaders/texture_loading/slang/texture.vert.spv b/shaders/texture_loading/slang/texture.vert.spv new file mode 100644 index 0000000000..eeb941dcd3 Binary files /dev/null and b/shaders/texture_loading/slang/texture.vert.spv differ diff --git a/shaders/texture_mipmap_generation/slang/texture.frag.slang b/shaders/texture_mipmap_generation/slang/texture.frag.slang new file mode 100644 index 0000000000..8cc99a5d62 --- /dev/null +++ b/shaders/texture_mipmap_generation/slang/texture.frag.slang @@ -0,0 +1,41 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct UBO +{ + float4x4 projection; + float4x4 model; + float lodBias; + int samplerIndex; +}; +ConstantBuffer ubo; + +Texture2D textureColor; +SamplerState samplers[3]; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("fragment")] +float4 main(VSOutput input) +{ + float3 color = textureColor.SampleBias(samplers[ubo.samplerIndex], input.UV * float2(2.0, 0.25), ubo.lodBias).rgb; + return float4(color, 1.0); +} \ No newline at end of file diff --git a/shaders/texture_mipmap_generation/slang/texture.frag.spv b/shaders/texture_mipmap_generation/slang/texture.frag.spv new file mode 100644 index 0000000000..473dc71c8c Binary files /dev/null and b/shaders/texture_mipmap_generation/slang/texture.frag.spv differ diff --git a/shaders/texture_mipmap_generation/slang/texture.vert.slang b/shaders/texture_mipmap_generation/slang/texture.vert.slang new file mode 100644 index 0000000000..dc52863116 --- /dev/null +++ b/shaders/texture_mipmap_generation/slang/texture.vert.slang @@ -0,0 +1,46 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float2 UV; +}; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float lodBias; + int samplerIndex; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float2 UV; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UV = input.UV; + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz, 1.0))); + return output; +} \ No newline at end of file diff --git a/shaders/texture_mipmap_generation/slang/texture.vert.spv b/shaders/texture_mipmap_generation/slang/texture.vert.spv new file mode 100644 index 0000000000..e3c95ef755 Binary files /dev/null and b/shaders/texture_mipmap_generation/slang/texture.vert.spv differ diff --git a/shaders/timeline_semaphore/game_of_life_init.comp b/shaders/timeline_semaphore/glsl/game_of_life_init.comp similarity index 96% rename from shaders/timeline_semaphore/game_of_life_init.comp rename to shaders/timeline_semaphore/glsl/game_of_life_init.comp index 1e0f680c79..1e4ac47a27 100644 --- a/shaders/timeline_semaphore/game_of_life_init.comp +++ b/shaders/timeline_semaphore/glsl/game_of_life_init.comp @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/timeline_semaphore/game_of_life_init.comp.spv b/shaders/timeline_semaphore/glsl/game_of_life_init.comp.spv similarity index 100% rename from shaders/timeline_semaphore/game_of_life_init.comp.spv rename to shaders/timeline_semaphore/glsl/game_of_life_init.comp.spv diff --git a/shaders/timeline_semaphore/game_of_life_mutate.comp b/shaders/timeline_semaphore/glsl/game_of_life_mutate.comp similarity index 95% rename from shaders/timeline_semaphore/game_of_life_mutate.comp rename to shaders/timeline_semaphore/glsl/game_of_life_mutate.comp index fe93757d2e..7d37c41ba3 100644 --- a/shaders/timeline_semaphore/game_of_life_mutate.comp +++ b/shaders/timeline_semaphore/glsl/game_of_life_mutate.comp @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/timeline_semaphore/game_of_life_mutate.comp.spv b/shaders/timeline_semaphore/glsl/game_of_life_mutate.comp.spv similarity index 100% rename from shaders/timeline_semaphore/game_of_life_mutate.comp.spv rename to shaders/timeline_semaphore/glsl/game_of_life_mutate.comp.spv diff --git a/shaders/timeline_semaphore/game_of_life_update.comp b/shaders/timeline_semaphore/glsl/game_of_life_update.comp similarity index 97% rename from shaders/timeline_semaphore/game_of_life_update.comp rename to shaders/timeline_semaphore/glsl/game_of_life_update.comp index e79d0fb42a..d4d69dd4d3 100644 --- a/shaders/timeline_semaphore/game_of_life_update.comp +++ b/shaders/timeline_semaphore/glsl/game_of_life_update.comp @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/timeline_semaphore/game_of_life_update.comp.spv b/shaders/timeline_semaphore/glsl/game_of_life_update.comp.spv similarity index 100% rename from shaders/timeline_semaphore/game_of_life_update.comp.spv rename to shaders/timeline_semaphore/glsl/game_of_life_update.comp.spv diff --git a/shaders/timeline_semaphore/render.frag b/shaders/timeline_semaphore/glsl/render.frag similarity index 94% rename from shaders/timeline_semaphore/render.frag rename to shaders/timeline_semaphore/glsl/render.frag index 881821a2ae..b5301adcf1 100644 --- a/shaders/timeline_semaphore/render.frag +++ b/shaders/timeline_semaphore/glsl/render.frag @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/timeline_semaphore/render.frag.spv b/shaders/timeline_semaphore/glsl/render.frag.spv similarity index 100% rename from shaders/timeline_semaphore/render.frag.spv rename to shaders/timeline_semaphore/glsl/render.frag.spv diff --git a/shaders/timeline_semaphore/render.vert b/shaders/timeline_semaphore/glsl/render.vert similarity index 94% rename from shaders/timeline_semaphore/render.vert rename to shaders/timeline_semaphore/glsl/render.vert index b07652f98d..3c47228dbf 100644 --- a/shaders/timeline_semaphore/render.vert +++ b/shaders/timeline_semaphore/glsl/render.vert @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Arm Limited and Contributors +/* Copyright (c) 2021-2025, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * diff --git a/shaders/timeline_semaphore/render.vert.spv b/shaders/timeline_semaphore/glsl/render.vert.spv similarity index 100% rename from shaders/timeline_semaphore/render.vert.spv rename to shaders/timeline_semaphore/glsl/render.vert.spv diff --git a/shaders/timeline_semaphore/slang/game_of_life_init.comp.slang b/shaders/timeline_semaphore/slang/game_of_life_init.comp.slang new file mode 100644 index 0000000000..b23655717b --- /dev/null +++ b/shaders/timeline_semaphore/slang/game_of_life_init.comp.slang @@ -0,0 +1,56 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::image_format("rgba8")]] RWTexture2D Image; + +// Slang/HLSL do not have GLSL's (not)equal functions +bool2 equal(int2 a, int2 b) { + return bool2(a.x == b.x, a.y == b.y); +} + +bool2 notEqual(int2 a, int2 b) { + return bool2(a.x != b.x, a.y != b.y); +} + +[shader("compute")] +[numthreads(8, 8, 1)] +void main(uint3 globalInvocationID: SV_DispatchThreadID) +{ + int2 index = globalInvocationID.xy; + bool is_alive; + + // Create an arbitrary pattern which happens to create a desirable result. + + int2 mask = lerp(int2(3), int2(7), notEqual(index & 16, int2(0))); + + int2 wrapped_index = index & mask; + if (all(equal(wrapped_index, int2(1, 0))) || + all(equal(wrapped_index, int2(2, 1))) || + all(equal(wrapped_index, int2(0, 2))) || + all(equal(wrapped_index, int2(1, 2))) || + all(equal(wrapped_index, int2(2, 2)))) + { + is_alive = true; + } + else + { + is_alive = false; + } + + Image[int2(globalInvocationID.xy)] = is_alive ? float4(1.0, 1.0, 1.0, 0.0) : float4(0.0); +} diff --git a/shaders/timeline_semaphore/slang/game_of_life_init.comp.spv b/shaders/timeline_semaphore/slang/game_of_life_init.comp.spv new file mode 100644 index 0000000000..31ff86916d Binary files /dev/null and b/shaders/timeline_semaphore/slang/game_of_life_init.comp.spv differ diff --git a/shaders/timeline_semaphore/slang/game_of_life_mutate.comp.slang b/shaders/timeline_semaphore/slang/game_of_life_mutate.comp.slang new file mode 100644 index 0000000000..03137e4a60 --- /dev/null +++ b/shaders/timeline_semaphore/slang/game_of_life_mutate.comp.slang @@ -0,0 +1,40 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::image_format("rgba8")]] RWTexture2D ImageOutput; +[[vk::binding(0, 1)]] Sampler2D ImageInput; + +// Slang/HLSL do not have GLSL's (not)equal functions +bool3 notEqual(float3 a, float3 b) { + return bool3(a.x != b.x, a.y != b.y, a.z != b.z); +} + +[shader("compute")] +[numthreads(8, 8, 1)] +void main(uint3 globalInvocationID: SV_DispatchThreadID, uniform float counter) +{ + float4 v = ImageInput.Load(int3(globalInvocationID.xy, 0)); + + // Increase intensity over time until the cell dies. + if (any(notEqual(v.rgb, float3(0.0)))) + v.w = max(v.w, counter); + else + v.w = 0.0; + + ImageOutput[globalInvocationID.xy] = v; +} diff --git a/shaders/timeline_semaphore/slang/game_of_life_mutate.comp.spv b/shaders/timeline_semaphore/slang/game_of_life_mutate.comp.spv new file mode 100644 index 0000000000..1995c350b4 Binary files /dev/null and b/shaders/timeline_semaphore/slang/game_of_life_mutate.comp.spv differ diff --git a/shaders/timeline_semaphore/slang/game_of_life_update.comp.slang b/shaders/timeline_semaphore/slang/game_of_life_update.comp.slang new file mode 100644 index 0000000000..1dbde10c66 --- /dev/null +++ b/shaders/timeline_semaphore/slang/game_of_life_update.comp.slang @@ -0,0 +1,86 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::image_format("rgba8")]] RWTexture2D ImageOutput; +[[vk::binding(0, 1)]] Sampler2D ImageInput; + +// Slang/HLSL do not have GLSL's (not)equal functions +bool3 notEqual(float3 a, float3 b) { + return bool3(a.x != b.x, a.y != b.y, a.z != b.z); +} + +[shader("compute")] +[numthreads(8, 8, 1)] +void main(uint3 globalInvocationID: SV_DispatchThreadID) +{ + float2 textureSize; + ImageInput.GetDimensions(textureSize.x, textureSize.y); + + int2 index = int2(globalInvocationID.xy); + float2 uv = (float2(index) + 0.5) / textureSize; + int neighbors = 0; + + float4 self = ImageInput.SampleLevel(uv, 0.0); + bool is_alive = any(notEqual(self.rgb, float3(0.0))); + float3 total = self.rgb; + +#define CHECK_OFFSET(x, y) { \ + float3 tmp; \ + tmp = ImageInput.SampleLevel(uv, 0.0, int2(x, y)).rgb; \ + if (any(notEqual(tmp, float3(0.0)))) { \ + neighbors++; \ + total += tmp.rgb; \ + } \ +} + CHECK_OFFSET(-1, -1) + CHECK_OFFSET( 0, -1) + CHECK_OFFSET(+1, -1) + CHECK_OFFSET(-1, 0) + CHECK_OFFSET(+1, 0) + CHECK_OFFSET(-1, +1) + CHECK_OFFSET( 0, +1) + CHECK_OFFSET(+1, +1) + + if (is_alive) + { + is_alive = neighbors == 2u || neighbors == 3u; + if (is_alive) + { + total /= float(neighbors); + } + else + { + total = float3(0.0); + } + } + else + { + is_alive = neighbors == 3u; + if (is_alive) + { + float3 fresh_color = float3(uv.x, uv.y, 1.0 - uv.x - uv.y); + total = fresh_color; + } + else + { + total = float3(0.0); + } + } + + ImageOutput[int2(globalInvocationID.xy)] = float4(total, 0.0); +} diff --git a/shaders/timeline_semaphore/slang/game_of_life_update.comp.spv b/shaders/timeline_semaphore/slang/game_of_life_update.comp.spv new file mode 100644 index 0000000000..8cbb92db68 Binary files /dev/null and b/shaders/timeline_semaphore/slang/game_of_life_update.comp.spv differ diff --git a/shaders/timeline_semaphore/slang/render.frag.slang b/shaders/timeline_semaphore/slang/render.frag.slang new file mode 100644 index 0000000000..0fd35caf21 --- /dev/null +++ b/shaders/timeline_semaphore/slang/render.frag.slang @@ -0,0 +1,37 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + float2 UV; +} + +Sampler2D in_image; + +float4 convert_color(float4 value) +{ + float gray = dot(value.rgb, float3(0.3, 0.6, 0.1)); + return float4(lerp(float3(gray), value.rgb, value.a), 1.0); +} + +[shader("fragment")] +float4 main(VSOutput input) +{ + return convert_color(in_image.SampleLevel(input.UV, 0.0)); +} diff --git a/shaders/timeline_semaphore/slang/render.frag.spv b/shaders/timeline_semaphore/slang/render.frag.spv new file mode 100644 index 0000000000..7089d35069 Binary files /dev/null and b/shaders/timeline_semaphore/slang/render.frag.spv differ diff --git a/shaders/timeline_semaphore/slang/render.vert.slang b/shaders/timeline_semaphore/slang/render.vert.slang new file mode 100644 index 0000000000..782e7a3860 --- /dev/null +++ b/shaders/timeline_semaphore/slang/render.vert.slang @@ -0,0 +1,37 @@ +/* Copyright (c) 2021-2025, Arm Limited and Contributors + * Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSOutput +{ + float4 Pos : SV_Position; + float2 UV; +} + +[shader("vertex")] +VSOutput main(uint vertexIndex: SV_VertexID) +{ + VSOutput output; + if (vertexIndex == 0) + output.Pos = float4(-1.0, -1.0, 0.0, 1.0); + else if (vertexIndex == 1) + output.Pos = float4(-1.0, 3.0, 0.0, 1.0); + else + output.Pos = float4(3.0, -1.0, 0.0, 1.0); + output.UV = output.Pos.xy * 0.5 + 0.5; + return output; +} diff --git a/shaders/timeline_semaphore/slang/render.vert.spv b/shaders/timeline_semaphore/slang/render.vert.spv new file mode 100644 index 0000000000..d094b4bcd6 Binary files /dev/null and b/shaders/timeline_semaphore/slang/render.vert.spv differ diff --git a/shaders/vertex_dynamic_state/slang/gbuffer.frag.slang b/shaders/vertex_dynamic_state/slang/gbuffer.frag.slang new file mode 100644 index 0000000000..71c0b240e1 --- /dev/null +++ b/shaders/vertex_dynamic_state/slang/gbuffer.frag.slang @@ -0,0 +1,113 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +[[vk::binding(1, 0)]] SamplerCube samplerEnvMap; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +struct FSOutput +{ + float4 Color0; +}; + +[[SpecializationConstant]] const int type = 0; + +struct UBOMatrices +{ + float4x4 projection; + float4x4 modelview; + float4x4 skyboxModelview; + float4x4 inverseModelView; + float modelscale; +}; +ConstantBuffer uboMatrices; + +[shader("fragment")] +FSOutput main(VSOutput input) +{ + FSOutput output; + float4 color; + float3 wcNormal; + + switch (type) + { + case 0: // Skybox + { + float3 normal = normalize(input.UVW); + color = samplerEnvMap.Sample(normal); + } + break; + + case 1: // Reflect + { + float3 wViewVec = mul((float3x3) uboMatrices.inverseModelView, normalize(input.ViewVec)); + float3 normal = normalize(input.Normal); + float3 wNormal = mul((float3x3) uboMatrices.inverseModelView, normal).xyz; + + float NdotL = max(dot(normal, input.LightVec), 0.0); + + float3 eyeDir = normalize(input.ViewVec); + float3 halfVec = normalize(input.LightVec + eyeDir); + float NdotH = max(dot(normal, halfVec), 0.0); + float NdotV = max(dot(normal, eyeDir), 0.0); + float VdotH = max(dot(eyeDir, halfVec), 0.0); + + // Geometric attenuation + float NH2 = 2.0 * NdotH; + float g1 = (NH2 * NdotV) / VdotH; + float g2 = (NH2 * NdotL) / VdotH; + float geoAtt = min(1.0, min(g1, g2)); + + const float F0 = 0.6; + const float k = 0.2; + + // Fresnel (schlick approximation) + float fresnel = pow(1.0 - VdotH, 5.0); + fresnel *= (1.0 - F0); + fresnel += F0; + + float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14); + + color = samplerEnvMap.Sample(reflect(-wViewVec, wNormal)); + + color = float4(color.rgb * NdotL * (k + spec * (1.0 - k)), 1.0); + } + break; + + case 2: // Refract + { + float3 wViewVec = mul((float3x3) uboMatrices.inverseModelView, normalize(input.ViewVec)); + float3 wNormal = mul((float3x3)uboMatrices.inverseModelView, input.Normal); + color = samplerEnvMap.Sample(refract(-wViewVec, wNormal, 1.0 / 1.6)); + } + break; + } + + + // Color with manual exposure into attachment 0 + const float exposure = 1.0; + output.Color0.rgb = float3(1.0, 1.0, 1.0) - exp(-color.rgb * exposure); + + return output; +} diff --git a/shaders/vertex_dynamic_state/slang/gbuffer.frag.spv b/shaders/vertex_dynamic_state/slang/gbuffer.frag.spv new file mode 100644 index 0000000000..51bfcd3bc5 Binary files /dev/null and b/shaders/vertex_dynamic_state/slang/gbuffer.frag.spv differ diff --git a/shaders/vertex_dynamic_state/slang/gbuffer.vert.slang b/shaders/vertex_dynamic_state/slang/gbuffer.vert.slang new file mode 100644 index 0000000000..30c8a9e03c --- /dev/null +++ b/shaders/vertex_dynamic_state/slang/gbuffer.vert.slang @@ -0,0 +1,69 @@ +/* Copyright (c) 2025, Sascha Willems + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 the "License"; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +struct VSInput +{ + float3 Pos : POSITION0; + float3 Normal; +}; + +[[SpecializationConstant]] const int type = 0; + +struct UBO +{ + float4x4 projection; + float4x4 modelview; + float4x4 skyboxModelview; + float4x4 inverseModelView; + float modelscale; +}; +ConstantBuffer ubo; + +struct VSOutput +{ + float4 Pos : SV_POSITION; + float3 UVW; + float3 Normal; + float3 ViewVec; + float3 LightVec; +}; + +[shader("vertex")] +VSOutput main(VSInput input) +{ + VSOutput output; + output.UVW = input.Pos; + float3 worldPos; + + switch (type) + { + case 0: // Skybox + worldPos = mul((float3x3) ubo.skyboxModelview, input.Pos); + output.Pos = mul(ubo.projection, float4(worldPos, 1.0)); + break; + case 1: // Object + worldPos = mul(ubo.modelview, float4(input.Pos * ubo.modelscale, 1.0)).xyz; + output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos * ubo.modelscale, 1.0))); + break; + } + output.Normal = mul((float3x3) ubo.modelview, input.Normal); + + float3 lightPos = float3(0.0f, -5.0f, 5.0f); + output.LightVec = lightPos - worldPos; + output.ViewVec = -worldPos; + return output; +} diff --git a/shaders/vertex_dynamic_state/slang/gbuffer.vert.spv b/shaders/vertex_dynamic_state/slang/gbuffer.vert.spv new file mode 100644 index 0000000000..946544f133 Binary files /dev/null and b/shaders/vertex_dynamic_state/slang/gbuffer.vert.spv differ