OpenGL Tutorial 14 - Depth Buffer

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024

Комментарии • 45

  • @SB-rf2ye
    @SB-rf2ye 3 года назад +8

    massively underrated channel!!

  • @VictorGordan
    @VictorGordan  3 года назад +15

    NOTE: If you are having trouble loading in the models in this tutorial, it might be because the names of the textures are "diffuse" and "specular" instead of "baseColor" and "metallicRoughness" like in the previous tutorial. To fix this simply make the 'getTextures' function accept "baseColor" or "diffuse" and "metallicRoughness" or "specular" like this:
    if (texPath.find("baseColor") != std::string::npos || texPath.find("diffuse") != std::string::npos)
    else if (texPath.find("metallicRoughness") != std::string::npos || texPath.find("specular") != std::string::npos)
    Also note that in the Vertex Shader I removed the negative sign from the rotation matrix!

  • @PhamAnhKhoa118
    @PhamAnhKhoa118 3 года назад +1

    Hi Victor Gordan, there is one thing unclear in my mind about this equation in the fragment shader:
    FragColor = direcLight() * (1.0f - depth) + vec4(depth * vec3(0.85f, 0.85f, 0.90f), 1.0f);
    From what I see, the first part of the equation is about to adjust the strength of direction light. The depth value run from 0.0f to 1.0f, so this part will be between 0.0f and direcLight(). That means when we are close to the object (depth close to 0.0f), we get the object brighter - we see it clearer and vice verse. The second part is to adjust the strength of the background color. The principle is the same: we are close to the object, the background color seem to be brighter and vice verse. In short, the first part of the equation is for the object (trees and ground) while the other is for the surrounding color. Is that true???

    • @VictorGordan
      @VictorGordan  3 года назад +1

      Hmmm, I wrote it like shit from a readability perspective 💀
      I should have put the depth outside the vec4() to make it more clear that it is a linear interpolation.
      You got the first part right. When you are close to the object, you see its full color while when it's far away the object becomes black.
      The second part of the equation is there to not make the object black at a distance, but instead make it the color of the background so that it blends in with the background... 😅
      I could also have written it like this:
      FragColor = mix(directLight(), backgroundColor, depth);

    • @PhamAnhKhoa118
      @PhamAnhKhoa118 3 года назад +1

      @@VictorGordan thank you bro!

  • @sephjfox
    @sephjfox 5 месяцев назад

    this video is an absolute lifesaver 🥰

  • @PhamAnhKhoa118
    @PhamAnhKhoa118 3 года назад +4

    I am learning OpenGL as well. When i first tried to lauch your codes in the 14 lesson, I faced an error on my computer with the fragment shader. That is:
    SHADER_COMPILATION_ERROR for:FRAGMENT
    ERROR: 0:113: '=' : syntax error syntax error
    I checked again and again but I didn't see any problem with the syntax but whenever I built, the error showed up, giving me a blank screen. Do anyone have any situation like me???
    Anyway thanks a lot Victor Gordan for this useful tutorial!!!

    • @VictorGordan
      @VictorGordan  3 года назад +3

      Glad you liked the tutorial!
      That error just looks like a syntax error for the Fragment Shader. Without seeing your code though, I can't really help you. But since it specifies an equal sign maybe you wrote "=" instead of "=="? Or you forgot a semicolon somewhere.

    • @PhamAnhKhoa118
      @PhamAnhKhoa118 3 года назад +2

      @@VictorGordan Thanks for replying me! I already figured out the root of my problem. That was this line in the fragment shader:
      float logisticDepth(float depth, float steepness = 0.5f, float offset = 5.0f)
      I don't know much about graphic programming, OpenGL and stuff around like GLSL you know. So I can not explain why this is helping me that when I removed the 2 default arguments in the above function (I actually place them in the function body) and It worked. I searched for some helps in "Stack Overflow" and there were some people already dealt with this error but no clear answers were given, maybe something with the graphic card that decide whether or not we can use default arguments in the GLSL function.
      English is not my mother language so please feel free if I had made any mistakes.

    • @VictorGordan
      @VictorGordan  3 года назад +3

      The problem was that you tried to use default parameters, but GLSL doesn't support those sadly :/
      Glad you figured it out in the end!

    • @PhamAnhKhoa118
      @PhamAnhKhoa118 3 года назад +2

      @@VictorGordan haha, one lesson to know about GLSL

    • @keithle_
      @keithle_ Год назад

      So how did you fix this problem?
      I tried copying Victor's code and it's still the same error
      Also, chào đồng hương

  • @NickProkhorenko
    @NickProkhorenko Месяц назад

    Depth test doesn't work for me...

  • @ksriharsha2911
    @ksriharsha2911 3 года назад

    Subbed,shared,liked,saved😷

  • @oscarbayton1118
    @oscarbayton1118 2 года назад +2

    has anyone had a problem where the ground and the trees are upside down?

    • @BryseMeijer
      @BryseMeijer 2 года назад

      Strange. My trees are upside down as well. The author provided a comment saying that he removed the inverse on rotation in the vertex shader.
      Before: currentPos = vec3(model * translation * -rotation * scale * vec4(aPos, 1.0f));
      After: currentPos = vec3(model * translation * rotation * scale * vec4(aPos, 1.0f));
      This fixed my upside down trees.

  • @maxencedupont5523
    @maxencedupont5523 2 года назад +1

    Hi Victor, great video as always !
    I built a hexagonal map and I want to know if the mouse is on a particular hex, whatever the position of the camera, to be able to select the hexes in real time with the mouse. I think the best way to do that is to use the Depth Buffer, to detect if the mouse is over a particular hex or not. Should I try to consider the mouse as a 3D object ?

    • @VictorGordan
      @VictorGordan  2 года назад +1

      You can do this in multiple ways. Using the depth buffer would be one way of doing it, but it seems a bit complicated. What I would do in this case is give each hex a unique color and render the scene in a framebuffer without any sort of fancy stuff, just the scene with pure colors. Then check the mouse position, and see what pixel is at the mouse's position. Then you'll know which hex you are on since they all have a unique color ;)
      Hope that helps!

    • @maxencedupont5523
      @maxencedupont5523 2 года назад

      @@VictorGordan Oh, I see ! I have no idea on how to make this framebuffer, but I'll try. Thanks !

  • @davidmakowka922
    @davidmakowka922 Год назад

    Thanks!!!

  • @md.mazharulislam3493
    @md.mazharulislam3493 3 года назад

    Thanks 👍.

  • @ksriharsha2911
    @ksriharsha2911 3 года назад

    🔥🔥🔥🔥

  • @coinnerd9633
    @coinnerd9633 3 года назад +1

    hey my name is also Victor and I also have a youtube channel! ahahha

  • @manpotato295
    @manpotato295 2 месяца назад

    If you guys got flipped screen positionY:
    make -rotation -> rotation in default.vert
    curPos = vec3(model * translation * rotation * scale * vec4(aPos, 1.0f));

  • @josiahgil
    @josiahgil 2 месяца назад

    i've been wondering if it is possible to create a pixel depth offset effect in blender, like it is works in ue5, blender can do parallax occlusion, i just want to learn how pixel depth offset would work in blender.

  • @victorchalamet1170
    @victorchalamet1170 Год назад +1

    Hey, i have an issue, when i load the ground and tree model, they are upside down. Any idea of how to fix this ?

  • @lukasjetu9776
    @lukasjetu9776 7 месяцев назад

    for some reason, loading different models works, but it has the same texture as the sword, loading in just the ground and trees without the sword does work, but it has no texture, it's black; loading in the sword but not drawing it results in again, everything having the sword texture

    • @lukasjetu9776
      @lukasjetu9776 7 месяцев назад

      ohhh, i fixed it, it's in the comment from Victor Gordan, in Model class, at line 250 or something, you have to change "if (texPath.find("baseColor") != std::string::npos)" _to_ "if (texPath.find("baseColor") != std::string::npos || texPath.find("diffuse") != std::string::npos)" _and_ "else if (texPath.find("metallicRoughness") != std::string::npos)" _to_ "else if (texPath.find("metallicRoughness") != std::string::npos || texPath.find("specular") != std::string::npos)"

  • @chingching954
    @chingching954 Год назад +1

    why is it upside down? i got upside down result. please help :(

    • @VictorGordan
      @VictorGordan  Год назад

      You probably just made a typo somewhere by putting a minus where there shouldn't be one

  • @MooNDesigns
    @MooNDesigns 3 года назад +1

    Thanks!

  • @CaarabaloneDZN
    @CaarabaloneDZN 9 месяцев назад

    Great video

  • @adityawildan7
    @adityawildan7 Год назад

    Can i use this for shadow map?, I working on android version and only this method possible to show depth.

    • @VictorGordan
      @VictorGordan  Год назад

      Yeah, you can use this for shadow maps. I also have a tutorial on shadow maps ;)

  • @longjohn7992
    @longjohn7992 2 года назад

    I’m 69 polys and that deep

  • @lanchanoinguyen2914
    @lanchanoinguyen2914 Год назад

    Please help,my geometries have z buffer malfunction,when looking at a specific angle like 0 degree,the texture seem right but when multiply it with a rotation matrix,it become fail of depth testing at 180 degree.

    • @VictorGordan
      @VictorGordan  Год назад

      Not quite sure what you just said, but if you have a problem with textures and rotation, then it sounds like you are applying a rotation matrix to your texture UVs

    • @lanchanoinguyen2914
      @lanchanoinguyen2914 Год назад

      @@VictorGordan no,i mean the z value seems wrong.the object behind not being hidden.Basically,the z does not change when rotation happen,so that it only correct at half of the rotation cycle.When look back,the behind object still in front.

    • @VictorGordan
      @VictorGordan  Год назад +1

      Oh ok, interesting. Sounds like something might be wrong with the projection matrix? I'm honestly unsure what could caude this. It does sound like some value should be negative but it becomes positive instead, or the opposite...

    • @lanchanoinguyen2914
      @lanchanoinguyen2914 Год назад

      @@VictorGordan ok thanks for replying

    • @lanchanoinguyen2914
      @lanchanoinguyen2914 Год назад

      @@VictorGordan hey man,i fixed my problem.it turns out that i need to set gl_fragdepth manually,assign it with z after transform matrices.This answer here may help some people in the future.