Skip to content

Commit c03adff

Browse files
committed
Split chapter 10 into two
Chapter 10 does not include PBR which has been pushed to chapter 11
1 parent 7e65479 commit c03adff

File tree

179 files changed

+15787
-669
lines changed

Some content is hidden

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

179 files changed

+15787
-669
lines changed

bookcontents/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ The book is structured in the following chapters:
1212
- [Chapter 07](chapter-07/chapter-07.md): In this chapter we go 3D by implementing depth testing and add windows resizing support.
1313
- [Chapter 08](chapter-08/chapter-08.md): In this chapter we add support for loading complex 3D models using Assimp and textures.
1414
- [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-09/chapter-10.md): Deferred rendering.
15+
- [Chapter 10](chapter-09/chapter-10.md): Deferred rendering (I).
16+
- [Chapter 10](chapter-09/chapter-11.md): Deferred rendering (II).

bookcontents/chapter-10/chapter-10.md

Lines changed: 1369 additions & 5 deletions
Large diffs are not rendered by default.
Lines changed: 254 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Deferred rendering (II)
2+
3+
Pending
Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
11
#version 450
22

3-
layout(location = 0) in vec3 inNormal;
4-
layout(location = 1) in vec3 inTangent;
5-
layout(location = 2) in vec3 inBitangent;
6-
layout(location = 3) in vec2 inTextCoords;
7-
3+
layout(location = 0) in vec2 textCoords;
84
layout(location = 0) out vec4 outAlbedo;
9-
layout(location = 1) out vec4 outNormal;
10-
layout(location = 2) out vec4 outPBR;
115

126
layout(set = 2, binding = 0) uniform sampler2D textSampler;
13-
layout(set = 3, binding = 0) uniform sampler2D normalSampler;
14-
layout(set = 4, binding = 0) uniform sampler2D metRoughSampler;
157

16-
layout(set = 5, binding = 0) uniform MaterialUniform {
8+
layout(set = 3, binding = 0) uniform MaterialUniform {
179
vec4 diffuseColor;
18-
float hasNormalMap;
19-
float hasMetalRoughMap;
20-
float roughnessFactor;
21-
float metallicFactor;
2210
} material;
2311

24-
vec3 calcNormal(float hasNormalMap, vec3 normal, vec2 textCoords, mat3 TBN)
25-
{
26-
vec3 newNormal = normal;
27-
if (hasNormalMap > 0)
28-
{
29-
newNormal = texture(normalSampler, textCoords).rgb;
30-
newNormal = normalize(newNormal * 2.0 - 1.0);
31-
newNormal = normalize(TBN * newNormal);
32-
}
33-
return newNormal;
34-
}
35-
3612
void main()
3713
{
38-
outAlbedo = material.diffuseColor + texture(textSampler, inTextCoords);
39-
40-
// Hack to avoid transparent PBR artifacts
41-
if (outAlbedo.a < 0.5) {
42-
discard;
43-
}
44-
45-
mat3 TBN = mat3(inTangent, inBitangent, inNormal);
46-
vec3 newNormal = calcNormal(material.hasNormalMap, inNormal, inTextCoords, TBN);
47-
// Transform normals from [-1, 1] to [0, 1]
48-
outNormal = vec4(0.5 * newNormal + 0.5, 1.0);
49-
50-
float ao = 0.5f;
51-
float roughnessFactor = 0.0f;
52-
float metallicFactor = 0.0f;
53-
if (material.hasMetalRoughMap > 0) {
54-
vec4 metRoughValue = texture(metRoughSampler, inTextCoords);
55-
roughnessFactor = metRoughValue.g;
56-
metallicFactor = metRoughValue.b;
57-
} else {
58-
roughnessFactor = material.roughnessFactor;
59-
metallicFactor = material.metallicFactor;
60-
}
61-
62-
outPBR = vec4(ao, roughnessFactor, metallicFactor, 1.0f);
14+
outAlbedo = material.diffuseColor + texture(textSampler, textCoords);
6315
}
Binary file not shown.
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#version 450
22

33
layout(location = 0) in vec3 entityPos;
4-
layout(location = 1) in vec3 entityNormal;
5-
layout(location = 2) in vec3 entityTangent;
6-
layout(location = 3) in vec3 entityBitangent;
7-
layout(location = 4) in vec2 entityTextCoords;
4+
layout(location = 1) in vec2 entityTextCoords;
85

9-
layout(location = 0) out vec3 outNormal;
10-
layout(location = 1) out vec3 outTangent;
11-
layout(location = 2) out vec3 outBitangent;
12-
layout(location = 3) out vec2 outTextCoords;
6+
layout(location = 0) out vec2 textCoords;
137

148
layout(set = 0, binding = 0) uniform ProjUniform {
159
mat4 projectionMatrix;
@@ -24,10 +18,6 @@ layout(push_constant) uniform matrices {
2418

2519
void main()
2620
{
27-
mat4 modelViewMatrix = viewUniform.viewMatrix * push_constants.modelMatrix;
28-
outNormal = normalize(modelViewMatrix * vec4(entityNormal, 0)).xyz;
29-
outTangent = normalize(modelViewMatrix * vec4(entityTangent, 0)).xyz;
30-
outBitangent = normalize(modelViewMatrix * vec4(entityBitangent, 0)).xyz;
31-
outTextCoords = entityTextCoords;
32-
gl_Position = projUniform.projectionMatrix * modelViewMatrix * vec4(entityPos, 1);
21+
gl_Position = projUniform.projectionMatrix * viewUniform.viewMatrix * push_constants.modelMatrix * vec4(entityPos, 1);
22+
textCoords = entityTextCoords;
3323
}
-1.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)