Skip to content

Commit 7908b22

Browse files
committed
Chapter 15 and 16
1 parent d196d10 commit 7908b22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2999
-298
lines changed

bookcontents/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

bookcontents/.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"cSpell.words": [
3+
"assimp",
4+
"bitangents",
5+
"calloc",
6+
"GLSL",
7+
"LWJGL",
8+
"malloc",
9+
"SPIR",
10+
"tinylog",
11+
"vulkanb"
12+
]
13+
}

bookcontents/chapter-14/chapter-14.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public class LightRender {
414414
TextureSampler sampler) {
415415
DescAllocator descAllocator = vkCtx.getDescAllocator();
416416
Device device = vkCtx.getDevice();
417-
DescSet descSet = descAllocator.addDescSets(device, DESC_ID_ATT, 1, descSetLayout)[0];
417+
DescSet descSet = descAllocator.addDescSet(device, DESC_ID_ATT, descSetLayout);
418418
List<ImageView> imageViews = new ArrayList<>();
419419
attachments.forEach(a -> imageViews.add(a.getImageView()));
420420
descSet.setImages(device, imageViews, sampler, 0);

bookcontents/chapter-15/chapter-15.md

Lines changed: 1044 additions & 1 deletion
Large diffs are not rendered by default.
624 KB
Loading
2.51 MB
Loading
3.91 MB
Loading

bookcontents/chapter-16/chapter-16.md

Lines changed: 1508 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 250 additions & 0 deletions
Loading
Loading
3.91 MB
Loading

bookcontents/vulkanbook.epub

12.7 MB
Binary file not shown.

booksamples/chapter-14/src/main/java/org/vulkanb/eng/graph/light/LightRender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static void createAttDescSet(VkCtx vkCtx, DescSetLayout descSetLayout, L
5959
TextureSampler sampler) {
6060
DescAllocator descAllocator = vkCtx.getDescAllocator();
6161
Device device = vkCtx.getDevice();
62-
DescSet descSet = descAllocator.addDescSets(device, DESC_ID_ATT, 1, descSetLayout)[0];
62+
DescSet descSet = descAllocator.addDescSet(device, DESC_ID_ATT, descSetLayout);
6363
List<ImageView> imageViews = new ArrayList<>();
6464
attachments.forEach(a -> imageViews.add(a.getImageView()));
6565
descSet.setImages(device, imageViews, sampler, 0);

booksamples/chapter-15/resources/shaders/light_frg.glsl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ layout(set = 0, binding = 1) uniform sampler2D albedoSampler;
2121
layout(set = 0, binding = 2) uniform sampler2D normalsSampler;
2222
layout(set = 0, binding = 3) uniform sampler2D pbrSampler;
2323

24-
layout(scalar, set = 1, binding = 0) uniform Lights {
25-
vec3 ambientLightColor;
26-
uint numLights;
27-
Light lights[MAX_LIGHTS];
24+
layout(scalar, set = 1, binding = 0) readonly buffer Lights {
25+
Light lights[];
2826
} lights;
29-
layout(set = 2, binding = 0) uniform SceneInfo {
27+
layout(scalar, set = 2, binding = 0) uniform SceneInfo {
3028
vec3 camPos;
29+
vec3 ambientLightColor;
30+
uint numLights;
3131
} sceneInfo;
3232

3333
float distributionGGX(float dotNH, float roughness)
@@ -95,7 +95,7 @@ void main() {
9595
F0 = mix(F0, albedo, metallic);
9696

9797
vec3 Lo = vec3(0.0);
98-
for (uint i = 0U; i < lights.numLights; i++) {
98+
for (uint i = 0U; i < sceneInfo.numLights; i++) {
9999
Light light = lights.lights[i];
100100
// calculate per-light radiance
101101
vec3 L;
@@ -113,7 +113,7 @@ void main() {
113113
Lo += BRDF(albedo, light.color.rgb * attenuation, L, V, N, metallic, roughness);
114114
}
115115

116-
vec3 ambient = lights.ambientLightColor.rgb * albedo;
116+
vec3 ambient = sceneInfo.ambientLightColor.rgb * albedo;
117117
vec3 color = ambient + Lo;
118118

119119
outFragColor = vec4(color, 1.0);
Binary file not shown.

booksamples/chapter-15/resources/shaders/scn_frg.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ struct Material {
2525
float roughnessFactor;
2626
float metallicFactor;
2727
};
28-
layout(set = 2, binding = 0) uniform sampler2D textSampler[MAX_TEXTURES];
29-
layout(set = 3, binding = 0) readonly buffer MaterialUniform {
28+
layout(set = 2, binding = 0) readonly buffer MaterialUniform {
3029
Material materials[];
3130
} matUniform;
31+
layout(set = 3, binding = 0) uniform sampler2D textSampler[MAX_TEXTURES];
3232

3333
vec3 calcNormal(Material material, vec3 normal, vec2 textCoords, mat3 TBN)
3434
{
Binary file not shown.

booksamples/chapter-15/src/main/java/org/vulkanb/Main.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@ public InitData init(EngCtx engCtx) {
5656

5757
scene.getAmbientLight().set(0.2f, 0.2f, 0.2f);
5858
List<Light> lights = new ArrayList<>();
59-
dirLight = new Light();
60-
dirLight.getPosition().set(0.0f, -1.0f, 0.0f, 0.0f);
61-
dirLight.getColor().set(1.0f, 1.0f, 1.0f, 1.0f);
59+
dirLight = new Light(new Vector4f(0.0f, -1.0f, 0.0f, 0.0f), new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
6260
lights.add(dirLight);
6361

64-
pointLight = new Light();
65-
pointLight.getPosition().set(5.0f, 3.4f, 0.9f, 1.0f);
66-
pointLight.getColor().set(0.0f, 1.0f, 0.0f, 1.0f);
62+
pointLight = new Light(new Vector4f(5.0f, 3.4f, 0.9f, 1.0f), new Vector4f(0.0f, 1.0f, 0.0f, 1.0f));
6763
lights.add(pointLight);
68-
Vector4f pointPos = pointLight.getPosition();
64+
Vector4f pointPos = pointLight.position();
6965
lightEntity.setPosition(pointPos.x, pointPos.y, pointPos.z);
7066
lightEntity.updateModelMatrix();
7167

@@ -114,14 +110,14 @@ public void input(EngCtx engCtx, long diffTimeMillis) {
114110

115111
move = move * 0.1f;
116112
if (ki.keyPressed(GLFW_KEY_1)) {
117-
pointLight.getPosition().y += move;
113+
pointLight.position().y += move;
118114
} else if (ki.keyPressed(GLFW_KEY_2)) {
119-
pointLight.getPosition().y -= move;
115+
pointLight.position().y -= move;
120116
}
121117
if (ki.keyPressed(GLFW_KEY_3)) {
122-
pointLight.getPosition().z -= move;
118+
pointLight.position().z -= move;
123119
} else if (ki.keyPressed(GLFW_KEY_4)) {
124-
pointLight.getPosition().z += move;
120+
pointLight.position().z += move;
125121
}
126122

127123
MouseInput mi = window.getMouseInput();
@@ -144,15 +140,15 @@ public void input(EngCtx engCtx, long diffTimeMillis) {
144140

145141
@Override
146142
public void update(EngCtx engCtx, long diffTimeMillis) {
147-
Vector4f pointPos = pointLight.getPosition();
143+
Vector4f pointPos = pointLight.position();
148144
lightEntity.setPosition(pointPos.x, pointPos.y, pointPos.z);
149145
lightEntity.updateModelMatrix();
150146
}
151147

152148
private void updateDirLight() {
153149
float zValue = (float) Math.cos(Math.toRadians(lightAngle));
154150
float yValue = (float) Math.sin(Math.toRadians(lightAngle));
155-
Vector4f lightDirection = dirLight.getPosition();
151+
Vector4f lightDirection = dirLight.position();
156152
lightDirection.x = 0;
157153
lightDirection.y = yValue;
158154
lightDirection.z = zValue;

0 commit comments

Comments
 (0)