|
1 | 1 | # Deferred shading (I) |
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 | You can find the complete source code for this chapter [here](../../booksamples/chapter-10). |
6 | 6 |
|
7 | 7 | ## Deferred shading |
8 | 8 |
|
9 | 9 | 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. |
10 | 10 |
|
11 | | - |
12 | | - |
13 | 11 | 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: |
14 | 12 |
|
15 | 13 | - The diffuse colors for each position. We call this the albedo. |
16 | 14 | - The normals at each position. |
17 | 15 | - Depth values. |
18 | 16 | - Other materials information, |
19 | 17 |
|
20 | | - |
21 | | - |
22 | 18 | All that information is stored in attachments, as the depth attachment used in previous chapters. |
23 | 19 |
|
24 | 20 | 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 { |
986 | 982 | private void createDescriptorPool() { |
987 | 983 | List<DescriptorPool.DescriptorTypeCount> descriptorTypeCounts = new ArrayList<>(); |
988 | 984 | 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)); |
990 | 985 | descriptorPool = new DescriptorPool(device, descriptorTypeCounts); |
991 | 986 | } |
992 | 987 | ... |
993 | 988 | } |
994 | 989 | ``` |
995 | | - |
996 | 990 | 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). |
997 | 991 |
|
998 | 992 | 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: |
|
0 commit comments