as a maths teacher from germany i have to admit i wish i could explain like u do. i dont remember understanding a new topic that quick. thank you, great work! :)
i took a break for a while, came back somehow understanding ALL of what i learned, you are a great teacher! thank you for the tutorial, this made it quite clear for me, by far one of the coolest videos in the series! like you answered the EXACT questions i had.
I know you want to keep it simple and on point. Though the "perspective divide" is generally called the homogeneous divide. We use homogeneous coordinates because "normal" cartesian coordinates and matrix multiplication can't represent translation or projection. The idea of homogeneous coordinates is that we simply go one dimension higher and offset our desired coordinate system by one unit in that new dimension. That's why points in space have "w" set to 1. So the whole 3d coordinate space simply lives at a 3d "sliver" of 4d space, at a distance of 1 from the origin. Matrix multiplications still can't do translations, however we can do a shear operation in 4d space. Since our 3d space that we are interested in is at distance 1, when applying a shear, our "flat" 3d space within the 4d space would appear to have shifted. So we actually want to keep our coordinate space at a "w" distance of 1 at all times. So if w contains a value different from 1, we "normalize" our coordinates by dividing the whole vector by w. Yes, this division is hardcoded into the rendering pipeline. This simple convention allows us all sorts of things to represent with just matrices and since you can combine matrices this is super efficient for more complex setups. If you have trouble understanding 4d coordinates, homogeneous coordinates also work for 2d coordinates in the same way. When you have 2d coordinates in a 2d plane, we simply offset them by 1 in the z direction. By applying a shear, we can move the 2d coordinate system around. This concept also applies to higher dimensions. So when you want to represent actual 4d space, we can use 5x5 matrices to do the translation and projection down into 3d space.
Thanks for the comment. I actually think that 'perspective division' is a bit more common and this is how it's called in the OpneGL spec, but both terms are fine.
Now a lot of things make sense. Please tell me from where I can learn more about these things. I am working on 3D renderer and it is very difficult for me.
I'm a bit late to the party, but this video finally made this stuff click for me - thank you! I've been reading textbooks and trying to understand for a couple weeks now, and your explanation made it finally made sense. Thank you for making these learning resources :)
I'm learning OpenGL using Joey de Vries book and this video was a great complement for me to really understand what was going on. I will probably watch the whole series, thank you!
My mind is _blown!_ Your way of explanation is truly amazing. It was very intuitive and everything just clicked into place for me. Thank you so much for putting out this content. Instantly subscribed!
great video saved me from depression i was llooking like every where for two days and a 20 minute video made it look easy it would be great if you did a video about the whole row-major vs column-major difference and how do i know what matrix to multiply first. like i have no idea what happens when i multiply the translation first but it just doesnt work unless i re order the projection matrix to look like a column-major one
Thanks! I'll add the row/column major topic to the TODO list. Regarding matrix multiplication order - please check out my video ruclips.net/video/gdlu6EEWm2I/видео.html. I think it should address your question.
My man thank you very for the tutorial you are the real MVP and not those matrices I'm learning opengl on my own with no computer science background and this small series in cameras has been the real deal for me, keep it up, try to be a little more dynamic and I am sure that the channel will go very far :)
Thanks! I wish I was able to publish more frequently but it's very difficult with a full time job and a few kids. Maybe in the future I'll be able to work on this full time and publish every week. Kind of a chicken and an egg problem...
your videos are a great help.. just one query... i have applied your same code your code works fine... but then i applied your code for a mesh data given. without projection matrix it works fine like it should work..but then i apply the projection matrix the screen goes black..i applied different angles wide and small..for angle 180 i can see something appearing in my screen...but seems like instead of getting a solid mesh i see lines coming out towards screens..seems like from a far depth for all other angles i barely see something on screen..i also tried changing the depth using the translation matrix nothing worked... any suggestion would be great help...
What is the range of the vertices of the problematic range on all the axis? I don't think you should work with an angle of 180 because it seems the frustum will be weird in this case (not a pyramid). Stay with 45 degrees and check the z range of the vertices. Perhaps they are being clipped on the near and far z.
@@OGLDEV thank you very much for the reply.. my range of the given mesh data for x(-18,20) for y(-20,25) for z(-32,32) these are approximations.. what i did is i scaled my points to 0.01 so that they become inside -1,1 and then tried applying your projection matrix... also i watched many lecture they say camera is at origin then how are we able to see positive z values since camera facing towards neg z axis... so much confusion can you provide the links from where i can have better understanding of how to modify the protection matrix according to ones need...
You are not supposed to scale the positions by 0.01 and then apply projection because you may end up with degenerate triangles. Perspective projection should bring the visible vertices into the [-1,1] range. I take a somewhat different path from other sources and I teach perspective projection before the camera transform so when you are on tutorial 11/12 you need to ignore the camera which is explained in tutorials 13-15. The camera must indeed be at the origin when you apply pers proj but since we have no notion of a camera at this point you can assume that it is there by default. The other lecture probably assume that you are using a right handed coordinate system with the camera looking down along the -z. This is indeed confusing. I'm using a left handed coordinate system. From the top of my head I think you just need to replace 1 in location [4,3] with -1 to switch from left hand to right hand. A couple of resources that may help you here are www.songho.ca/opengl/gl_projectionmatrix.html and www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix
@@OGLDEV ohh thank you very much sir... that clears my doubt...because the libraries that already are there like glm library i think they use right hand rule... and reading from different different resources had confused my understanding..thank you that cleared...my doubt
just one more question that is eating up my head.. the near and far plane are always on negative z axis according to right hand convention...and so my screen will clip only what's inside the frustum..my question is ...that what happens to positive z coordinates... as they are not inside our frustum they will not be displayed right? so for taking care of that do we have to translate all our object coordinates in negative z direction so that now our object is in the near and far plane range.
The camera is at the origin and it can only point at either the positive or negative half of the coordinate system. So in the right handed the negative Z is in front of you and the negative Z is behind you and must be clipped.
I wasn't able to get it to work until I used the glm library and used glm::perspective. The matrix glm::perspective creates is very different from your Projection matrix. How did you get yours to work without specifying a far or near clip plane? Why is the Z value on the 4th row 1 instead of -1? Thanks again for your videos, despite my shortcuts I still wouldn't have been able to get as far as I have without them.
The near/far clip planes are handled in the second part of this video. Once completed, you should find my matrix and the one by GLM almost the same (at least that's what I remember from the last time I checked...). The difference in the sign of Z is due to the right handedness of GLM vs my left handedness.
Hello Etay, thanks for the series. Could you please explain, why in projected point we set z_p to be equal to 1 instead of d? At time 9:52 you pointed out that z_p = d, but then from the final matrix 12:35 it is easy to see that z_p will be equal to 1 after division by z.
The projection matrix is composed of two completely independent transformations - projection of X&Y for the illusion of 3D and mapping of Z to -1 to 1 between the near and far Z. In this video we handle the first one and in the next one we handle the second. So right now the final matrix looks like that because we are still not mapping the Z properly.
What do you mean by 'abstract algebra'? sets, vector spaces, fields, etc? The purpose of OpenGL is visualization. If you can visualize something you can do it with OpenGL.
@6:00 What if the camera is located at the same y value as the objects that are being projected? the lines from the top of each object would just be parallel and they wouldn't be scaled down in the perspective view, right? Or am I more confused than I thought lol. Thanks!
The fact that the camera and the objects have the same Y value just means they are at the same "height". Whether or not the objects are visible depends on their relation to the frustum and for that we need to know the target vector.
@@OGLDEV gotcha, So In my example let’s say the objects are people who are the same size, if I wanted a 3rd person view from the perspective of one of the people, I’d have to set the viewing plane to be above and behind the head of the person, right? If I wanted a 1st person perspective, the viewing plane would be in front of the person, and at the same height(y value) right? So in that case, the farther objects wouldn’t appear smaller, is that right? Thanks!! 🙏
With perspective projection the further the object the smaller it looks, same as with regular human vision. Whether this is 1st person or 3rd person view is just a matter of whether the camera is "inside" the character or hovering a bit above.
This is explained in part 2 of the perspective projection tutorial (next one on the playlist). In this video I only talk about making X and Y dependent on the distance from the object and the aspect ratio and the normalization of the Z is handled in the next one.
Difficult to say, what do you have as the original Z value in the vertex? Does it work without the perspective matrix? Please try to compare your code to my code from the repo. If you can't find the problem you can send it to me and I'll try to find some time to take a look.
this is very nice explanation. you describe everything in detail.is that possible that you go further, and provide tutorials also in gaming, like realtime graphics, game development? or maybe like what thinmatrix did, but he did it in java, not c++.
Thanks! The plan for the next few months is to focus on various 3D techniques. From there branching to game development is definitely something that I'm considering.
@@OGLDEV thank you very much,.that would be amazing.cause any game development tutorial i found was with java and opengl.no one was with c++ and opengl.
@@OGLDEV thank you very much for the adivce,i will follow it later,but i could not see any visual results in his tutorials,thats not im not following it yet.like in thimatrix,there will be a game,an environment,something visual,for him it was some cubes...but i will go for it.thanx
@Sara nh I watched the first few episodes of his game engine series and they are mostly about setting up all the infra structure of the engine. I think that is expected because there is a lot of infra structure in such sw. I haven't followed the entire series but I noticed lately that he started doing effects like bloom, lighting, etc so I guess there is something to see. I hope I'll be able to find time to watch it...
@OGLDEV basically, when the object goes to the side of the viewport, it gets heavily distorted, i tried reducing the fov but that doesn't seem to work.
Changing the angle causes a zoom in/out effect, so you may want to compensate that in the Z of the translation matrix so that the object will not be too close or too far away. I have a feeling the problem is with the Z. Since you can see the mesh without projection the X and Y are probably already in the -1 to 1 range.
also one more qsn you haven't use depth buffer...and enable depth tests.. when i tried doing it..your code showed black screen what could be the reason for that?
I recently realized that I may have delayed the depth test too long so I've added it to the next tutorial which will be out in a few days. It shouldn't be a problem as long as you use simple models like the cube because back face culling will take care of the depth test. Which tutorial showed a black screen with the depth test?
OK, so it probably has something to do with the fact that tutorial 11 is missing the Z transformation which is explained in tutorial 12. I guess when the depth test is enabled most of the vertices end up being clipped. Try to enable the depth test in tutorial 12.
Hello Etay, I have been following the series sequentially and you have been clearing the whole concepts for me, Thanks! Until this video, I faced no issues at all, however, I can now see nothing on my screen, complete Black window, no errors, no issues at all. I changed many things in the Transformation matrices, but still got no results. I am using Visual Studio 2022 on Windows 10. Please would you help me out? I am crying my brains out why this doesn't work. Here is a more detailed Problem : When all three matrices are just identity matrices, I can see the the square / cube. I add Rotation, along the z axis, it starts rotating, but looks weird. I add Translation to Z, it starts moving left and right. I change Projection[0][0] and Projection[1][0] to 'f', it still acts like the identity Projection Matrix. But, when I set the Projection[3][3] to zero. It all goes blank.
Are rotation and translation working as expected without projection? Note that the order of transformations matters. I have a video about that. Regarding projection - try to compare your matrix to mine. What is the FOV that you are using? Note that Projection[1][0] should be zero while [1][1] should be f.
@@OGLDEV Rotation Works, the Translation, instead of moving the camera far away, the complete Cube moves sideways. But atleast I can see something on the screen. With Projection, its black. The order is also correct. Referred to your previous videos. I have now copied the exact code you have, except, I am using glm and not your library. All the matrices are exact as same as you. The FOV is 90 degrees, before converting it to radians. I do use glm::radians to convert.
I think it's critical to get the translation along Z working correctly because the projection works by dividing X and Y by Z. If the object moves sideways when Z is changed then it may break everything. Start with a basic sample that renders a single triangle (bottom left corner of the screen, top center and bottom right). The camera should be at the origin and facing the Z axis. Apply the projection and start moving the triangle along Z. The simple projection matrix in this video should make it smaller as it moves away. There is no near/far Z at this point which is explained in the next video. Note that without near/far Z mapping the valid range for Z is -1.0 to 1.0 so make sure not to go outside of this range. You can see that in my sample the Z is +0.5 or -0.5 for the vertices of the cube. If you change this to +1.5 and -1.5 you will also get a blank screen every now and then.
You look like Electroboom if he was more interested in 3D graphics GPUboom lol Other than that, I find this video very helpful, as perspective projection is the hardest thing for me to setup.
as a maths teacher from germany i have to admit i wish i could explain like u do. i dont remember understanding a new topic that quick. thank you, great work! :)
Thanks a lot!
i took a break for a while, came back somehow understanding ALL of what i learned, you are a great teacher! thank you for the tutorial, this made it quite clear for me, by far one of the coolest videos in the series! like you answered the EXACT questions i had.
Thanks!
I know you want to keep it simple and on point. Though the "perspective divide" is generally called the homogeneous divide. We use homogeneous coordinates because "normal" cartesian coordinates and matrix multiplication can't represent translation or projection. The idea of homogeneous coordinates is that we simply go one dimension higher and offset our desired coordinate system by one unit in that new dimension. That's why points in space have "w" set to 1. So the whole 3d coordinate space simply lives at a 3d "sliver" of 4d space, at a distance of 1 from the origin. Matrix multiplications still can't do translations, however we can do a shear operation in 4d space. Since our 3d space that we are interested in is at distance 1, when applying a shear, our "flat" 3d space within the 4d space would appear to have shifted. So we actually want to keep our coordinate space at a "w" distance of 1 at all times. So if w contains a value different from 1, we "normalize" our coordinates by dividing the whole vector by w. Yes, this division is hardcoded into the rendering pipeline. This simple convention allows us all sorts of things to represent with just matrices and since you can combine matrices this is super efficient for more complex setups.
If you have trouble understanding 4d coordinates, homogeneous coordinates also work for 2d coordinates in the same way. When you have 2d coordinates in a 2d plane, we simply offset them by 1 in the z direction. By applying a shear, we can move the 2d coordinate system around. This concept also applies to higher dimensions. So when you want to represent actual 4d space, we can use 5x5 matrices to do the translation and projection down into 3d space.
Thanks for the comment. I actually think that 'perspective division' is a bit more common and this is how it's called in the OpneGL spec, but both terms are fine.
Now a lot of things make sense. Please tell me from where I can learn more about these things.
I am working on 3D renderer and it is very difficult for me.
Amazing that this has so few views - I couldn't find a good explanation of projection matrices until I stumbled on this. Great work!
Thanks a lot for your feedback!
Thank you for the clarity and precise word choices.
You're welcome :-)
Wow this is the most thorough video about the subject I've seen so far, it's really good, you explain things very well. Thank you
You're very welcome!
I'm a bit late to the party, but this video finally made this stuff click for me - thank you! I've been reading textbooks and trying to understand for a couple weeks now, and your explanation made it finally made sense.
Thank you for making these learning resources :)
Glad it was helpful!
I'm learning OpenGL using Joey de Vries book and this video was a great complement for me to really understand what was going on. I will probably watch the whole series, thank you!
Thanks and good luck!
My mind is _blown!_ Your way of explanation is truly amazing. It was very intuitive and everything just clicked into place for me.
Thank you so much for putting out this content. Instantly subscribed!
Glad it was helpful!
Best OpenGl tutorials that I have seen. Thanks !!!
Thank you!
Best opengl tutorial I've ever seen!
Thank you!
great video saved me from depression i was llooking like every where for two days and a 20 minute video made it look easy
it would be great if you did a video about the whole row-major vs column-major difference and how do i know what matrix to multiply first.
like i have no idea what happens when i multiply the translation first but it just doesnt work unless i re order the projection matrix to look like a column-major one
Thanks! I'll add the row/column major topic to the TODO list. Regarding matrix multiplication order - please check out my video ruclips.net/video/gdlu6EEWm2I/видео.html. I think it should address your question.
My man thank you very for the tutorial you are the real MVP and not those matrices
I'm learning opengl on my own with no computer science background and this small series in cameras has been the real deal for me, keep it up, try to be a little more dynamic and I am sure that the channel will go very far :)
Thanks! I wish I was able to publish more frequently but it's very difficult with a full time job and a few kids. Maybe in the future I'll be able to work on this full time and publish every week. Kind of a chicken and an egg problem...
good explanation with 2d and 3d definition
Thanks :-)
your videos are a great help..
just one query... i have applied your same code your code works fine...
but then i applied your code for a mesh data given. without projection matrix it works fine like it should work..but then i apply the projection matrix the screen goes black..i applied different angles wide and small..for angle 180 i can see something appearing in my screen...but seems like instead of getting a solid mesh i see lines coming out towards screens..seems like from a far depth for all other angles i barely see something on screen..i also tried changing the depth using the translation matrix nothing worked...
any suggestion would be great help...
What is the range of the vertices of the problematic range on all the axis? I don't think you should work with an angle of 180 because it seems the frustum will be weird in this case (not a pyramid). Stay with 45 degrees and check the z range of the vertices. Perhaps they are being clipped on the near and far z.
@@OGLDEV thank you very much for the reply..
my range of the given mesh data for x(-18,20) for y(-20,25) for z(-32,32) these are approximations.. what i did is i scaled my points to 0.01 so that they become inside -1,1 and then tried applying your projection matrix...
also i watched many lecture they say camera is at origin then how are we able to see positive z values since camera facing towards neg z axis... so much confusion
can you provide the links from where i can have better understanding of how to modify the protection matrix according to ones need...
You are not supposed to scale the positions by 0.01 and then apply projection because you may end up with degenerate triangles. Perspective projection should bring the visible vertices into the [-1,1] range. I take a somewhat different path from other sources and I teach perspective projection before the camera transform so when you are on tutorial 11/12 you need to ignore the camera which is explained in tutorials 13-15. The camera must indeed be at the origin when you apply pers proj but since we have no notion of a camera at this point you can assume that it is there by default. The other lecture probably assume that you are using a right handed coordinate system with the camera looking down along the -z. This is indeed confusing. I'm using a left handed coordinate system. From the top of my head I think you just need to replace 1 in location [4,3] with -1 to switch from left hand to right hand. A couple of resources that may help you here are www.songho.ca/opengl/gl_projectionmatrix.html and www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix
@@OGLDEV ohh thank you very much sir... that clears my doubt...because the libraries that already are there like glm library i think they use right hand rule... and reading from different different resources had confused my understanding..thank you that cleared...my doubt
You can choose the type of the coordinate system in glm using glm::frustumLH and glm::frustumRH
You are a _fantastic_ teacher, thank you so much for sharing your knowledge!
all the best,
Thank you Jack!
just one more question that is eating up my head..
the near and far plane are always on negative z axis according to right hand convention...and so my screen will clip only what's inside the frustum..my question is ...that what happens to positive z coordinates... as they are not inside our frustum they will not be displayed right?
so for taking care of that do we have to translate all our object coordinates in negative z direction so that now our object is in the near and far plane range.
The camera is at the origin and it can only point at either the positive or negative half of the coordinate system. So in the right handed the negative Z is in front of you and the negative Z is behind you and must be clipped.
Wow, thank you for this video. Everything is explained so clearly!
Your'e welcome :-)
Thanks! Great explanation from first principles
You're welcome :-)
So cool. Love the breakdown. It clarify a lot for me. Thank you !
Glad it was helpful!
actually really interesting and helpful! am looking forward to the next video!
Thank you! It will be ready in a few days.
I wasn't able to get it to work until I used the glm library and used glm::perspective. The matrix glm::perspective creates is very different from your Projection matrix. How did you get yours to work without specifying a far or near clip plane? Why is the Z value on the 4th row 1 instead of -1? Thanks again for your videos, despite my shortcuts I still wouldn't have been able to get as far as I have without them.
The near/far clip planes are handled in the second part of this video. Once completed, you should find my matrix and the one by GLM almost the same (at least that's what I remember from the last time I checked...). The difference in the sign of Z is due to the right handedness of GLM vs my left handedness.
Hello Etay, thanks for the series.
Could you please explain, why in projected point we set z_p to be equal to 1 instead of d?
At time 9:52 you pointed out that z_p = d, but then from the final matrix 12:35 it is easy to see that z_p will be equal to 1 after division by z.
The projection matrix is composed of two completely independent transformations - projection of X&Y for the illusion of 3D and mapping of Z to -1 to 1 between the near and far Z. In this video we handle the first one and in the next one we handle the second. So right now the final matrix looks like that because we are still not mapping the Z properly.
Hey, how exactly you've exported vertex coordinates and indices from blender?
I usually export to obj from Blender.
Thanks
very very good lecture
better than my prof
lol! Thanks :-)
amazing, explanation.
Thank you!
hi Mr OGL, hv u implement abstract algebra in opengl?
What do you mean by 'abstract algebra'? sets, vector spaces, fields, etc? The purpose of OpenGL is visualization. If you can visualize something you can do it with OpenGL.
@@OGLDEV Nice, Thanks!
@@abdullahazam-yf3qw You're welcome :-)
@6:00 What if the camera is located at the same y value as the objects that are being projected? the lines from the top of each object would just be parallel and they wouldn't be scaled down in the perspective view, right? Or am I more confused than I thought lol.
Thanks!
The fact that the camera and the objects have the same Y value just means they are at the same "height". Whether or not the objects are visible depends on their relation to the frustum and for that we need to know the target vector.
@@OGLDEV gotcha,
So In my example let’s say the objects are people who are the same size, if I wanted a 3rd person view from the perspective of one of the people, I’d have to set the viewing plane to be above and behind the head of the person, right? If I wanted a 1st person perspective, the viewing plane would be in front of the person, and at the same height(y value) right? So in that case, the farther objects wouldn’t appear smaller, is that right?
Thanks!! 🙏
With perspective projection the further the object the smaller it looks, same as with regular human vision. Whether this is 1st person or 3rd person view is just a matter of whether the camera is "inside" the character or hovering a bit above.
Super tuto !!!!!! j'ai hâte de voir le prochain . Merci à toi !!! J'oubliais , tu parles bien le français ?
Merci! Je parle français uniquement avec google translate ;-)
@@OGLDEV ok ;-) thanks
@MO 9845 don't worry, i can speak to @oglDev in english, i really thought @oglDev speaks french ;-)
thanx ogldev!!
You're welcome!
Awesome series!
Thanks Antoine!
21:42 , when z will be divided by w it willl became 1 , so how this depth imformation is preserved ?
This is explained in part 2 of the perspective projection tutorial (next one on the playlist). In this video I only talk about making X and Y dependent on the distance from the object and the aspect ratio and the normalization of the Z is handled in the next one.
@@OGLDEVThanks for rply. I am doing same but my output is black screen only even after model translated to 3 ,as you did. What I am doing wrong ?
Difficult to say, what do you have as the original Z value in the vertex? Does it work without the perspective matrix? Please try to compare your code to my code from the repo. If you can't find the problem you can send it to me and I'll try to find some time to take a look.
this is very nice explanation. you describe everything in detail.is that possible that you go further, and provide tutorials also in gaming, like realtime graphics, game development? or maybe like what thinmatrix did, but he did it in java, not c++.
Thanks! The plan for the next few months is to focus on various 3D techniques. From there branching to game development is definitely something that I'm considering.
@@OGLDEV thank you very much,.that would be amazing.cause any game development tutorial i found was with java and opengl.no one was with c++ and opengl.
The Cherno has a good series on game engine development in C++ - ruclips.net/p/PLlrATfBNZ98dC-V-N3m0Go4deliWHPFwT
@@OGLDEV thank you very much for the adivce,i will follow it later,but i could not see any visual results in his tutorials,thats not im not following it yet.like in thimatrix,there will be a game,an environment,something visual,for him it was some cubes...but i will go for it.thanx
@Sara nh I watched the first few episodes of his game engine series and they are mostly about setting up all the infra structure of the engine. I think that is expected because there is a lot of infra structure in such sw. I haven't followed the entire series but I noticed lately that he started doing effects like bloom, lighting, etc so I guess there is something to see. I hope I'll be able to find time to watch it...
Very easy to understand ^o^
Glad it helped!
I keep getting perspective distortion, how do i fix this?
What's the nature of the distortion? What's the contents of the projection matrix?
@OGLDEV basically, when the object goes to the side of the viewport, it gets heavily distorted, i tried reducing the fov but that doesn't seem to work.
OK, and how does the projection matrix looks like? Try using a square window do disable interference of the aspect ratio.
or can you just tell me...what should we take care of while changing the angle and the depth in translation matrix
Changing the angle causes a zoom in/out effect, so you may want to compensate that in the Z of the translation matrix so that the object will not be too close or too far away. I have a feeling the problem is with the Z. Since you can see the mesh without projection the X and Y are probably already in the -1 to 1 range.
also one more qsn you haven't use depth buffer...and enable depth tests..
when i tried doing it..your code showed black screen what could be the reason for that?
I recently realized that I may have delayed the depth test too long so I've added it to the next tutorial which will be out in a few days. It shouldn't be a problem as long as you use simple models like the cube because back face culling will take care of the depth test. Which tutorial showed a black screen with the depth test?
@@OGLDEV your code for this tutorial which i found on github..
OK, so it probably has something to do with the fact that tutorial 11 is missing the Z transformation which is explained in tutorial 12. I guess when the depth test is enabled most of the vertices end up being clipped. Try to enable the depth test in tutorial 12.
Hello Etay, I have been following the series sequentially and you have been clearing the whole concepts for me, Thanks!
Until this video, I faced no issues at all, however, I can now see nothing on my screen, complete Black window, no errors, no issues at all. I changed many things in the Transformation matrices, but still got no results. I am using Visual Studio 2022 on Windows 10. Please would you help me out? I am crying my brains out why this doesn't work.
Here is a more detailed Problem :
When all three matrices are just identity matrices, I can see the the square / cube.
I add Rotation, along the z axis, it starts rotating, but looks weird.
I add Translation to Z, it starts moving left and right.
I change Projection[0][0] and Projection[1][0] to 'f', it still acts like the identity Projection Matrix.
But, when I set the Projection[3][3] to zero. It all goes blank.
Are rotation and translation working as expected without projection? Note that the order of transformations matters. I have a video about that. Regarding projection - try to compare your matrix to mine. What is the FOV that you are using? Note that Projection[1][0] should be zero while [1][1] should be f.
@@OGLDEV Rotation Works, the Translation, instead of moving the camera far away, the complete Cube moves sideways. But atleast I can see something on the screen. With Projection, its black. The order is also correct. Referred to your previous videos.
I have now copied the exact code you have, except, I am using glm and not your library. All the matrices are exact as same as you.
The FOV is 90 degrees, before converting it to radians. I do use glm::radians to convert.
I think it's critical to get the translation along Z working correctly because the projection works by dividing X and Y by Z. If the object moves sideways when Z is changed then it may break everything. Start with a basic sample that renders a single triangle (bottom left corner of the screen, top center and bottom right). The camera should be at the origin and facing the Z axis. Apply the projection and start moving the triangle along Z. The simple projection matrix in this video should make it smaller as it moves away. There is no near/far Z at this point which is explained in the next video. Note that without near/far Z mapping the valid range for Z is -1.0 to 1.0 so make sure not to go outside of this range. You can see that in my sample the Z is +0.5 or -0.5 for the vertices of the cube. If you change this to +1.5 and -1.5 you will also get a blank screen every now and then.
can i get this code completely in pdf form
Have you tried using one of the online tools to convert code to pdf?
This tutorial is lovely amazing :D
Thank you!
You look like Electroboom if he was more interested in 3D graphics
GPUboom lol
Other than that, I find this video very helpful, as perspective projection is the hardest thing for me to setup.
And we have almost the same number of subscribers ;-)
could you get away with just dividing by Z
Division by Z is indeed the core of projection. The other parts of the matrix are for field of view, aspect ratio and Z transformation.
how to install ogldev_math_3d.h
It's in the git repo github.com/emeiri/ogldev
In the Include directory.