Skip to content

Commit 9579d9b

Browse files
Chapter 38 Ray Tracing placeholder
1 parent 01ab96a commit 9579d9b

11 files changed

+175653
-2
lines changed

attachments/38_ray_tracing.cpp

Lines changed: 1200 additions & 0 deletions
Large diffs are not rendered by default.

attachments/38_ray_tracing.frag

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#version 450
2+
3+
layout(binding = 1) uniform sampler2D texSampler;
4+
5+
layout(location = 0) in vec3 fragColor;
6+
layout(location = 1) in vec2 fragTexCoord;
7+
8+
layout(location = 0) out vec4 outColor;
9+
10+
void main() {
11+
outColor = texture(texSampler, fragTexCoord);
12+
}

attachments/38_ray_tracing.slang

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
struct VSInput {
2+
float3 inPosition;
3+
float3 inColor;
4+
float2 inTexCoord;
5+
};
6+
7+
struct UniformBuffer {
8+
float4x4 model;
9+
float4x4 view;
10+
float4x4 proj;
11+
};
12+
ConstantBuffer<UniformBuffer> ubo;
13+
14+
struct VSOutput
15+
{
16+
float4 pos : SV_Position;
17+
float3 fragColor;
18+
float2 fragTexCoord;
19+
};
20+
21+
[shader("vertex")]
22+
VSOutput vertMain(VSInput input) {
23+
VSOutput output;
24+
output.pos = mul(ubo.proj, mul(ubo.view, mul(ubo.model, float4(input.inPosition, 1.0))));
25+
output.fragColor = input.inColor;
26+
output.fragTexCoord = input.inTexCoord;
27+
return output;
28+
}
29+
30+
Sampler2D texture;
31+
32+
[shader("fragment")]
33+
float4 fragMain(VSOutput vertIn) : SV_TARGET {
34+
return texture.Sample(vertIn.fragTexCoord);
35+
}

attachments/38_ray_tracing.vert

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#version 450
2+
3+
layout(binding = 0) uniform UniformBufferObject {
4+
mat4 model;
5+
mat4 view;
6+
mat4 proj;
7+
} ubo;
8+
9+
layout(location = 0) in vec3 inPosition;
10+
layout(location = 1) in vec3 inColor;
11+
layout(location = 2) in vec2 inTexCoord;
12+
13+
layout(location = 0) out vec3 fragColor;
14+
layout(location = 1) out vec2 fragTexCoord;
15+
16+
void main() {
17+
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
18+
fragColor = inColor;
19+
fragTexCoord = inTexCoord;
20+
}

attachments/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ function (add_chapter CHAPTER_NAME)
130130
target_link_libraries (${CHAPTER_NAME} ${CHAPTER_LIBS})
131131
endif ()
132132
if (DEFINED CHAPTER_MODELS)
133-
file (COPY assets/${CHAPTER_MODELS} DESTINATION ${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/models)
133+
list(TRANSFORM CHAPTER_MODELS PREPEND "${CMAKE_SOURCE_DIR}/assets/")
134+
file (COPY ${CHAPTER_MODELS} DESTINATION ${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/models)
134135
endif ()
135136
if (DEFINED CHAPTER_TEXTURES)
136-
file (COPY assets/${CHAPTER_TEXTURES} DESTINATION ${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/textures)
137+
list(TRANSFORM CHAPTER_TEXTURES PREPEND "${CMAKE_SOURCE_DIR}/assets/")
138+
file (COPY ${CHAPTER_TEXTURES} DESTINATION ${CMAKE_BINARY_DIR}/${CHAPTER_NAME}/textures)
137139
endif ()
138140
endfunction ()
139141

@@ -275,3 +277,13 @@ add_chapter (36_multiple_objects
275277
add_chapter (37_multithreading
276278
SHADER 37_shader_compute
277279
LIBS glm::glm)
280+
281+
add_chapter (38_ray_tracing
282+
SHADER 38_ray_tracing
283+
MODELS plant_on_table.obj
284+
MODELS plant_on_table.mtl
285+
TEXTURES plant_on_table_textures/nettle_plant_diff_4k.png
286+
TEXTURES plant_on_table_textures/potted_plant_02_pot_diff_1k.png
287+
TEXTURES plant_on_table_textures/wooden_picnic_table_bottom_diff_1k.png
288+
TEXTURES plant_on_table_textures/wooden_picnic_table_top_diff_1k.png
289+
LIBS glm::glm tinyobjloader::tinyobjloader)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Blender 4.0.2 MTL File: 'plant_on_table.blend'
2+
# www.blender.org
3+
4+
newmtl nettle_plant
5+
Ns 360.000000
6+
Ka 1.000000 1.000000 1.000000
7+
Kd 0.800000 0.800000 0.800000
8+
Ks 0.500000 0.500000 0.500000
9+
Ke 0.000000 0.000000 0.000000
10+
Ni 1.000000
11+
d 1.000000
12+
illum 2
13+
map_Kd ../textures/nettle_plant_diff_4k.png
14+
15+
newmtl nettle_plant.001
16+
Ns 360.000000
17+
Ka 1.000000 1.000000 1.000000
18+
Kd 0.800000 0.800000 0.800000
19+
Ks 0.500000 0.500000 0.500000
20+
Ke 0.000000 0.000000 0.000000
21+
Ni 1.000000
22+
d 1.000000
23+
illum 2
24+
map_Kd ../textures/nettle_plant_diff_4k.png
25+
26+
newmtl potted_plant_02_pot
27+
Ka 1.000000 1.000000 1.000000
28+
Ks 0.500000 0.500000 0.500000
29+
Ke 0.000000 0.000000 0.000000
30+
Ni 1.450000
31+
d 1.000000
32+
illum 2
33+
map_Kd ../textures/potted_plant_02_pot_diff_1k.png
34+
35+
newmtl wooden_picnic_table_bottom
36+
Ka 1.000000 1.000000 1.000000
37+
Ks 0.500000 0.500000 0.500000
38+
Ke 0.000000 0.000000 0.000000
39+
Ni 1.450000
40+
d 1.000000
41+
illum 2
42+
map_Kd ../textures/wooden_picnic_table_bottom_diff_1k.png
43+
map_Bump -bm 1.000000 ../textures/wooden_picnic_table_bottom_nor_gl_1k.png
44+
45+
newmtl wooden_picnic_table_table
46+
Ka 1.000000 1.000000 1.000000
47+
Ks 0.500000 0.500000 0.500000
48+
Ke 0.000000 0.000000 0.000000
49+
Ni 1.450000
50+
d 1.000000
51+
illum 2
52+
map_Kd ../textures/wooden_picnic_table_top_diff_1k.png

0 commit comments

Comments
 (0)