Basic Shadow Mapping // Intermediate OpenGL Series

  Рет қаралды 18,830

OGLDEV

OGLDEV

Күн бұрын

In this video we learn a basic technique to add shadows to the 3D scene.
Timecodes
00:00 Intro
00:16 Spot light example
01:24 Characterizing the shadowed pixels
02:03 The shadow test
02:27 Shadow mapping
04:59 Perspective division
06:00 Shadow test example
06:21 The ShadowMapFBO class
08:00 The shadow pass
10:23 Testing the shadow pass
11:00 The lighting pass
16:25 Conclusion
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...
More info:
My shadow mapping tutorials: ogldev.org/www/tutorial23/tut...
ogldev.org/www/tutorial24/tut...
Shadow mapping tutorial by Joey de Vries: learnopengl.com/Advanced-Ligh...
Intro on ApiTrace: • Debugging Your OpenGL ...
OpenGL 4.6 specification: www.khronos.org/registry/Open...
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: "Black Hole" by Creator Mix (creatormix.com/)
Models:
** "Ordinary House" by tastyfish (www.blendswap.com/blend/19501)
** www.mixamo.com/#/?page=1&quer...
Enjoy,
Etay Meiri
#opengl #ogldev #opengtutorials

Пікірлер: 58
@tranxn7971
@tranxn7971 Жыл бұрын
Awesome, thanks a lot for all your work and great tutorials ! You deserve much more views.
@OGLDEV
@OGLDEV Жыл бұрын
Thanks a lot!
@maheshmahindrakar1884
@maheshmahindrakar1884 Жыл бұрын
Really awesome explaination 👍
@OGLDEV
@OGLDEV Жыл бұрын
Thanks a lot 😊
@cromartie3292
@cromartie3292 Жыл бұрын
Great, thanks for the video!
@OGLDEV
@OGLDEV Жыл бұрын
My pleasure!
@therealjtgill
@therealjtgill Жыл бұрын
Awesome video!
@OGLDEV
@OGLDEV Жыл бұрын
Glad you enjoyed it
@hallowedbythyframe
@hallowedbythyframe Жыл бұрын
Doing the lord's work
@OGLDEV
@OGLDEV Жыл бұрын
Wow! Thank you!
@killcode6717
@killcode6717 Жыл бұрын
Earned a subscribe
@OGLDEV
@OGLDEV Жыл бұрын
Welcome!
@pb5821
@pb5821 Жыл бұрын
hello. i m french. i m a big fan of your tutorials. i know they are exclusively opengl. but i wonder if you could, ad exception, make a tutorial on 3d collisions please? thanks again for your videos, they are very clear! keep on making them!
@OGLDEV
@OGLDEV Жыл бұрын
Thanks! It's true that right now I'm focusing on OpenGL but in the future I plan to branch out to more game development topics, including collision detection. However, this is a big topic and will require some research. I'll try to do something in between my regular videos. Possible after a few more light and shadow tutorials.
@pb5821
@pb5821 Жыл бұрын
@@OGLDEV nice!
Жыл бұрын
I feel we are gonna see a cascade of these videos
@OGLDEV
@OGLDEV Жыл бұрын
Probably... ;-)
@mortezabahrami2407
@mortezabahrami2407 Жыл бұрын
Hello. how is going? Can we develop a program like Maya or 3ds max by OpenGL? What about 2d animation engine or any 2d graphic program? thankyou
@OGLDEV
@OGLDEV Жыл бұрын
Yes. If you want to take advantage of the power of the GPU to do the rendering then you have to choose one of the available APIs. There really isn't a direct access to the GPU as with the CPU. You can also do 2D stuff using OpenGL. After all, the 3rd dimension is simply a combination of a projection matrix and the perspective divide mechanism in the GPU. Not sure how convenient the API itself is for 2D and how it stacks up against 2D specific APIs such as Direct2D.
@mortezabahrami2407
@mortezabahrami2407 Жыл бұрын
@@OGLDEV thanks a lot
@EDFHLFLFF
@EDFHLFLFF Жыл бұрын
Hi, when I follow this tutorial in my project, my shadow map texture texture values all seem to be 0.0, any idea why that would be? (In the calcShadowFactor() function in the shader the depth variable is always 0.0)
@OGLDEV
@OGLDEV Жыл бұрын
Did you change the default depth value by calling glClearDepth? It should be 1. Try to output some color from the fragment shader in the shadow pass (instead of the empty shader) so that you can see what the light "sees". This requires not binding the shadow map so that everything will go to the screen instead.
@EDFHLFLFF
@EDFHLFLFF Жыл бұрын
@@OGLDEV Currently I've got it outputting a black and white light view, which has the expected depth. However the texture from sampler2D in the lighting shader still only samples the value 0.0 which is confusing me. Even when I swap the argument to the texture function (float depth = texture(my-texture, uvCoords).x ) (where my-texture is the texture I use for the scene) it still gives 0.
@OGLDEV
@OGLDEV Жыл бұрын
Make sure the shadow map is bound correctly for reading during the light pass (glActiveTexture, glBindTexture, set the index and not GL_TEXTURE* in the shader). You can use ApiTrace to verify the shadow map is created and bound correctly. If you believe it is bound you can replace it with an all white texture just to make sure you get 1. You can also hack the shader to display uvCoords in the window as color to check that it makes sense.
@EDFHLFLFF
@EDFHLFLFF Жыл бұрын
@@OGLDEV Finally found the issue, turns out when I was clearing my depth buffer with glClear(GL_DEPTH_BUFFER_BIT) I was doing it while the fbo was still unbound, and now my shadows are working
@OGLDEV
@OGLDEV Жыл бұрын
Excellent!
@killereks
@killereks 3 ай бұрын
How do game engines like unity handle moving the sun so that it's in the frustum of the camera? I need to figure out the orientation and position of the directional light so that the camera shadows are always highest possible quality. Any resources on this?
@OGLDEV
@OGLDEV 3 ай бұрын
In the case of a directional light you only have a direction, there's no position. You will find a discussion about a tight intersection between the view frustum and the light volume here: learn.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps
@killereks
@killereks 3 ай бұрын
@@OGLDEV but for lightspace matrix u need a position, is that somehow excluded?
@OGLDEV
@OGLDEV 3 ай бұрын
For the light space matrix you use orthogonal projection so no need for position: kzbin.info/www/bejne/gJrYlZl4ad9keq8
@killereks
@killereks 3 ай бұрын
@@OGLDEV now im confused. Surely u need a position when rendering to the framebuffer? Otherwise the projection doesnt know what to include
@OGLDEV
@OGLDEV 3 ай бұрын
OK so it's not exactly a position per se. You define an orthogonal frustum with the usual six clipping planes which looks like a box. You need to make sure all the objects in the scene are within it and clip it against the view volume to make it as small as possible. No need to render stuff whose shadow cannot be seen (tricky because the object may be outside but the shadow inside).
@matanmigdal7108
@matanmigdal7108 Жыл бұрын
if you want to do shadow map for multi light source?
@OGLDEV
@OGLDEV Жыл бұрын
You need a separate shadow map for each spot light. You do a series of shadow passes - one pass per light/shadow map. You bind all the shadow maps to your lighting shader and do a single lighting pass. For each light you calculate its own shadow factor. A fragment may be in shadow for one light and not for another. You sum up the contribution from all light sources as usual. I will cover this in one of the upcoming videos.
@fudgeracoon2529
@fudgeracoon2529 Жыл бұрын
Can you do a video about PBR next ?
@OGLDEV
@OGLDEV Жыл бұрын
I plan to do a PBR tutorial in the not very distant future. You may also want to check out the video by my buddy Victor Gordan: kzbin.info/www/bejne/iIOoXnlrbMuVjtk.
@OGLDEV
@OGLDEV Жыл бұрын
And here's my video! - kzbin.info/www/bejne/jnzCoWWDrax1h9U
@glez3711
@glez3711 Жыл бұрын
I've tried implementing shadow mapping into my OpenGL program, but for whatever reason the objects captured in the shadow map dissapear and re-appear depending on the light's position (It's a directional light that moves left and right). Any help would be greatly appreciated.
@OGLDEV
@OGLDEV Жыл бұрын
Are you using an orthogonal projection matrix for the shadow pass? It may not be large enough and the object stays out of the frustum on some location of the light source.
@glez3711
@glez3711 Жыл бұрын
@@OGLDEV Nope, I'm using a perspective matrix for spot lights. I've tried switching up the perspective matrix that spot lights use with an orthogonal projection matrix, and the shadows work just fine (although they don't look as good given that now i'm using directional light shadows for a spot light).
@OGLDEV
@OGLDEV Жыл бұрын
Maybe the angle is simply not wide enough to capture the objects as the light moves left and right? If one matrix works and the other doesn't then it pretty much tells us the source of the problem.
@glez3711
@glez3711 Жыл бұрын
It's a possible explanation, however, if I push the light's position far back enough so that both objects are clearly within the shadow map's bounds at all times, they dissapear regardless and no shadows are casted. I am absolutely baffled by whatever witchcraft is going on in my program.
@OGLDEV
@OGLDEV Жыл бұрын
Try to track the shadow map using apitrace or any other debugging tool. It will help you understand the changes to the shadow map at the frame level. You should be able to pinpoint the exact frame where the object disappeared and debug from there.
@Xizilqou
@Xizilqou Жыл бұрын
Shadow volumes looks better
@OGLDEV
@OGLDEV Жыл бұрын
Each method can be improved in different ways and one method may look better than the other in different environments and settings.
SHADOWS! // Hazel Engine Dev Log
26:09
The Cherno
Рет қаралды 64 М.
Shadow Mapping Strikes Back // Intermediate OpenGL Series
10:56
Godzilla Attacks Brawl Stars!!!
00:39
Brawl Stars
Рет қаралды 10 МЛН
НЕОБЫЧНЫЙ ЛЕДЕНЕЦ
00:49
Sveta Sollar
Рет қаралды 7 МЛН
Зу-зу Күлпәш. Көрінбейтін адам. (4-бөлім)
54:41
Optimize Your Meshes!
19:41
OGLDEV
Рет қаралды 4,8 М.
Interactive Graphics 16 - Shadow Mapping
1:06:47
Cem Yuksel
Рет қаралды 10 М.
OpenGL (2024) for the Absolute Beginner #1... Why Bother?
9:45
Code Imposter
Рет қаралды 2,3 М.
Introduction to shaders: Learn the basics!
34:50
Barney Codes
Рет қаралды 261 М.
Lights and Shadows in Graphics - Computerphile
8:49
Computerphile
Рет қаралды 160 М.
How I Implemented Shadows in my Game Engine
7:45
ThinMatrix
Рет қаралды 92 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,3 МЛН
Basic Lighting And Materials // OpenGL Beginners Series
23:33
The Math behind (most) 3D games - Perspective Projection
13:20
Brendan Galea
Рет қаралды 358 М.