Skip to content

Commit 693ce00

Browse files
committed
Fixed coordinates problems in chapter 10
1 parent 628e623 commit 693ce00

File tree

9 files changed

+9
-9
lines changed

9 files changed

+9
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ 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](screen-shot.png)
10+
911
## Book Code
1012

1113
The book itself is also hosted in [GitHub](https://github.com/lwjglgamedev/vulkanbook/tree/master/bookcontents).

bookcontents/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ 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 (Draft code, still missing PBR lighting).
15+
- [Chapter 10](chapter-09/chapter-10.md): Deferred rendering (Draft code, synchronization needs to be reviewed).

booksamples/chapter-10/resources/shaders/lighting_fragment.glsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#version 450
2-
precision highp float;
32

43
const int MAX_LIGHTS = 10;
54
const float PI = 3.14159265359;
@@ -128,7 +127,7 @@ void main() {
128127
float metallic = pbrSampledValue.b;
129128

130129
// Retrieve position from depth
131-
vec4 clip = vec4(inTextCoord * 2.0 - 1.0, texture(depthSampler, inTextCoord).x, 1.0);
130+
vec4 clip = vec4(inTextCoord.x * 2.0 - 1.0, inTextCoord.y * -2.0 + 1.0, texture(depthSampler, inTextCoord).x, 1.0);
132131
vec4 world_w = projUniform.invProjectionMatrix * clip;
133132
vec3 pos = world_w.xyz / world_w.w;
134133

Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#version 450
2-
precision highp float;
32

43
layout(location = 0) out vec2 outTextCoord;
54

65
void main()
76
{
87
outTextCoord = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
9-
gl_Position = vec4(outTextCoord * 2.0f - 1.0f, 0.0f, 1.0f);
8+
gl_Position = vec4(outTextCoord.x * 2.0f - 1.0f, outTextCoord.y * -2.0f + 1.0f, 0.0f, 1.0f);
109
}
84 Bytes
Binary file not shown.

booksamples/chapter-10/src/main/java/org/vulkanb/eng/graph/lighting/LightingRenderActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void preRecordCommandBuffer(int idx) {
169169

170170
commandBuffer.reset();
171171
VkClearValue.Buffer clearValues = VkClearValue.callocStack(1, stack);
172-
clearValues.apply(0, v -> v.color().float32(0, 0.5f).float32(1, 0.7f).float32(2, 0.9f).float32(3, 1));
172+
clearValues.apply(0, v -> v.color().float32(0, 0.0f).float32(1, 0.0f).float32(2, 0.0f).float32(3, 1));
173173

174174
VkRect2D renderArea = VkRect2D.callocStack(stack);
175175
renderArea.offset().set(0, 0);
@@ -191,8 +191,8 @@ public void preRecordCommandBuffer(int idx) {
191191

192192
VkViewport.Buffer viewport = VkViewport.callocStack(1, stack)
193193
.x(0)
194-
.y(0)
195-
.height(height)
194+
.y(height)
195+
.height(-height)
196196
.width(width)
197197
.minDepth(0.0f)
198198
.maxDepth(1.0f);

booksamples/chapter-10/src/main/java/org/vulkanb/eng/graph/vk/VertexBufferStructure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public VertexBufferStructure() {
5555
viAttrs.get(i)
5656
.binding(0)
5757
.location(i)
58-
.format(VK_FORMAT_R32G32B32_SFLOAT)
58+
.format(VK_FORMAT_R32G32_SFLOAT)
5959
.offset(NORMAL_COMPONENTS * GraphConstants.FLOAT_LENGTH * 3 + POSITION_COMPONENTS * GraphConstants.FLOAT_LENGTH);
6060

6161
viBindings.get(0)

screen-shot.png

3.51 MB
Loading

0 commit comments

Comments
 (0)