Skip to content

Commit 9626b6f

Browse files
committed
Updated up to chapter 17
1 parent c5af574 commit 9626b6f

36 files changed

+1647
-87
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This [online book](bookcontents/) will introduce the main concepts required to w
66

77
We will use [LWJGL](http://www.lwjgl.org/) as the Java library which provides the required bindings to use Vulkan and any other required APIs. This book is the result of my self learning language, that I think it may help the community.
88

9-
![Sample screen shot](./bookcontents/chapter-13/rc13-screen-shot.png)
9+
![Sample screen shot](./bookcontents/chapter-17/rc17-screen-shot.png)
1010

1111
> [!NOTE]
1212
> This is a new version which tries to use modern Vulkan features, such us:

bookcontents/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Table of Contents
2+
3+
The book is structured in the following chapters:
4+
5+
- [Chapter 00](chapter-00/chapter-00.md): Vulkan introduction and book pre-requisites.
6+
- [Chapter 01](chapter-01/chapter-01.md): Describes the basic scaffolding code to support rendering.
7+
- [Chapter 02](chapter-02/chapter-02.md): We start with the first Vulkan pieces of code that will create a Vulkan instance.
8+
- [Chapter 03](chapter-03/chapter-03.md): We continue with the definition of more basic Vulkan concepts such as the physical and Logical devices, surfaces and queues.
9+
- [Chapter 04](chapter-04/chapter-04.md): The key mechanism to present images to the screen is presented: the Swap chain.
10+
- [Chapter 05](chapter-05/chapter-05.md): In this chapter we will setup the basic structures for rendering (render information, command buffers and the synchronization mechanisms).
11+
- [Chapter 06](chapter-06/chapter-06.md): In this chapter we define the classes required to define the vertices, use the graphics pipeline and create shaders. We will draw our first shape to the screen (a triangle).
12+
- [Chapter 07](chapter-07/chapter-07.md): In this chapter we go 3D by implementing depth testing and add windows resizing support.
13+
- [Chapter 08](chapter-08/chapter-08.md): In this chapter we add support for loading complex 3D models using Assimp and textures.
14+
- [Chapter 09](chapter-09/chapter-09.md): We will automatically generate mipmaps, add support for transparent objects, add a camera to move around the scene and use dynamic uniform objects.
15+
- [Chapter 10](chapter-10/chapter-10.md): Vulkan Memory Allocator.
16+
- [Chapter 11](chapter-11/chapter-11.md): Post processing.
17+
- [Chapter 12](chapter-12/chapter-12.md): Render of GUI elements through ImGui.
18+
- [Chapter 13](chapter-13/chapter-13.md): Sound with OpenAL.
19+
- [Chapter 14](chapter-14/chapter-14.md): Deferred rendering (I).
20+
- [Chapter 15](chapter-15/chapter-15.md): Deferred rendering (II).
21+
- [Chapter 16](chapter-16/chapter-16.md): Cascade shadows.
22+
- [Chapter 17](chapter-17/chapter-17.md): Animations.
-76.3 KB
Loading
-63.1 KB
Loading
-51.3 KB
Loading
-60.2 KB
Loading
Loading
-75.8 KB
Loading

bookcontents/chapter-17/chapter-17.md

+1,605-1
Large diffs are not rendered by default.
3.67 MB
Loading

booksamples/chapter-17/resources/models/bob/boblamp.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
],
5353
"vtx_path": "resources/models/bob/boblamp.vtx",
5454
"idx_path": "resources/models/bob/boblamp.idx",
55-
"anim_mesh_data_list": [
55+
"anim_meshes": [
5656
{
5757
"weights": [
5858
1.0,
@@ -6810,7 +6810,7 @@
68106810
]
68116811
}
68126812
],
6813-
"animations_list": [
6813+
"animations": [
68146814
{
68156815
"name": "",
68166816
"frame_millis": 5.7916665,
Binary file not shown.
Binary file not shown.
Binary file not shown.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ layout (constant_id = 3) const int DEBUG_SHADOWS = 0;
1111
const float PI = 3.14159265359;
1212
const float SHADOW_FACTOR = 0.25;
1313

14-
// color cannot be vec3 due to std140 in GLSL
1514
struct Light {
1615
vec4 position;
1716
vec3 color;
@@ -151,7 +150,7 @@ void main() {
151150
vec3 pbr = texture(pbrSampler, inTextCoord).rgb;
152151

153152
float roughness = pbr.g;
154-
float metallic = pbr.b;
153+
float metallic = pbr.b;
155154

156155
vec3 N = normalize(normal);
157156
vec3 V = normalize(sceneInfo.camPos - worldPos);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

booksamples/chapter-17/resources/shaders/shadow_geom.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main()
2121
{
2222
for (int i = 0; i < 3; i++)
2323
{
24-
outTextCoords = inTextCoords[i];
24+
outTextCoords = inTextCoords[i];
2525
outMaterialIdx = inMaterialIdx[i];
2626
gl_Layer = gl_InvocationID;
2727
gl_Position = projUniforms.projViewMatrices[gl_InvocationID] * gl_in[i].gl_Position;
Binary file not shown.

booksamples/chapter-17/resources/shaders/shadow_vtx.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ void main()
2020
outMaterialIdx = push_constants.materialIdx;
2121

2222
gl_Position = push_constants.modelMatrix * vec4(entityPos, 1.0f);
23-
}
23+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public InitData init(EngCtx engCtx) {
4747

4848
ModelData bobModelData = ModelLoader.loadModel("resources/models/bob/boblamp.json");
4949
models.add(bobModelData);
50-
maxFrames = bobModelData.animationsList().get(0).frames().size();
50+
maxFrames = bobModelData.animations().get(0).frames().size();
5151
bobEntity = new Entity("BobEntity", bobModelData.id(), new Vector3f(0.0f, 0.0f, 0.0f));
5252
bobEntity.setScale(0.04f);
5353
bobEntity.getRotation().rotateY((float) Math.toRadians(-90.0f));
@@ -59,9 +59,6 @@ public InitData init(EngCtx engCtx) {
5959
materials.addAll(ModelLoader.loadMaterials("resources/models/sponza/Sponza_mat.json"));
6060
materials.addAll(ModelLoader.loadMaterials("resources/models/bob/boblamp_mat.json"));
6161

62-
List<Entity> animatedEntities = new ArrayList<>();
63-
animatedEntities.add(bobEntity);
64-
6562
scene.getAmbientLight().set(0.8f, 0.8f, 0.8f);
6663
List<Light> lights = new ArrayList<>();
6764
dirLight = new Light(new Vector4f(0.0f, -1.0f, 0.0f, 0.0f), new Vector4f(5.0f, 5.0f, 5.0f, 1.0f));

booksamples/chapter-17/src/main/java/org/vulkanb/eng/EngCfg.java

-20
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public class EngCfg {
1717
private boolean fxaa;
1818
private int maxDescs;
1919
private int maxJointsMatricesLists;
20-
private int maxMaterials;
21-
private int maxStorageBuffers;
2220
private String physDeviceName;
2321
private int requestedImages;
2422
private boolean shaderRecompilation;
@@ -50,13 +48,11 @@ private EngCfg() {
5048
zFar = Float.parseFloat(props.getOrDefault("zFar", 100.f).toString());
5149
maxDescs = Integer.parseInt(props.getOrDefault("maxDescs", 1000).toString());
5250
defaultTexturePath = props.getProperty("defaultTexturePath");
53-
maxMaterials = Integer.parseInt(props.getOrDefault("maxMaterials", 500).toString());
5451
fxaa = Boolean.parseBoolean(props.getOrDefault("fxaa", true).toString());
5552
shadowPcf = Boolean.parseBoolean(props.getOrDefault("shadowPcf", false).toString());
5653
shadowBias = Float.parseFloat(props.getOrDefault("shadowBias", 0.00005f).toString());
5754
shadowMapSize = Integer.parseInt(props.getOrDefault("shadowMapSize", 2048).toString());
5855
shadowDebug = Boolean.parseBoolean(props.getOrDefault("shadowDebug", false).toString());
59-
maxStorageBuffers = Integer.parseInt(props.getOrDefault("maxStorageBuffers", 100).toString());
6056
maxJointsMatricesLists = Integer.parseInt(props.getOrDefault("maxJointsMatricesLists", 100).toString());
6157
} catch (IOException excp) {
6258
Logger.error("Could not read [{}] properties file", FILENAME, excp);
@@ -86,14 +82,6 @@ public int getMaxJointsMatricesLists() {
8682
return maxJointsMatricesLists;
8783
}
8884

89-
public int getMaxMaterials() {
90-
return maxMaterials;
91-
}
92-
93-
public int getMaxStorageBuffers() {
94-
return maxStorageBuffers;
95-
}
96-
9785
public String getPhysDeviceName() {
9886
return physDeviceName;
9987
}
@@ -149,12 +137,4 @@ public boolean isShadowPcf() {
149137
public boolean isVkValidate() {
150138
return vkValidate;
151139
}
152-
153-
public void setMaxJointsMatricesLists(int maxJointsMatricesLists) {
154-
this.maxJointsMatricesLists = maxJointsMatricesLists;
155-
}
156-
157-
public void setMaxStorageBuffers(int maxStorageBuffers) {
158-
this.maxStorageBuffers = maxStorageBuffers;
159-
}
160140
}

booksamples/chapter-17/src/main/java/org/vulkanb/eng/graph/ModelsCache.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import org.joml.Matrix4f;
44
import org.lwjgl.system.MemoryUtil;
5-
import org.vulkanb.eng.graph.vk.Queue;
65
import org.vulkanb.eng.graph.vk.*;
6+
import org.vulkanb.eng.graph.vk.Queue;
77
import org.vulkanb.eng.model.*;
88

99
import java.io.*;
@@ -29,7 +29,7 @@ private static TransferBuffer createIndicesBuffers(VkCtx vkCtx, MeshData meshDat
2929
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
3030
var dstBuffer = new VkBuffer(vkCtx, bufferSize,
3131
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO,
32-
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, 0);
32+
0, 0);
3333

3434
long mappedMemory = srcBuffer.map(vkCtx);
3535
IntBuffer data = MemoryUtil.memIntBuffer(mappedMemory, (int) srcBuffer.getRequestedSize());
@@ -55,7 +55,7 @@ private static TransferBuffer createJointMatricesBuffers(VkCtx vkCtx, AnimatedFr
5555
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
5656
var dstBuffer = new VkBuffer(vkCtx, bufferSize,
5757
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO,
58-
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, 0);
58+
0, 0);
5959

6060
long mappedMemory = srcBuffer.map(vkCtx);
6161
ByteBuffer matrixBuffer = MemoryUtil.memByteBuffer(mappedMemory, (int) srcBuffer.getRequestedSize());
@@ -75,7 +75,7 @@ private static TransferBuffer createVerticesBuffers(VkCtx vkCtx, MeshData meshDa
7575
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
7676
var dstBuffer = new VkBuffer(vkCtx, bufferSize,
7777
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO,
78-
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, 0);
78+
0, 0);
7979

8080
long mappedMemory = srcBuffer.map(vkCtx);
8181
FloatBuffer data = MemoryUtil.memFloatBuffer(mappedMemory, (int) srcBuffer.getRequestedSize());
@@ -101,7 +101,7 @@ private static TransferBuffer createWeightsBuffers(VkCtx vkCtx, AnimMeshData ani
101101
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
102102
var dstBuffer = new VkBuffer(vkCtx, bufferSize,
103103
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
104-
VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, 0);
104+
VMA_MEMORY_USAGE_AUTO, 0, 0);
105105

106106
long mappedMemory = srcBuffer.map(vkCtx);
107107
FloatBuffer data = MemoryUtil.memFloatBuffer(mappedMemory, (int) srcBuffer.getRequestedSize());
@@ -148,7 +148,7 @@ public void loadModels(VkCtx vkCtx, List<ModelData> models, CmdPool cmdPool, Que
148148
VulkanModel vulkanModel = new VulkanModel(modelData.id());
149149
modelsMap.put(vulkanModel.getId(), vulkanModel);
150150

151-
List<Animation> animationsList = modelData.animationsList();
151+
List<Animation> animationsList = modelData.animations();
152152
boolean hasAnimation = animationsList != null && !animationsList.isEmpty();
153153
if (hasAnimation) {
154154
for (Animation animation : animationsList) {
@@ -178,7 +178,7 @@ public void loadModels(VkCtx vkCtx, List<ModelData> models, CmdPool cmdPool, Que
178178
indicesBuffers.recordTransferCommand(cmd);
179179

180180
TransferBuffer weightsBuffers = null;
181-
List<AnimMeshData> animMeshDataList = modelData.animMeshDataList();
181+
List<AnimMeshData> animMeshDataList = modelData.animMeshes();
182182
if (animMeshDataList != null && !animMeshDataList.isEmpty()) {
183183
weightsBuffers = createWeightsBuffers(vkCtx, animMeshDataList.get(meshCount));
184184
stagingBufferList.add(weightsBuffers.srcBuffer());

booksamples/chapter-17/src/main/java/org/vulkanb/eng/model/ModelData.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
import java.util.List;
44

5-
public record ModelData(String id, List<MeshData> meshes, String vtxPath, String idxPath,
6-
List<AnimMeshData> animMeshDataList, List<Animation> animationsList) {
5+
public record ModelData(String id, List<MeshData> meshes, String vtxPath, String idxPath, List<AnimMeshData> animMeshes,
6+
List<Animation> animations) {
77
}

booksamples/chapter-17/src/main/java/org/vulkanb/eng/model/ModelGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private void mainProcessing() throws IOException {
318318
throw new RuntimeException("Model path does not exist [" + modelPath + "]");
319319
}
320320

321-
AIScene aiScene = aiImportFile(modelPath, FLAGS | (animation ? 0 : aiProcess_PreTransformVertices));
321+
AIScene aiScene = aiImportFile(modelPath, FLAGS | (animation ? aiProcess_LimitBoneWeights : aiProcess_PreTransformVertices));
322322
if (aiScene == null) {
323323
throw new RuntimeException("Error loading model [modelPath: " + modelPath + "]");
324324
}
@@ -386,6 +386,7 @@ private void mainProcessing() throws IOException {
386386
Logger.info("Generated materials file [{}]", outMaterialFile);
387387

388388
modelBinData.close();
389+
aiReleaseImport(aiScene);
389390
Logger.info("Generated vtx file [{}]", modelBinData.getVtxFilePath());
390391
Logger.info("Generated idx file [{}]", modelBinData.getIdxFilePath());
391392
}

booksamples/chapter-17/src/main/java/org/vulkanb/eng/scene/Node.java

-43
This file was deleted.

booksamples/chapter-17/src/main/java/org/vulkanb/eng/scene/Scene.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public List<Entity> getEntities() {
4343
}
4444

4545
public Light[] getLights() {
46-
return this.lights;
46+
return lights;
4747
}
4848

4949
public Projection getProjection() {

booksamples/chapter-17/src/main/resources/eng.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
debugShaders=true
1+
debugShaders=false
22
defaultTexturePath=resources/models/default/default.png
33
fov=60
44
fxaa=true

0 commit comments

Comments
 (0)