Compare commits
6 Commits
aae54d1073
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c1c004d241 | |||
| 4efaebb813 | |||
| af0fc3fb54 | |||
| 8b5f4b51c2 | |||
| 1201f3d749 | |||
| 7fb01674b7 |
1267
28_model_loading.cpp
Normal file
1267
28_model_loading.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1383
29_mipmapping.cpp
Normal file
1383
29_mipmapping.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1428
30_multisampling.cpp
Normal file
1428
30_multisampling.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1185
31_compute_shader.cpp
Normal file
1185
31_compute_shader.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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})
|
||||
@@ -257,44 +257,44 @@ add_chapter (27_depth_buffering
|
||||
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 (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
|
||||
|
||||
BIN
assets/images/viking_room.png
Normal file
BIN
assets/images/viking_room.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 940 KiB |
16053
assets/models/viking_room.obj
Normal file
16053
assets/models/viking_room.obj
Normal file
File diff suppressed because it is too large
Load Diff
2
build
2
build
@@ -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
|
||||
|
||||
66
shaders/31_shader_compute.comp.slang
Normal file
66
shaders/31_shader_compute.comp.slang
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user