You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/Building_a_Simple_Engine/Lighting_Materials/02_lighting_models.adoc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ One of the most widely used traditional lighting models, developed by Bui Tuong
60
60
* *Disadvantages*: Not physically accurate, can look artificial under certain lighting conditions
61
61
* *When to use*: For simple real-time applications where PBR is too expensive
62
62
63
-
For more information on the Phong lighting model, see the link:https://en.wikipedia.org/wiki/Phong_reflection_model[Wikipedia article] or this link:https://www.cs.utah.edu/~shirley/books/fcg2/rt.pdf[computer graphics textbook].
63
+
For more information on the Phong lighting model, see the link:https://en.wikipedia.org/wiki/Phong_reflection_model[Wikipedia article].
64
64
65
65
==== Blinn-Phong Model
66
66
@@ -149,7 +149,7 @@ Global Illumination (GI) simulates how light bounces between surfaces, creating
149
149
* *Path Tracing*: Traces light paths through the scene
150
150
* *Photon Mapping*: Stores light information in a spatial data structure
151
151
152
-
For more information, see this link:https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-12-tricks-real-time-radiosity[GPU Gems chapter on radiosity].
152
+
For more information, see this link:https://developer.download.nvidia.com/books/HTML/gpugems2/chapters/gpugems2_chapter12.html[GPU Gems chapter on radiosity].
153
153
154
154
=== Subsurface Scattering
155
155
@@ -161,7 +161,7 @@ For more information, see this link:https://developer.nvidia.com/gpugems/gpugems
161
161
162
162
Ambient Occlusion (AO) approximates how much ambient light a surface point would receive, darkening corners and crevices.
163
163
164
-
For more information, see this link:https://developer.nvidia.com/gpugems/gpugems/part-ii-lighting-and-shadows/chapter-17-ambient-occlusion[GPU Gems chapter on ambient occlusion].
164
+
For more information, see this link:https://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch17.html[GPU Gems chapter on ambient occlusion].
Copy file name to clipboardExpand all lines: en/Building_a_Simple_Engine/Lighting_Materials/05_vulkan_integration.adoc
+3-273Lines changed: 3 additions & 273 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,288 +144,18 @@ void Renderer::recordCommandBuffer(vk::CommandBuffer commandBuffer, uint32_t ima
144
144
}
145
145
----
146
146
147
-
== Creating the PBR Shader
147
+
== PBR Shader Reference
148
148
149
-
Now that we've updated our renderer to support our PBR implementation, we need to create the PBR shader that implements the concepts we've discussed in this chapter. Rather than presenting this as a monolithic code dump, let's break down the shader creation into logical sections that explain both the technical implementation and the reasoning behind each component.
149
+
This chapter reuses the exact PBR shader defined in the previous section to avoid duplication and drift. Please refer to link:04_lighting_implementation.adoc[Implementing the PBR Shader] for the full pbr.slang source and detailed explanations. Here we focus strictly on Vulkan integration: pipeline layout, descriptor bindings, push constants, and draw submission.
150
150
151
-
=== Section 1: Shader Structure and Data Interface
152
-
153
-
The first section establishes the communication interface between our CPU application and GPU shader, defining how data flows through the rendering pipeline.
154
-
155
-
[source,cpp]
156
-
----
157
-
// Combined vertex and fragment shader for PBR rendering
158
-
159
-
// Input from vertex buffer - Data sent per vertex from CPU
160
-
struct VSInput {
161
-
float3 Position : POSITION; // 3D position in model space
162
-
float3 Normal : NORMAL; // Surface normal for lighting calculations
163
-
float2 UV : TEXCOORD0; // Texture coordinates for material sampling
164
-
float4 Tangent : TANGENT; // Tangent vector for normal mapping (w component = handedness)
165
-
};
166
-
167
-
// Output from vertex shader / Input to fragment shader - Interpolated data
168
-
struct VSOutput {
169
-
float4 Position : SV_POSITION; // Required clip space position for rasterization
170
-
float3 WorldPos : POSITION; // World space position for lighting calculations
171
-
float3 Normal : NORMAL; // World space normal (interpolated)
This interface design reflects modern GPU architecture principles where different types of data flow through different pathways based on their update frequency and size. Uniform buffers efficiently handle large, infrequently changing data like transformation matrices, while push constants provide ultra-fast updates for small, frequently changing material properties.
224
-
225
-
=== Section 2: PBR Mathematical Foundation
226
-
227
-
The second section implements the core mathematical functions that form the foundation of physically-based rendering, translating complex light-surface interactions into computationally efficient approximations.
228
-
229
-
[source,cpp]
230
-
----
231
-
// Normal Distribution Function (D) - GGX/Trowbridge-Reitz Distribution
232
-
// Describes the statistical distribution of microfacet orientations
These mathematical functions represent decades of computer graphics research distilled into efficient real-time approximations. The GGX distribution provides more realistic highlight falloff compared to older models, while the Smith geometry function ensures energy conservation at grazing angles. The Fresnel approximation captures the essential angle-dependent reflection behavior that makes materials look convincing under different viewing conditions.
267
-
268
-
=== Section 3: Vertex and Fragment Shader Implementation
269
-
270
-
The final section contains the actual shader entry points that execute for each vertex and pixel, implementing the complete PBR pipeline from geometry transformation through final color output.
271
-
272
-
[source,cpp]
273
-
----
274
-
// Vertex shader entry point - Executes once per vertex
275
-
[[shader("vertex")]]
276
-
VSOutput VSMain(VSInput input)
277
-
{
278
-
VSOutput output;
279
-
280
-
// Transform vertex position through the rendering pipeline
281
-
// Model -> World -> Camera -> Clip space transformation chain
After creating the shader file, we need to compile it using slangc. This is typically done as part of the build process, but we can also do it manually:
0 commit comments