Perspective Projection - Part 2 // OpenGL Tutorial #12

preview_player
Показать описание


If you want to get the same version that was used in the video checkout the tag TUT_12_PERS_PROJ_2.

🔥 I'm using the following books as background information for my tutorials and I highly recommend them for learning more about OpenGL and Vulkan.
These are affiliate links so if you use them to buy the books the price is the same for you and I will get a small commision (thank-you!).

Timecodes
0:00 Intro
1:08 Background on Aspect Ratio
2:28 Viewport Transform
3:00 Aspect Ratio mapping
4:27 Aspect Ratio code review
8:44 Z transformation
9:21 The Painter’s Algorithm
10:02 The Depth Test
12:03 Range of floating points
14:02 Transforming NearZ/FarZ to -1 and 1
16:24 Transfored Z chart
17:46 Z transform code review
20:11 Conclusion

Feel free to comment below.

Twitter: @ogldev

Credits:

Enjoy,

Etay Meiri

#opengl #ogldev #opengtutorials
Рекомендации по теме
Комментарии
Автор

Your explanations are amazing, that's what really sets you apart from other youtubers or tutorials in general. It's great to watch this series and get more information on topics that were only covered for a really short time in other tutorials. You're doing an amazing job, keep going!

Manuel-gznj
Автор

Thank you so I've been dealing with my scenes stretching due to non-square aspect rations for a WEEK. I literally got two books from my school library just to see if they had something that could help me! I asked three different professors for advice! and you solved my issue in five minutes ;-;

DEFINITELY subscribing!

LaynaStambaugh
Автор

I had trouble understanding other people's explanations, but yours are very clear. Thank you for your videos!

Yolwoocle
Автор

Yes, I enjoy this video 😊. Watching for the 2nd time, better understanding now. Will watch again in the future.

linearz
Автор

I wasn't expecting this level of quality. Thank you so much for your content!

marcosdanieltorres
Автор

Someone asked me a question but for some reason the comment got deleted. I think the question may be interesting to other people so I'll post it here - "I am confused, I guess face culling happens in window space, and after facing culling only rasterization happens. But you mentioned rasterization happens in NDC space".

And the answer is:

OGLDEV
Автор

Legendary teacher this tutorial is pure gold

MrFacciolone
Автор

Hi @OGLDEV . I have a problem where I am trying to convert a point in a 2D image (taken within OpenGL) --> 3D point. I am trying to reverse the transformations that OpenGL does to bring 3D->2D but it is not working exactly. I am interested, how you would approach this problem and if you know if it is possible? Thank you in advance :D

rowanthomas
Автор

In the glm implementation of the projection matrix the elements in the third column seem to be negated when compared to the matrix shown at 16:19. Is there a reason for this.

My code seems to only work with the glm implementation.

nitishmalluru
Автор

Hi! I really cant get why we use the linear function AZ + B for the projection z. What are the meaning A and B constants. I've watched a lot of different videos about the projection matrix theme and i still confused. I'm really don't want to leave this matrix like a blackbox.

Бендер-Задунайский
Автор

Best explanation!! I finally understand

richardj.rustleshyman
Автор

Thank you for the tutorials, they are really good to dive in OGL and CG as well =)
IMHO, if you swap the terms of the denominator in A and B formulas they would look little bit nicer, and should be easier to remember:
A = (Zfar + Znear) / (Zfar - Znear)
B = -2 * (Zfar Znear) / (Zfar - Znear)
also it shows that fact that A is always positive and B is always negative (because Zfar > Znear > 0).

konstantinkozlovtsev
Автор

I cant thank enough sir! These videos are EXCELLENT. You are really good at explaining hard concepts. BTW, you look like Mehdi from ElectroBoom. Are you guys brothers? :P

vectork
Автор

At 17:57, why now you have both "near = 1.0" AND "d =1 / tanHalfFOV" ? From previous video, I thought that near Z plane is exactly defined as "1 / tanHalfFOV". What does the constant "1.0" brings here?

dengan
Автор

you really helped me out thank you!!!!

JohnDoe-kdmw
Автор

at 14:50, why do you do perspective division? shouldn't you solve as is (Az + B) because perspective division by Z will be done automatically after the transformation? the x and y components don't seem to take perspective division into account yet unlike z. why?

syeds
Автор

Hi, I'm having some trouble with the projection matrix... If I don't change it from the identity matrix i still see the spinning cube, but if I do change it to the same matrix as you have it stops showing the cube. I even tried using glm::perspective, but it didn't help.


I should have probably written this comment on the last video, but i thought perhaps something in this video would help me, welp it didnt lmao

xx_sad_dam_whose_sane_xx
Автор

This fixed a lot of issues in my previous code. Previusly, I had to set the Z part in the matrix to 0.9999, so that when it gets divided by w=1, it won't be exactly 1 - which got clipped for me. Now I could also disabe face culling, since depth test could do its job perfectly.

johetajava
Автор

redirect from ogldev.org, thanks for all your posts on ogldev. one question here, looks like the notation for the perspective matrix is based on LH along with the view matrix, opengl uses RH, the third column should be multiplied by -1?

hunterize
Автор

I know that this z projection gives greater accuracy at close range (which is often desireable), but could you not theoretically do it linearly just by making Zt = 2*( (Z - Near)/(Far - Near) ) - 1 ?

kerbalcadet