Skip to content

Commit 701ef0c

Browse files
committed
Fixed bug in lighting shader
1 parent af4bcb9 commit 701ef0c

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

bookcontents/chapter-10/chapter-10.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
# Deferred shading (I)
22

3-
In this chapter we will setup the basis to implement deferred shading. We will split the rendering into two phases, one to render the geometry and relevant parameters of the scene and another one to apply lighting. In this chapter we will only setup the basis, leaving the changes required to apply lighting for the next chapter. We will not be introducing new Vulkan concepts, just combine the ones we have described previously to support deferred shading. Therefore, you will see larger chunks of code with an explanatory overview, focusing on the key concepts of Vulkan that need to be applied to implement deferred shading
3+
In this chapter we will setup the basis to implement deferred shading. We will split the rendering into two phases, one to render the geometry and relevant parameters of the scene and another one to apply lighting. In this chapter we will only setup the basis, leaving the changes required to apply lighting for the next chapter. We will not be introducing new Vulkan concepts, just combine the ones we have described previously to support deferred shading. Therefore, you will see larger chunks of code with an explanatory overview, focusing on the key concepts of Vulkan that need to be applied to implement deferred shading.
44

55
You can find the complete source code for this chapter [here](../../booksamples/chapter-10).
66

77
## Deferred shading
88

99
Up to now the way that we are rendering a 3D scene is called forward rendering. Deferred rendering is frequently used when having multiple lights and usually consists of two phases. In the first phase data that is required for shading computation is generated (depth values, albedo colors, material properties, etc.). In the second phase, taking all that information as inputs lighting is applied to each fragment.
1010

11-
12-
1311
Hence, with deferred shading we perform two rendering phases. The first one, is the geometry pass, where we render the scene to several attachments that will contain the following information:
1412

1513
- The diffuse colors for each position. We call this the albedo.
1614
- The normals at each position.
1715
- Depth values.
1816
- Other materials information,
1917

20-
21-
2218
All that information is stored in attachments, as the depth attachment used in previous chapters.
2319

2420
The second pass is called the lighting phase. This phase takes a shape that fills up all the screen and generates the final color information, using lighting, for each fragment using as inputs the attachment outputs generated in the previous phase. When are will performing the lighting pass, the depth test in the geometry phase will have already removed all the scene data that is not be seen. Hence, the number of operations to be done are restricted to what will be displayed on the screen.
@@ -986,13 +982,11 @@ public class LightingRenderActivity {
986982
private void createDescriptorPool() {
987983
List<DescriptorPool.DescriptorTypeCount> descriptorTypeCounts = new ArrayList<>();
988984
descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(GeometryAttachments.NUMBER_ATTACHMENTS, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER));
989-
descriptorTypeCounts.add(new DescriptorPool.DescriptorTypeCount(swapChain.getNumImages() * 2 + 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER));
990985
descriptorPool = new DescriptorPool(device, descriptorTypeCounts);
991986
}
992987
...
993988
}
994989
```
995-
996990
We will need texture samplers to access the attachments filled up in the geometry phase, therefore we will need as many samplers as input attachments we have (Remember that the input attachments in this phase are the output attachments in the previous one).
997991

998992
The `createDescriptorSets` method just creates the descriptor set layout and the descriptor set that defines the samplers needed to access the attachments in the lighting phase:
-152 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)