OpenGL Tutorial 14 - Depth Buffer

  Рет қаралды 24,213

Victor Gordan

Victor Gordan

Күн бұрын

Пікірлер: 46
@VictorGordan
@VictorGordan 3 жыл бұрын
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!
@SB-rf2ye
@SB-rf2ye 3 жыл бұрын
massively underrated channel!!
@VictorGordan
@VictorGordan 3 жыл бұрын
Thank you :,)
@PhamAnhKhoa118
@PhamAnhKhoa118 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@VictorGordan thank you bro!
@sephjfox
@sephjfox 7 ай бұрын
this video is an absolute lifesaver 🥰
@PhamAnhKhoa118
@PhamAnhKhoa118 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
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 жыл бұрын
@@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
@victorchalamet1170
@victorchalamet1170 Жыл бұрын
Hey, i have an issue, when i load the ground and tree model, they are upside down. Any idea of how to fix this ?
@ksriharsha2911
@ksriharsha2911 3 жыл бұрын
Subbed,shared,liked,saved😷
@MooNDesigns
@MooNDesigns 3 жыл бұрын
Thanks!
@VictorGordan
@VictorGordan 3 жыл бұрын
You're welcome! :)
@josiahgil
@josiahgil 5 ай бұрын
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.
@manpotato295
@manpotato295 4 ай бұрын
If you guys got flipped screen positionY: make -rotation -> rotation in default.vert curPos = vec3(model * translation * rotation * scale * vec4(aPos, 1.0f));
@notballai
@notballai 11 күн бұрын
Life saver
@davidmakowka922
@davidmakowka922 Жыл бұрын
Thanks!!!
@md.mazharulislam3493
@md.mazharulislam3493 3 жыл бұрын
Thanks 👍.
@VictorGordan
@VictorGordan 3 жыл бұрын
No problem haha
@maxencedupont5523
@maxencedupont5523 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@VictorGordan Oh, I see ! I have no idea on how to make this framebuffer, but I'll try. Thanks !
@chingching954
@chingching954 Жыл бұрын
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
@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 Жыл бұрын
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.
@NickProkhorenko
@NickProkhorenko 4 ай бұрын
Depth test doesn't work for me...
@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 ;)
@oscarbayton1118
@oscarbayton1118 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.
@lukasjetu9776
@lukasjetu9776 10 ай бұрын
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 10 ай бұрын
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)"
@ksriharsha2911
@ksriharsha2911 3 жыл бұрын
🔥🔥🔥🔥
@VictorGordan
@VictorGordan 3 жыл бұрын
😎
@CaarabaloneDZN
@CaarabaloneDZN Жыл бұрын
Great video
@coinnerd9633
@coinnerd9633 3 жыл бұрын
hey my name is also Victor and I also have a youtube channel! ahahha
@longjohn7992
@longjohn7992 2 жыл бұрын
I’m 69 polys and that deep
OpenGL Tutorial 15 - Stencil Buffer & Outlining
8:20
Victor Gordan
Рет қаралды 26 М.
OpenGL Tutorial 22 - Anti-Aliasing (MSAA)
4:29
Victor Gordan
Рет қаралды 16 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
OpenGL Tutorial 7 - Going 3D
8:01
Victor Gordan
Рет қаралды 51 М.
Basic Shadow Mapping // OpenGL Tutorial #35
16:54
OGLDEV
Рет қаралды 25 М.
OpenGL Tutorial 11 - Types of Light
4:15
Victor Gordan
Рет қаралды 20 М.
OpenGL Tutorial 6 - Textures
9:31
Victor Gordan
Рет қаралды 76 М.
OpenGL Tutorial 19 - Cubemaps & Skyboxes
6:09
Victor Gordan
Рет қаралды 34 М.
OpenGL Tutorial 16 - Face Culling & FPS Counter
4:31
Victor Gordan
Рет қаралды 16 М.
Modern OpenGL Tutorial - Tessellation Shaders
7:59
Victor Gordan
Рет қаралды 20 М.
WebGL 2: Framebuffer Objects (The Basics)
19:43
Andrew Adamson
Рет қаралды 2,1 М.
OpenGL Tutorial 21 - Instancing
4:56
Victor Gordan
Рет қаралды 20 М.
OpenGL Tutorial 13 - Model Loading
14:50
Victor Gordan
Рет қаралды 47 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН