Skip to content

Commit c525ad8

Browse files
committed
polish
1 parent ca4e6be commit c525ad8

File tree

1 file changed

+22
-44
lines changed

1 file changed

+22
-44
lines changed

docs/en/manuals/physically-based-rendering.md

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ Defold’s PBR implementation follows the glTF 2.0 material specification and as
1212
PBR materials can include effects such as metallic reflections, surface roughness, transmission, clearcoat, subsurface scattering, iridescence, and more.
1313

1414
::: sidenote
15-
Embedded textures from GLTF files are not yet exposed or accessible for assignment in Defold. This will come at a later stage, for now only the material data is exposed to the shaders.
15+
Defold currently exposes PBR material data to shaders, but does not provide a built-in PBR lighting model. You can use this data in your own lighting and reflection shaders to achieve physically based rendering. A default PBR lighting model will be added to Defold at a later stage.
16+
:::
17+
18+
::: sidenote
19+
Embedded textures from glTF files are currently not automatically assigned in Defold. Only material parameters are exposed to shaders. You can still manually assign textures to model components and sample them in your shader.
1620
:::
1721

1822
## Material properties overview
1923

20-
The material properties are parsed from the GLTF 2.0 source files assigned to a model component. Not all properties are considered standard properties, some of these are explicitly exposed via GLTF extensions that may or may not be enabled by the application that exported the gltf files. The relevant extension is denoted in parentheses after the property name below.
24+
The material properties are parsed from the glTF 2.0 source files assigned to a model component. Not all properties are standard. Some are provided through optional glTF extensions that may or may not be included by the tool used to export the glTF file. The relevant extension is denoted in parentheses after the property name below.
2125

2226
Metallic roughness
2327
: Describes how light interact with the material. The default PBR model.
@@ -79,7 +83,7 @@ Some of these properties provides hints on how the material should be rendered.
7983

8084
## Shader integration
8185

82-
The PBR material data is exposed to the shaders based on types and name convention. First of all, the base material struct must be a separate uniform block in the shader named 'PbrMaterial':
86+
The PBR material data is exposed to the shaders based on types and name convention. The PBR material system provides all parsed material parameters to shaders via a structured uniform block named `PbrMaterial`. Each supported glTF extension corresponds to a struct within this block, which can be conditionally compiled using #define flags.
8387

8488
```glsl
8589
uniform PbrMaterial
@@ -172,42 +176,7 @@ struct PbrIridescence
172176
};
173177
```
174178

175-
Texture usage is also exposed to the shaders, but as previously mentioned, textures from the GLTF containers are not automatically set during rendering. You need to assign the textures to the models yourself for this to properly work. Naming for textures are a bit differently since you cannot store texture uniforms inside structs. In this case, the naming scheme is `<feature>_texture`:
176-
177-
```glsl
178-
// PbrMetallicRoughness
179-
uniform sampler2D PbrMetallicRoughness_baseColorTexture;
180-
uniform sampler2D PbrMetallicRoughness_metallicRoughnessTexture;
181-
182-
// PbrSpecularGlossiness
183-
uniform sampler2D PbrSpecularGlossiness_diffuseTexture;
184-
uniform sampler2D PbrSpecularGlossiness_specularGlossinessTexture;
185-
186-
// PbrClearCoat
187-
uniform sampler2D PbrClearcoat_clearcoatTexture;
188-
uniform sampler2D PbrClearcoat_clearcoatRoughnessTexture;
189-
uniform sampler2D PbrClearcoat_clearcoatNormalTexture;
190-
191-
// PbrTransmission
192-
uniform sampler2D PbrTransmission_transmissionTexture;
193-
194-
// PbrSpecular
195-
uniform sampler2D PbrSpecular_specularTexture;
196-
uniform sampler2D PbrSpecular_specularColorTexture;
197-
198-
// PbrVolume
199-
uniform sampler2D PbrVolume_thicknessTexture;
200-
201-
// PbrSheen
202-
uniform sampler2D PbrSheen_sheenColorTexture;
203-
uniform sampler2D PbrSheen_sheenRoughnessTexture;
204-
205-
// PbrIridescence
206-
uniform sampler2D PbrEmissive_iridescenceTexture;
207-
uniform sampler2D PbrEmissive_iridescenceThicknessTexture;
208-
```
209-
210-
The common properties are set on the material uniform itself (and once again, note the data packing into vec4). Textures follow a similar pattern as we've already seen:
179+
The common properties are set on the material uniform itself (and once again, note the data packing into vec4).
211180

212181
```glsl
213182
// Common textures
@@ -230,7 +199,7 @@ uniform PbrMaterial
230199

231200
### Example shader
232201

233-
Here is an example shader that contains all textures and features. Note that you can turn off features simply by using defines around each member of the PbrMaterial itself, as shown in the example below:
202+
Here is an example shader that contains all features and a proposed naming scheme for texture bindings (again, this must be handled manually). Note that you can turn off features simply by using defines around each member of the PbrMaterial itself, as shown in the example below:
234203

235204
```glsl
236205
// Feature flags, comment or remove these to slim down the shader.
@@ -277,9 +246,9 @@ struct PbrSpecularGlossiness
277246
};
278247
279248
// PbrClearCoat
280-
uniform sampler2D PbrClearcoat_clearcoatTexture;
281-
uniform sampler2D PbrClearcoat_clearcoatRoughnessTexture;
282-
uniform sampler2D PbrClearcoat_clearcoatNormalTexture;
249+
uniform sampler2D PbrClearCoat_clearcoatTexture;
250+
uniform sampler2D PbrClearCoat_clearcoatRoughnessTexture;
251+
uniform sampler2D PbrClearCoat_clearcoatNormalTexture;
283252
284253
struct PbrClearCoat
285254
{
@@ -409,7 +378,16 @@ If specific data points in the material struct are not found, the data for those
409378

410379
### Constants
411380

412-
Since all of the properties are represented internally by render constants, materials can specify different default values when these values are not present. To do this, you can use the following naming pattern: ´pbrFeature.structMember`:
381+
Each material property corresponds to an internal render constant in Defold. You can override default values by defining constants on the material resource itself, following the naming pattern `pbrFeature.structMember`. These values will be applied automatically if the matching data is missing in the glTF material.
413382

414383
![Material constants](images/physically-based-rendering/material-constants.png)
415384

385+
## Next steps
386+
387+
To use the material data for physically based lighting, implement a BRDF in your fragment shader using the parameters provided in the `PbrMaterial` block.
388+
See also:
389+
390+
* [Shaders manual](/manuals/shader)
391+
* [Render manual](/manuals/render)
392+
* [glTF 2.0 specification](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html)
393+

0 commit comments

Comments
 (0)