Рет қаралды 7,417
In this video we will learn how to implement diffuse lighting which is the second type of light in the Phong Reflection Model. We've covered ambient lighting in the previous tutorial and specular lighting will be covered in the next one.
In this tutorial I have used the following public domain assets:
Wine barrel model - polyhaven.com/a/wine_barrel_01 by James Ray Cock
Terrain texture - polyhaven.com/a/aerial_rocks_02 by Rob Tuytel
Thanks a lot to James and Rob for providing their creations!
Make sure to watch all the previous tutorials in the "OpenGL For Beginners" playlist at • OpenGL for Beginners
Please visit ogldev.org to see more of my tutorials on modern OpenGL.
Link to source: github.com/emeiri/ogldev/blob...
If you want to get the same version that was used in the video checkout the tag TUT_20_DIFFUSE_LIGHTING.
OpenGL 4.6 specification: www.khronos.org/registry/Open...
Timecodes:
0:00 Intro
0:57 Light sources types
3:02 The diffuse light factor
3:51 Lambert’s Cosine Law
4:33 Diffusely reflecting surface
5:10 The surface normal
6:11 Calculating the diffuse factor
7:29 Surface vs Vertex normals
9:00 Transforming the normal
10:27 Diffuse lighting in local space
11:05 Generating the world-to-local matrix
12:37 Code Review
12:45 Step 1: Add a diffuse component to the material
13:36 Step 2: Create a directional light with a diffuse component
14:50 Step 3: Calculate the light direction in local space
16:01 Step 4: Add uniform locations for shader diffuse params
16:37 Step 5: Add vertex normal to the vertex shader
17:22 Step 6: Implement diffuse lighting in the fragment shader
19:39 Step 7: Minor changes to the main app code
20:17 Test and experiment
Feel free to comment below.
Email: ogldev1@gmail.com
Github: github.com/emeiri/ogldev.git
Twitter: @ogldev
One time donations (Paypal): ogldev.org/donate.html
Patreon: / ogldev
Credits:
Music - "Small Guitar" from bensound.com
Duke Nukem image - www.cleanpng.com/png-duke-nuk...
Johann Heinrich Lambert pic - en.wikipedia.org/wiki/Johann_...
Cosine pic - upload.wikimedia.org/wikipedi...
Enjoy,
Etay Meiri
#opengl #ogldev #opengtutorials