Diffuse Lighting // OpenGL Tutorial #20

Опубликовано: 24 Февраль 2025
на канале: OGLDEV
9,241
225

AEJuice Free Plugins https://aejuice.com/free-plugins/?ref...
AEJuice I Want It All Bundle https://aejuice.com/product/i-want-it...
AEJuice YouTube Channel    / @aejuice  

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 - https://polyhaven.com/a/wine_barrel_01 by James Ray Cock
Terrain texture - https://polyhaven.com/a/aerial_rocks_02 by Rob Tuytel

Thanks a lot to James and Rob for providing their creations!

🔥 I'm using the following books as background information for my tutorials and I highly recommend them for learning more about OpenGL and Vulkan.
These are affiliate links so if you use them to buy the books the price is the same for you and I will get a small commision (thank-you!).

📖 OpenGL 4 Shading Language Cookbook - Third Edition: Build high-quality, real-time 3D graphics with OpenGL 4.6, GLSL 4.6 and C++17 3rd ed. Edition: https://amzn.to/3XO2J3S

📖 3D Graphics Rendering Cookbook: A comprehensive guide to exploring rendering algorithms in modern OpenGL and Vulkan: https://amzn.to/3MMJQbf
(Watch my short video review on this book:    • The 2nd book I'm using for my Vulkan ...  )

📖 Vulkan Programming Guide: The Official Guide to Learning Vulkan: https://amzn.to/3XwBjhr
(Watch my short video review on this book:    • The book I'm using for my Vulkan seri...  )

Make sure to watch all the previous tutorials in the "OpenGL For Beginners" playlist at    • OpenGL for Beginners  

Please visit https://ogldev.org to see more of my tutorials on modern OpenGL.

Link to source: https://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: https://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: [email protected]
Github: https://github.com/emeiri/ogldev.git
Twitter: @ogldev
One time donations (Paypal): https://ogldev.org/donate.html
Patreon:   / ogldev  

Credits:
Music - "Small Guitar" from https://bensound.com
Duke Nukem image - https://www.cleanpng.com/png-duke-nuk...

Johann Heinrich Lambert pic - https://en.wikipedia.org/wiki/Johann_...
Cosine pic - https://upload.wikimedia.org/wikipedi...

Enjoy,

Etay Meiri

#opengl #ogldev #opengtutorials