OpenGL Tutorial 25 - Shadow Maps (Directional Lights)

Sdílet
Vložit
  • čas přidán 1. 07. 2024
  • In this tutorial I'll show you what shadow maps are and how you can implement them in your scenes with directional lights!
    Source Code
    github.com/VictorGordan/openg...
    OpenGL Documentation
    www.khronos.org/registry/Open...
    Discord Server
    / discord
    Patreon
    / victorgordan
    Timestamps
    0:00 Introduction & Theory
    1:10 Shadow Map Framebuffer
    1:45 Light Matrices
    3:03 Shadow Map Shaders
    3:21 Shadow Map Program
    3:31 Shadow Map Rendering
    3:48 Shadow Map Debugging
    3:58 Normal Scene Rendering
    4:14 Modifying the Default Vertex Shader
    4:24 Modifying the Default Fragment Shader
    5:19 Shadow Acne
    6:23 Softening the Shadows
    6:43 Discord & Patreon
    References
    learnopengl.com/Advanced-Ligh...
    #opengl #opengltutorial #computergraphics #cpp #visualstudio #3dgraphics #shadows

Komentáře • 39

  • @RGBguy
    @RGBguy Před 2 lety +2

    Keep going! Need more advance computer graphics concepts! Thank you 🙏

  • @radoslavl921
    @radoslavl921 Před rokem +2

    Thank you for making this tutorial! I had so much trouble making shadow mapping work in my project. Turns out I had mistyped the code where I have to make FragLight be in the range of 0 and 1. I also made my shadows look nicer after rewatching your video.

  •  Před rokem

    Phenomenal explanation! Thanks!!!!

  • @aaron6807
    @aaron6807 Před rokem +5

    I've been trying to figure out how shadows work in games for a while but I could never think of solution and never got the chance to google it. But DAMN this is genius, I kind of feel bad that I couldn't figure this out but still

    • @VictorGordan
      @VictorGordan  Před rokem +3

      Sadly, now that you know, they will be a lot more visible (in a bad way). Before knowing this I thought the difference between low and high quality shadows was just how blurry they were. Now I know they are blurry cause they just blur low quality shadowmaps so they don't look that bad haha. And u'll start noticing the res of shadowmaps especially when they don't blur them haha

  • @thenospeak9244
    @thenospeak9244 Před rokem +1

    Very well explained and easy to follow. Great Job.

  • @imad9948
    @imad9948 Před 2 lety +2

    I love your videos

  • @yooyooman3d
    @yooyooman3d Před 2 lety +3

    Finally

    • @VictorGordan
      @VictorGordan  Před 2 lety +2

      It's here ;)

    • @yooyooman3d
      @yooyooman3d Před 2 lety

      @@VictorGordan Are you going in that order?
      learnopengl com

    • @VictorGordan
      @VictorGordan  Před 2 lety

      Yeah, 90% of the time I follow the order on learnopengl.com

  • @rohitaryan5043
    @rohitaryan5043 Před rokem

    Hi, your series on OpenGL is really great!!! Just having a small issue, in 3:48 where you were running depth map from light's perpective, the code is unable to preview it in the window and we get a large upscale version of the crow model with camera in origin, but later when the same matrices used making the shadows in the end it works. At the end, the entireity of the code works but not able to see the depth map from light perspective is what I am finding trouble from what I wrote code from your video

    • @VictorGordan
      @VictorGordan  Před rokem

      Very strange you can't see the depthmap while having it work... if it works it should be correct, therefore if you just display the depth map on two triangles covering the screen, you should be able to see it

  • @asunawu5351
    @asunawu5351 Před rokem +1

    This video is helpful, thanks a lot. I just got a question, how can I render the shadow map on the screen?

    • @VictorGordan
      @VictorGordan  Před rokem

      Look at my framebuffer tutorial and render the shadowmap texture instead of the framebuffer texture ;)

  • @noname-ni3hp
    @noname-ni3hp Před 11 měsíci +1

    why i feel the shadow is weird like there some places in mid of the light there is shadow and my shadow is not soft at all

  • @shoaibmehmood6103
    @shoaibmehmood6103 Před 2 lety +2

    Hey Victor, I'm a 2D character artist with a deep obsession with video games and computer graphics. However I was never into much programming and coding but more attracted to the creative and art sides of the projects like how shadows are implemented, light sources. Like I want to just know how it works without getting into the detail of the maths involved. I haven't been able to find simpler explainations of this. I have a question about how facial shadows are working in Forbidden West as the character of Aloy has poor facial deep facial shadows being casted on Aloy's face on the PS5 version in the prologue but get very good as we get into the game like advertised in the State of Play 21. Can you please help me with a little a bit of information?

    • @VictorGordan
      @VictorGordan  Před 2 lety +1

      I don't know much about facial shadows. I presume they work the same way all other shadows do though. Having bad depth early in the game vs late in the game seems more of an environment related thing rather than anything to do with the shadows themselves. Certain types of environment and lighting can affect the looks of things a lot. In this case we're probably talking about harsh lighting vs soft lighting. So it probably looks like it has less depth because of soft lighting which might be caused by a cloudy setting or smth like that

    • @pjrotsaert2832
      @pjrotsaert2832 Před rokem

      Late comment but I think what you're referring to are "contact shadows". Those are done by raymarching in the shader rather than shadow maps.

  • @menghanzhang
    @menghanzhang Před rokem

    I would like to ask a question. If I want to add a shadow map to the imported model in the program in tutorial 19 (keep the skybox), are the steps the same as in this tutorial? I tried the same way as in the tutorial (before 3:23) and no error was reported, but the window was all black.

    • @VictorGordan
      @VictorGordan  Před rokem

      Tbh I'm not sure. I don't really remember exactly what I did in the tutorials. But it sounds like you might have some problems with your shaders or your textures, specifically how you bind your textures and how many you have ;)
      Good luck!

    • @menghanzhang
      @menghanzhang Před rokem

      @@VictorGordan Okay. Thank you very much!

  • @user-ms1pt7jd8w
    @user-ms1pt7jd8w Před 2 lety +2

    How to dynamic(no static) calculate the projection matrix correctly? Thanks in advance for your reply )

    • @VictorGordan
      @VictorGordan  Před 2 lety +1

      I am not sure I understand your question 🤔
      Is the matrix not being calculated correctly in the video?

    • @starklosch
      @starklosch Před 2 lety +2

      Did you try to put the code of the matrices inside the while?

  • @MARIODILONARDO12
    @MARIODILONARDO12 Před rokem

    If the 3D model we render has a texture with alpha, how do we calculate the shadow properly? It will always be bad since only the mash is used to calculate the shadow

    • @VictorGordan
      @VictorGordan  Před rokem +1

      You render with textures on. Then it should work (assuming your renderer can handle transparent textures)

    • @MARIODILONARDO12
      @MARIODILONARDO12 Před rokem

      @@VictorGordan It worked great

  • @user-qd6tm2xr2t
    @user-qd6tm2xr2t Před rokem

    Hello, thank you very much for your video tutorial. But I still don't understand how shadow maps are rendered. I used the project in your video and replaced the post map with a shadow map. It does show, but the background is red. Then I try to do this in my own project. It only shows the red background, and nothing else.

    • @user-qd6tm2xr2t
      @user-qd6tm2xr2t Před rokem

      Thank you. I already know why there is no object in my shadow map. This is related to my light source coordinates. My light source is (0,0,0). But I still don't know why the shadow map I display is red, while the video is white.

    • @VictorGordan
      @VictorGordan  Před rokem

      Because you are getting RGB values from the map (a vector3). Just write ".r" or ".x" to only get the red part of the vector ;)

  • @starklosch
    @starklosch Před 2 lety +2

    First! I never did it. I had to do it. Xd

  • @shinystick241
    @shinystick241 Před 2 lety +1

    Can you first do physics tutorials and then continue with the opengl series please?

  • @shinystick241
    @shinystick241 Před 2 lety +1

    What else will you cover in this opengl series?

    • @VictorGordan
      @VictorGordan  Před 2 lety +2

      The same things that are on learnopengl.com and perhaps more ;)

    • @shinystick241
      @shinystick241 Před 2 lety +1

      @@VictorGordan ok