Skip to content

Commit 224a3f7

Browse files
committed
Close #14 (Missing changes in Chapter 14)
1 parent b71fefc commit 224a3f7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

chapter-14/chapter-14.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,44 @@ The first thing we do in that function is to calculate the TBN matrix. After tha
296296

297297
Finally, we use that function only if the material defines a normal map texture.
298298

299+
We need to modify also the `SceneRender` class to create and use the new normals that we use in the shaders:
300+
301+
```java
302+
public class SceneRender {
303+
...
304+
private void createUniforms() {
305+
...
306+
uniformsMap.createUniform("normalSampler");
307+
...
308+
uniformsMap.createUniform("material.hasNormalMap");
309+
...
310+
}
311+
public void render(Scene scene) {
312+
...
313+
uniformsMap.setUniform("normalSampler", 1);
314+
...
315+
for (Model model : models) {
316+
...
317+
for (Material material : model.getMaterialList()) {
318+
...
319+
String normalMapPath = material.getNormalMapPath();
320+
boolean hasNormalMapPath = normalMapPath != null;
321+
uniformsMap.setUniform("material.hasNormalMap", hasNormalMapPath ? 1 : 0);
322+
...
323+
if (hasNormalMapPath) {
324+
Texture normalMapTexture = textureCache.getTexture(normalMapPath);
325+
glActiveTexture(GL_TEXTURE1);
326+
normalMapTexture.bind();
327+
}
328+
...
329+
}
330+
}
331+
...
332+
}
333+
...
334+
}
335+
```
336+
299337
The last step is to update the `Main` class to show this effect. We will load two quads with and without normal maps associated to them. Also we will use left and right arrows to control light angle to show the effect.
300338

301339
```java

0 commit comments

Comments
 (0)