Physically Based Rendering // OpenGL Tutorial #43

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 มิ.ย. 2024
  • This video is (hopefully) a gentle introduction to Physically Based Rendering (PBR) using OpenGL. The topic itself is complex and relies on many years of research (by other people ;-) ). I tried to explain the mechanics and give some intuition into why they work this way.
    Resources:
    * 'OpenGL Shading Language Cookbook - 3rd Ed' by David Wolff
    * learnopengl.com/PBR/Lighting
    Timecodes:
    0:00 Intro
    0:49 What is PBR?
    1:56 Simplified PBR equation
    2:58 The BRDF
    4:25 The Diffuse BRDF
    6:47 The Specular BRDF
    8:03 The Normal Distribution Function (GGX)
    10:26 The Geometry Function (Schlick GGX)
    12:11 The Fresnel Function (Schlick approximation)
    14:23 Last two pieces of the PBR equation
    14:44 Fragment shader code review
    17:00 Outro
    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_43_PBR.
    OpenGL 4.6 specification: www.khronos.org/registry/Open...
    Credits:
    Images:
    * kordula vahle from Pixabay (lago federa)
    * Pau Llopart Cervello from Pixabay (ring)
    * www.codinglabs.net/article_phy...
    * Clker-Free-Vector-Images from Pixabay
    * OpenClipart-Vectors from Pixabay
    * blog.selfshadow.com/publicati...
    * www.codinglabs.net/article_phy...
    * Anja-#pray for ukraine# #helping hands# stop the war from Pixabay
    Videos:
    * • Sansar : Phong Materia...
    * • • CryEngine - Physical...
    * • PBR texture in Blender...
    * • Turning Images into PB...
    Music:
    "Sweet Heat" from tunetank.com/
    Feel free to comment below.
    Email: ogldev1@gmail.com
    Instagram: @ogldev1
    Github: github.com/emeiri/ogldev.git
    Twitter: @ogldev
    One time donations (Paypal): ogldev.org/donate.html
    Patreon: / ogldev
    Enjoy,
    Etay Meiri
    #opengl #ogldev #opengtutorials

ความคิดเห็น • 54

  • @liorsky
    @liorsky 6 หลายเดือนก่อน +1

    Im finding researching the topic with papers so difficult and this is just the perfect gateway for the subject

    • @OGLDEV
      @OGLDEV  6 หลายเดือนก่อน

      Thanks :-)

  • @claymans2731
    @claymans2731 ปีที่แล้ว +6

    I must say this is the most clear PBR explanation with actual working code. How about add IBL in the next video~

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      Thank you!
      IBL is on the roadmap but will take some time because I have other topics planned.

  • @furkanunsal5814
    @furkanunsal5814 ปีที่แล้ว +8

    very clear and applicable, great work! I had to read the book for it in my project.

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      Cool, thanks!

  • @maheshmahindrakar1884
    @maheshmahindrakar1884 ปีที่แล้ว +2

    Very well simplified explanation...👍

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      Thank you :-)

  • @asimovf77
    @asimovf77 ปีที่แล้ว +1

    Great content as usual !!!!! Keep going and thanx for sharing!!!!!

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว +1

      You bet!

  • @roness6749
    @roness6749 3 หลายเดือนก่อน

    Amazing tutorial, thank you so much for making this.

    • @OGLDEV
      @OGLDEV  3 หลายเดือนก่อน

      You're very welcome!

  • @xphereSpz
    @xphereSpz ปีที่แล้ว

    nice tutorial and great explanation!! :)

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      Thanks!

  •  2 หลายเดือนก่อน

    Great video, thanks!

    • @OGLDEV
      @OGLDEV  2 หลายเดือนก่อน

      You're welcome!

  • @CodeParticles
    @CodeParticles ปีที่แล้ว +1

    @OGLDEV, Thank you for this upload. I have a question on the reflection of objects you briefly mentioned @ 12:53? How would you reflect other objects when using PBR? When I was working on blinn-phong, I had to render a framebuffer object of my scene and then use that as a texture for my reflective objects to simulate reflection. Is it the same for PBR too or is it much easier to do? I've done PBR as well, but couldn't figure out how to reflect objects only the skybox, thank you!

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว +1

      I haven't done this yet but perhaps you mean something like: learnopengl.com/PBR/IBL/Diffuse-irradiance ?

  • @hajjex_9086
    @hajjex_9086 10 หลายเดือนก่อน +1

    Hey, i have a question
    Now, usually when calculating the reflection
    We usually dont have the "light" vector
    We would have a reflection vector, but that doesn't necessarily mean that the reflected ray would bounce of toward a light source.
    Is it still what you meant by "light" vector?
    Or do i have to somehow calculate the direction of the closest emitting material or something?
    Thanks in advance!

    • @OGLDEV
      @OGLDEV  10 หลายเดือนก่อน

      Reflecting and reversing (or negating) the light direction are two different things. When you want to calculate diffuse lighting you have to do a dot product between the normal and the light direction, but the light direction must be pointing from the surface and "up", same as the normal. For example, if the light hits the surface at maximum strength it means that the original light vector is perpendicular to the surface but is opposite to the normal (which is also perpendicular ofcourse). So you multiply the light direction by -1 and when you do the dot product with the normal you get 1 which means maximum strength. Reflecting is when you want to calculate the specular effect. Let's say that the light hits the surface at 45 degrees angle. To calc the reflection you call reflect(LightDirection, Normal) and this will give you the a vector which point 45 degrees on the "other side" of the normal. The original light vector is pointing at the surface and the reflection is pointing back up. This allows it to hits the camera and the specular effect increases as the reflection and pixel to camera vector become aligned. So you don't need to reverse in the specular case, just use reflect() with the original light direction.

    • @hajjex_9086
      @hajjex_9086 10 หลายเดือนก่อน +1

      @@OGLDEV thanks!
      My question was just wanting to know if I can replace the "light" in your video with just the incoming ray, whether it was from a light source or an object
      Because, as you know, that's how raytracers work
      Thanks again!
      Really underrated channel.
      Keep it up.

    • @OGLDEV
      @OGLDEV  10 หลายเดือนก่อน +1

      Oh, I see, I think you can.
      Thanks!

  • @progfix
    @progfix ปีที่แล้ว

    How does shadow mapping work with PBR? Where do you apply the shadow value?

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว +1

      I guess it should work the same as the regular Phong model, since PBR only deals with the color of the object. Compare CalcDirectionalLight with CalcPBRDirectionalLight. The non-PBR version calculates a shadow factor which depends only on the light direction and the normal. You need to multiply it with the PBR color.

    • @DasAntiNaziBroetchen
      @DasAntiNaziBroetchen 10 หลายเดือนก่อน

      You can just multiply the light color/intensity with the shadow factor.

  • @sumitmakkar7199
    @sumitmakkar7199 11 หลายเดือนก่อน

    Hi,
    First of all thanks a lot for providing us these videos. I have a doubt in half vector calculation. Taking the direction of light vector into consideration, shouldn't the equation for calculating half vector be: half = normalize( view-light). As light + view would be more horizontal. Or the direction of the light vector should be opposite ( by which I mean that it should be multiplied with -1).

    • @OGLDEV
      @OGLDEV  11 หลายเดือนก่อน

      The light direction is provided by the application in the natural order - down towards the earth. I believe it's more intuitive for the developer to think about it like that. It is reversed in the fragment shader.

    • @hajjex_9086
      @hajjex_9086 10 หลายเดือนก่อน

      ​@@OGLDEVso for me to apply it to my case, I have to reverse it like he said?
      *-1?

    • @OGLDEV
      @OGLDEV  10 หลายเดือนก่อน +1

      @hajjex_9086 Depends on how you send in your light direction. The shader assumes that it is the original direction so it has to reverse it for the diffuse calculation because the dot product needs the direction from the surface back to the light source. But you can also optimize somewhere between the application and shader and reverse the light direction before it goes in and then the shader can use it as-is without extra ops.

    • @hajjex_9086
      @hajjex_9086 10 หลายเดือนก่อน +1

      @@OGLDEV I actually send my rays from the camera
      And that's it
      So in reality
      It's actually pointing toward the light source at some point
      So does that need reversing?

    • @hajjex_9086
      @hajjex_9086 10 หลายเดือนก่อน

      ​​​@@OGLDEValso, by original direction, u mean that it's from light to surface.
      This means we will simply do light vector + view?
      This confused me a little.

  • @MrFacciolone
    @MrFacciolone ปีที่แล้ว

    one thing I don't understand, you say that alpha(roughness) = 0 means a perfectly smooth surface, that means it reflects all light, but when alpha is 0 than the whole normal distribution function D computes to 0 (since the numerator is 0*0), hence making the whole BRDF specular equal to 0, since D is multiplied for G and F .. Something I'm missing here?

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว +2

      It's a good question. Obviously when alpha is zero the BRDF is zero so we don't get specular lighting. I think that zero here serves as kind of a limit to which we are not supposed to reach and realistically the roughness values will be much higher (I consider 0.1 to be "much higher" ;-) ). Here's an interesting experiment you may want to try: plug the GGX equation into a spreadsheet. Set an input column for alpha and have it start at zero and continue with small increments. NdotH can be constant for the entire spreadsheet. A good example is 1 where the light ray is reflected directly at the eye but you may want to play with different values. When NdotH=1 and alpha=0.1 you are already getting 3183 which is very high and alpha=0.01 is really crazy. So I guess alpha=0 should return infinity but the equation simply doesn't work that way. I'm pretty sure the people who invented this were well aware of this corner and the papers may have addressed this already. Infinity is not very useful in practical applications so I guess they just ignored it. This is just my intuition. Joey De-Vries has a web based example in learnopengl.com/PBR/Lighting which you can also play with. When alpha is very low you get a very concentrated specular reflection and when it is zero there is nothing.

    • @MrFacciolone
      @MrFacciolone ปีที่แล้ว +1

      @@OGLDEV aaah thank you this clarifies it! I got stuck on that believing I wasn't undertanding some relatively simple math! Indeed thinking on it the stronger specular reflection is, the smaller the area that is seen reflecting. So alpha must be non zero or the area reflecting gets infinetely small, On the source you linked in the code alpha seems to start at 0.2. Thanks!

  • @ToPGoP
    @ToPGoP ปีที่แล้ว +1

    Hello, can you update the link to source please?

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      Done.

    • @ToPGoP
      @ToPGoP ปีที่แล้ว +1

      @@OGLDEV thanks

  • @divyakunwar6992
    @divyakunwar6992 4 หลายเดือนก่อน

    can you share the cpp file for this code

    • @OGLDEV
      @OGLDEV  4 หลายเดือนก่อน

      github.com/emeiri/ogldev/blob/master/tutorial43_youtube

  • @MrMariozzz78
    @MrMariozzz78 14 ชั่วโมงที่ผ่านมา

    Is the metallic shine of video games due to pbr or raytracing?

    • @OGLDEV
      @OGLDEV  13 ชั่วโมงที่ผ่านมา

      Both techniques can create the effect of metallic shine but I would guess that PBR is more common than raytracing because afaik raytracing is slower and more compute intensive.

    • @MrMariozzz78
      @MrMariozzz78 13 ชั่วโมงที่ผ่านมา

      @@OGLDEV for shure all these sport car are made with pbr 🙂

    • @OGLDEV
      @OGLDEV  12 ชั่วโมงที่ผ่านมา

      That's why they are so expensive ;-)

    • @MrMariozzz78
      @MrMariozzz78 11 ชั่วโมงที่ผ่านมา

      @@OGLDEV and teenagers spend 2000 euro for a 4090 for a fake global illumination

  • @hajjex_9086
    @hajjex_9086 10 หลายเดือนก่อน +2

    This is literally an irl cheat code

    • @OGLDEV
      @OGLDEV  10 หลายเดือนก่อน

      OMG! Is it a good thing or a bad thing??

    • @hajjex_9086
      @hajjex_9086 10 หลายเดือนก่อน

      @@OGLDEV I'm saying that this is wonderful Because it makes a hard topic very accessible
      Thanks!

    • @OGLDEV
      @OGLDEV  10 หลายเดือนก่อน

      You're welcome :-)

  • @alakhaggarwal6315
    @alakhaggarwal6315 ปีที่แล้ว

    For an ideal perfectly smooth surface, alpha=0. This makes D=0 because D is proportional to alpha^2. That makes SpecularBRDF=0. But I thought for smooth surface, Specular BRDF should be high

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      Hi, I'm on vacation. Will get back to you next week.

    • @OGLDEV
      @OGLDEV  ปีที่แล้ว

      I'm back and turns out I already answered this question three months ago 🙂
      Please see my response to @MrFacciolone below (th-cam.com/video/XK_p2MxGBQs/w-d-xo.html&lc=Ugz-W5xSJlCgSFO60EV4AaABAg.9jzRGRPKpap9k1dX8vgJdG)