Compare commits

..

8 Commits

Author SHA1 Message Date
c1c004d241 Compute shaders 2025-12-22 19:44:00 +00:00
4efaebb813 Update multisampling 2025-12-22 15:04:50 +00:00
af0fc3fb54 Multisampling 2025-12-22 14:58:29 +00:00
8b5f4b51c2 Mipmapping 2025-12-22 06:04:43 +00:00
1201f3d749 Loading models 2025-12-22 05:06:54 +00:00
7fb01674b7 Switch to RelWithDebInfo build type 2025-12-22 05:06:47 +00:00
aae54d1073 Depth buffering 2025-12-22 03:28:25 +00:00
c909a10304 Rename transitionSwapChainImageLayout to transitionRenderingImageLayout 2025-12-22 03:05:57 +00:00
24 changed files with 22715 additions and 75 deletions

View File

@@ -393,7 +393,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -438,7 +438,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -451,7 +451,7 @@ class HelloTriangleApplication {
// Finish recording the command buffer
commandBuffer.end();
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -446,7 +446,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -491,7 +491,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -504,7 +504,7 @@ class HelloTriangleApplication {
// Finish recording the command buffer
commandBuffer.end();
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -456,7 +456,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -501,7 +501,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -514,7 +514,7 @@ class HelloTriangleApplication {
// Finish recording the command buffer
commandBuffer.end();
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -489,7 +489,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -534,7 +534,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -547,7 +547,7 @@ class HelloTriangleApplication {
// Finish recording the command buffer
commandBuffer.end();
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -534,7 +534,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -579,7 +579,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -592,7 +592,7 @@ class HelloTriangleApplication {
// Finish recording the command buffer
commandBuffer.end();
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -558,7 +558,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -604,7 +604,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -627,7 +627,7 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to find suitable memory type!");
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -562,7 +562,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -608,7 +608,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -676,7 +676,7 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to find suitable memory type!");
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -592,7 +592,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -639,7 +639,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -707,7 +707,7 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to find suitable memory type!");
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -648,7 +648,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -695,7 +695,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -763,7 +763,7 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to find suitable memory type!");
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -688,7 +688,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -738,7 +738,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -806,7 +806,7 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to find suitable memory type!");
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -759,7 +759,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -809,7 +809,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -917,7 +917,7 @@ class HelloTriangleApplication {
commandBuffer.pipelineBarrier(sourceStage, destinationStage, {}, {}, nullptr, barrier);
endSingleTimeCommands(commandBuffer);
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -791,7 +791,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -841,7 +841,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -949,7 +949,7 @@ class HelloTriangleApplication {
commandBuffer.pipelineBarrier(sourceStage, destinationStage, {}, {}, nullptr, barrier);
endSingleTimeCommands(commandBuffer);
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

View File

@@ -820,7 +820,7 @@ class HelloTriangleApplication {
commandBuffer.begin({});
// Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eColorAttachmentOptimal,
@@ -870,7 +870,7 @@ class HelloTriangleApplication {
commandBuffer.endRendering();
// After rendering, transition the swapchain image to PRESENT_SRC
transitionSwapChainImageLayout(
transitionRenderingImageLayout(
imageIndex,
vk::ImageLayout::eColorAttachmentOptimal,
vk::ImageLayout::ePresentSrcKHR,
@@ -978,7 +978,7 @@ class HelloTriangleApplication {
commandBuffer.pipelineBarrier(sourceStage, destinationStage, {}, {}, nullptr, barrier);
endSingleTimeCommands(commandBuffer);
}
void transitionSwapChainImageLayout(
void transitionRenderingImageLayout(
uint32_t imageIndex,
vk::ImageLayout oldLayout,
vk::ImageLayout newLayout,

1224
27_depth_buffering.cpp Normal file

File diff suppressed because it is too large Load Diff

1267
28_model_loading.cpp Normal file

File diff suppressed because it is too large Load Diff

1383
29_mipmapping.cpp Normal file

File diff suppressed because it is too large Load Diff

1428
30_multisampling.cpp Normal file

File diff suppressed because it is too large Load Diff

1185
31_compute_shader.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -106,7 +106,7 @@ endfunction ()
function (add_slang_shader_target TARGET)
cmake_parse_arguments ("SHADER" "" "CHAPTER_NAME" "SOURCES" ${ARGN})
set (SHADERS_DIR ${CHAPTER_NAME}/shaders)
file(GLOB HAS_COMPUTE shaders/${CHAPTER_SHADER}.comp)
file(GLOB HAS_COMPUTE shaders/${CHAPTER_SHADER}.comp.slang)
set (ENTRY_POINTS -entry vertMain -entry fragMain)
if(HAS_COMPUTE)
list(APPEND ENTRY_POINTS -entry compMain)
@@ -155,7 +155,7 @@ function (add_chapter CHAPTER_NAME)
endif()
set (CHAPTER_SHADER_SLANG_TARGET ${CHAPTER_NAME}_slang_shader)
file (GLOB SHADER_SLANG_SOURCES shaders/${CHAPTER_SHADER}.slang)
file (GLOB SHADER_SLANG_SOURCES shaders/${CHAPTER_SHADER}*.slang)
if(SHADER_SLANG_SOURCES)
add_slang_shader_target( ${CHAPTER_SHADER_SLANG_TARGET} CHAPTER_NAME ${CHAPTER_NAME} SOURCES ${SHADER_SLANG_SOURCES})
add_dependencies(${CHAPTER_NAME} ${CHAPTER_SHADER_SLANG_TARGET})
@@ -252,49 +252,49 @@ add_chapter (26_texture_mapping
TEXTURES images/texture.jpg
LIBS glm::glm)
# add_chapter (27_depth_buffering
# SHADER 27_shader_depth
# TEXTURES images/texture.jpg
# LIBS glm::glm)
#
# add_chapter (28_model_loading
# SHADER 27_shader_depth
# MODELS viking_room.obj
# TEXTURES viking_room.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
#
# add_chapter (29_mipmapping
# SHADER 27_shader_depth
# MODELS viking_room.obj
# TEXTURES viking_room.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
#
# add_chapter (30_multisampling
# SHADER 27_shader_depth
# MODELS viking_room.obj
# TEXTURES viking_room.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
#
# add_chapter (31_compute_shader
# SHADER 31_shader_compute
# LIBS glm::glm)
#
add_chapter (27_depth_buffering
SHADER 27_shader_depth
TEXTURES images/texture.jpg
LIBS glm::glm)
add_chapter (28_model_loading
SHADER 27_shader_depth
MODELS models/viking_room.obj
TEXTURES images/viking_room.png
LIBS glm::glm tinyobjloader::tinyobjloader)
add_chapter (29_mipmapping
SHADER 27_shader_depth
MODELS models/viking_room.obj
TEXTURES images/viking_room.png
LIBS glm::glm tinyobjloader::tinyobjloader)
add_chapter (30_multisampling
SHADER 27_shader_depth
MODELS models/viking_room.obj
TEXTURES images/viking_room.png
LIBS glm::glm tinyobjloader::tinyobjloader)
add_chapter (31_compute_shader
SHADER 31_shader_compute
LIBS glm::glm)
# add_chapter (32_ecosystem_utilities
# SHADER 27_shader_depth
# MODELS viking_room.obj
# TEXTURES viking_room.png
# MODELS models/viking_room.obj
# TEXTURES images/viking_room.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
#
# add_chapter (33_vulkan_profiles
# SHADER 27_shader_depth
# MODELS viking_room.obj
# TEXTURES viking_room.png
# MODELS models/viking_room.obj
# TEXTURES images/viking_room.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
#
# add_chapter (34_android
# SHADER 27_shader_depth
# MODELS viking_room.obj
# TEXTURES viking_room.png
# MODELS models/viking_room.obj
# TEXTURES images/viking_room.png
# LIBS glm::glm tinyobjloader::tinyobjloader)
#
# add_chapter (35_gltf_ktx

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 KiB

16053
assets/models/viking_room.obj Normal file

File diff suppressed because it is too large Load Diff

2
build
View File

@@ -2,5 +2,5 @@
CMAKE_BUILD_DIR=cmake-build
cmake -S . -B $CMAKE_BUILD_DIR -G Ninja
cmake -S . -B $CMAKE_BUILD_DIR -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build $CMAKE_BUILD_DIR

View File

@@ -0,0 +1,34 @@
struct VSInput {
float3 inPosition;
float3 inColor;
float2 inTexCoord;
};
struct UniformBuffer {
float4x4 model;
float4x4 view;
float4x4 proj;
};
ConstantBuffer<UniformBuffer> ubo;
struct VSOutput {
float4 pos : SV_Position;
float3 color;
float2 fragTexCoord;
};
[shader("vertex")]
VSOutput vertMain(VSInput input) {
VSOutput output;
output.color = input.inColor;
output.pos = mul(ubo.proj, mul(ubo.view, mul(ubo.model, float4(input.inPosition, 1.0))));
output.fragTexCoord = input.inTexCoord;
return output;
}
Sampler2D texture;
[shader("fragment")]
float4 fragMain(VSOutput vertIn) : SV_Target {
return texture.Sample(vertIn.fragTexCoord);
}

View File

@@ -0,0 +1,66 @@
struct VSInput {
float2 inPosition;
float3 inColor;
};
struct VSOutput {
float4 pos : SV_Position;
float pointSize : SV_PointSize;
float3 fragColor : COLOR0;
};
struct PSInput {
float4 pos : SV_Position;
float3 fragColor : COLOR0;
float2 pointCoord : SV_PointCoord;
};
[shader("vertex")]
VSOutput vertMain(VSInput input) {
VSOutput output;
output.pointSize = 14.0;
output.pos = float4(input.inPosition, 1.0, 1.0);
output.fragColor = input.inColor.rgb;
return output;
}
[shader("fragment")]
float4 fragMain(PSInput input) : SV_Target {
float2 coord = input.pointCoord - float2(0.5);
return float4(input.fragColor, 0.5 - length(coord));
}
struct Particle {
float2 position;
float2 velocity;
float4 color;
};
struct UniformBuffer {
float deltaTime;
};
ConstantBuffer<UniformBuffer> ubo;
struct ParticleSSBO {
Particle particles;
};
StructuredBuffer<ParticleSSBO> particlesIn;
RWStructuredBuffer<ParticleSSBO> particlesOut;
[shader("compute")]
[numthreads(256, 1, 1)]
void compMain(uint3 threadId : SV_DispatchThreadID) {
uint index = threadId.x;
particlesOut[index].particles.position = particlesIn[index].particles.position +
particlesIn[index].particles.velocity.xy * ubo.deltaTime;
particlesOut[index].particles.velocity = particlesIn[index].particles.velocity;
// Flip movement at window border
if ((particlesOut[index].particles.position.x <= -1.0) || (particlesOut[index].particles.position.x >= 1.0)) {
particlesOut[index].particles.velocity.x = -particlesOut[index].particles.velocity.x;
}
if ((particlesOut[index].particles.position.y <= -1.0) || (particlesOut[index].particles.position.y >= 1.0)) {
particlesOut[index].particles.velocity.y = -particlesOut[index].particles.velocity.y;
}
}