The minute I changed my projection matrix to no longer be centered at 0 my triangles were getting drawn in totally bizarre ways... took me half an hour to remember that matrix multiplication order matters and I was multiplying backwards in my vertex shader!
@_slep5 жыл бұрын
I made the same mistake (heh..) Was getting some really odd shapes being drawn with objects looking like they were smeared across the window
@thatKurtis4 жыл бұрын
Almost did the same, but my brain froze for 2 minutes thinking about exactly this
@jinxblaze4 жыл бұрын
opengl is column major so that fucks things up for me :( im so used to row major
@kiljeaden7673 жыл бұрын
Thanks brave man, you just saved me half an hour.
@Pdrum24 ай бұрын
ha, it messed up the numbers
@jrp2k9 Жыл бұрын
The conversion of orthographic projection matrix values from relative to pixel really help explained this concept for me. The quick math demonstration at the end was perfect. Wish I could like the video twice.
@cykablyat27463 жыл бұрын
A few years late but for anyone still watching this, javidx9 has an amazing series where he tackles the graphics pipeline in depth through the use of a console and the power of the CPU.It provides a far more intuitive view over what is actually going on under the hood.
@rajasbondale65123 жыл бұрын
I like how he is also explaining how things far away look smaller. I mean he's just not excluding anyone with different skill levels. Love you
@Micha-mj7vg3 жыл бұрын
If your vertex positions got messed up but everything seems to be alright, it could be bacause of your shader program. instead of gl_Position = position * u_MVP; write gl_Position = u_MVP * position ; as the matrix multiplication is NOT communicative ( mat_1 * mat_2 != mat_2 * mat_1 )
@gr3yknigh12 жыл бұрын
thanks!
@SwarnimArun6 жыл бұрын
math! Math! MATH! I want some MATH.
@beProsto5 жыл бұрын
javidx9 is the guy to go
@JaredThirsk3 жыл бұрын
It sounds like what you really want are maths.
@sids31948 ай бұрын
math....not even once.
@skrolikowski6 жыл бұрын
More theory please. You can find thousands of videos already of people just coding without explanation.
@alanmejia13304 жыл бұрын
Im not sure if youre still interested in this kind of topics but you can read about this in a linear algrebra book (I like linear algebra by grossman) and this other book Mathematics for 3D game programming and computer graphics
@ASCENDANTGAMERSAGE4 жыл бұрын
I've heard that Graphics Programming:Practices and Principles is good. It's available online for free.
@regbot44324 жыл бұрын
watch 3blue1brown series about linear algebra
@rauldragu94473 жыл бұрын
@@regbot4432 and then maybe follow along with javidx9's graphics engine from scratch to see then concepts in action. That how I learned it and I still don't think that there's a better resource out there to truly learn this stuff. The maths and theory is still my favorite thing about 3D graphics.
@bebekngayang3 жыл бұрын
You can watch code it yourself 3d engine videos on javidx9 youtube channel
@finnbuhse47755 жыл бұрын
Just so everyone knows, he didn't mention that matrix multiplication is NOT commutative, and has to be matrix * vec4
@salihkavaf28643 жыл бұрын
My square wasn't rendering until I realized that I've flipped it in reverse to what it is in the video.
@Dodo17sky3 жыл бұрын
Thanks a lot. My square wasn't rendering ok until I read your comment
@nerijusvilcinskas78512 жыл бұрын
This is exactly what I needed in order to understand how to convert SDL2 renderer stuff to OpenGL in my game, thank you so much! Projection Matrices FTW
@nikoszervo6 жыл бұрын
Well before these series it was extremely difficult to learn graphics API'S from the Internet. For some reason there are no good tutorials out there about that stuff even that programming is actually one of the easiest topics to learn through the internet. Very good job! Keep going! (We also can't wait for the Game Engine Series)!!!!!!!!!!
@no5x9373 жыл бұрын
Another GREAT Technical Video Cherno! Much appreciated. More theory with practical application is the BEST teaching style. Theory BEFORE application is necessary for real understand, memory recall, and better applications development.
@BlackJar726 жыл бұрын
Implementing your own projection matrix is very useful; it makes it easy to get the inverse. Getting the inverse very handy for shooting a ray though an arbitrary point on the screen (e.g., to find what's under a mouse pointer).
@Jack-42426 жыл бұрын
why not just use the GL Matrix Utility functions for inverting matrices?
@BlackJar726 жыл бұрын
I don't know how it actually works under the hood -- there is a very slow and complex way of computationally inverting any matrix. But, there is a *much* faster way to get an inverse projection matrix. This is a much simpler and faster formula that can be worked out with pencil and paper and turned into its own function. More efficient than a generic matrix inversion function, which is probably what a utility would use. Besides, where's the fun in letting someone else write everything for you?
@BichoPragmatico5 жыл бұрын
you also have to use orthographic projection when implementing shadow mapping from a sun-like light source (outdoor scene), As "sun rays are parallel "
@violenceisfun9916 жыл бұрын
6:25 reminds me of that episode of Father Ted where he's trying to explain the difference between a small sheep and a far away sheep
@vertigo69825 жыл бұрын
I know some people below dont like the mostly talking and few coding, but I find that style to be the best. It was how my programming teachers in college taught. Basically in the 1 hour 15 minutes of course time it would be on just one topic. 45 minutes of the class to talk about logic and syntax.. do's and don'ts. History of the topic, current status, why its good, etc.. then we would have 30 minutes on the computers to play with the code. You know what you're doing. You know the code and theory.. so you know how complex it is.. If you feel you should do it this way to make sure everyone gets it then thats probably the best way. After all you know more about this stuff then we do.
@emanuelkokovics3 жыл бұрын
It is so weird, because what you say makes sense and it is the same, unless I try to project an image! Practically my image will show if I move the viewing area (12:32) from being centered to being more to the top right part! Anyone else with this problem?At 15:46 with the white square I get same result as Cherno, with the image I get black screen. Anyone with this problem? Maybe the "coordinate system" works differently on my pc (because of my GC), because it seems to handle images differently (not as simple squares), not as in the video!
@jairoacosta89405 жыл бұрын
damn man, you saved me from pulling my hair out (edit: once again). thanks.
@not_halls Жыл бұрын
the emotionally motivating music at the start damn
@dmaster20ify2 жыл бұрын
Love the theory Mr. Cherno. You ave done a great explanation of OpenGL. Like I didn't know that GLU was the one that loaded all those function pointers. I was always confused as to how I could just call these OpenGL functions without loading them from the DLL first. Note GLU has extra functions such as GluPerspective(...). I learnt what the hell are shaders in modern graphics libraries. I learnt about vertex shaders and fragment shaders. I learnt that by using gl buffers you could store memory directly into the GPU. And shaders allow you to write callback functions that run on the GPU.
@timothyvandyke95114 жыл бұрын
I'm very thankful for all this explanation of how things work. I finally have a grasp of what's happening when I type code!
@AxElKo4406 жыл бұрын
I've been looking for this, good video. Thank you
@myaramon6 жыл бұрын
Hey Yan. You are doing great job. Would you be interestend in making cmake tutorial for us not blessed with Visual Studio on linux? :)
@ianharvey91366 жыл бұрын
Fantastic explanation! Thank you.
@Destroyer199419955 жыл бұрын
How do I set up custom screen coordinates in perspective matrix since on the internet I only see width, height, fov and aspect ratio. There is no left and right.
@Neran2804 жыл бұрын
glm::perspectivefov();
@vrysk76856 жыл бұрын
Would like to see an application of the concepts you've gone over, maybe in rendering a basic first person scene, but it's certainly useful to get the theory in a well-packed video too! Maybe another series?
@quaylynrimer115 жыл бұрын
13:39 your example here is not working the same on my machine it still keeps 0 , 0 as the center of the screen
@_slep5 жыл бұрын
Your multiplying the matricies incorrectly, had the same issue. Need to change _position*u_MVP;_ to _u_MVP*position;_ in your basic.shader file (As matricies have a specific order of multiplication in this case)
@goldenlava10194 жыл бұрын
@@_slep Thank you so much, would have never found the problem and probably would have rewritten the entire thing to try to fix it. Because normally it doesn't matter what order you do multiplication.
@_slep4 жыл бұрын
@@goldenlava1019Yeah matricies are odd in the way that they arent commutative (a * b != b * a). Would reccomend looking into a little linear algebra since it shows up a fair bit in graphics programming (3b1b is pretty good)
@goldenlava10194 жыл бұрын
@@_slep thanks
@simonvyhnis58133 жыл бұрын
So many things now make sence..., thanks.
@kaushalchari56862 жыл бұрын
I am trying to use perspective projection instead of orthographic, but it does not seem to work the same way and I am getting weird results. Where can I get an example with perspective projection/
@puyadaravi31094 жыл бұрын
Thank you for the great series! Could you also make a video about how projection works for 3D displays?
@xtiooplus3 жыл бұрын
Nice explaination: 8/10
@tapanotbind4 жыл бұрын
Hi. Why did you say that after projection we have got the coordinates in NDC and in range of [-1,1] while they are in the range of [-w, w] and this space is called 'clip space'. And OpenGL do division by 'w' for us and after that we are in the NDC and in the range [-1,1]. No?
@praveshgaire34376 жыл бұрын
glm::mat4 proj = glm::ortho(0.0f, 960.0f, 0.0f, 540.0f, -1.0f, 1.0f); Are the last two parameters to tell what our normalized ranges are ???? The docs says they are near value and far value, not sure what that means.
@Byynx Жыл бұрын
How do you select and write down in two different places at the same time?
@infinitecmdz6 жыл бұрын
in most cases, you wouldnt be using projection matrix directly with vertices in model/local/world space. Generally, you would have a camera/view space. I think you would then base your projection matrix as a function of your view space, correct?
@bankoftrustnwobot32185 жыл бұрын
Siddharth P Yes but I would suggest to use quaternions instead of matrices for projection/rotation.
@emanuelkokovics3 жыл бұрын
For me using your positions , column 1 and 2 coordinates, makes a rectangles -> that seems to be divided into 4 , and my image gets projected in the right top corner (or on the full rectangle just the left bottom corner of my images is projected). It is weird. Could this be because how my graphics card drivers are handling stuff (implementations)?
@SketchpunkLabs6 жыл бұрын
Just to add an extra example of how Orthographic Projection can be 3D, I've used that sort of projection when I was playing around with isometric camera. For anyone who does not know what an Isometric view is, think Diablo, World Craft 3, sim city. Making games like that, ortho will be your friend :)
@dmitrykolesnikovich4 жыл бұрын
What kind of shader language are you using ?
@MaxwellsWitch6 жыл бұрын
Can you do a stencil buffer video?
@user-lk2vo8fo2q6 жыл бұрын
3:32 you were using a projection matrix, right? it's just an identity projection.
@TheCherno6 жыл бұрын
Not really. An identity matrix is just diagonal 1's, meaning any other matrix multiplied with the identity matrix will result in no change. We never did any matrix multiplication, we just set each vertex position of our geometry to the value stored in the vertex buffer.
@soupman21776 жыл бұрын
What is your favorite soup? your tutorials are amazing.
@10monthspregnant6 жыл бұрын
BeautifulSoup4
@praveen18p15 жыл бұрын
Great job !!! very well explained :)
@VoidAshen3 жыл бұрын
keep it at glm::mat4 proj = glm::ortho(-480.0f, 480.0f, -270.0f, 270.0f, -1.0f, 1.0f); its convenient cuz the origin is still at the center.
@simonbechara28145 жыл бұрын
I enjoyed your clear explanation in the Video, I would like to know how to convert from 3D space coordinates to Screen Coordinates in both Cases, Ortho2D and Perspective, Thx
@logancheatum83972 жыл бұрын
Some people might find this interest but I feel like this is the moment I feel like I actually understand out 3d graphics work on a fundamental level.
@jakubkawczynski88546 жыл бұрын
only 8,5k views and nearly 50 comments? well.. only a few have come this far by seeking better understanding :p
@ryanbinter24476 жыл бұрын
yea im in no hurry to use open GL for a project so i would prefer to understand the underlying things.
@mikamulperi4 жыл бұрын
How to transform so that we have 0,0 on top left?
@mikamulperi4 жыл бұрын
Figured it out myself, just put height to bottom argument : glm::ortho(0.0f, (float)WIDTH, (float)HEIGHT, 0.0f, -1.0f, 1.0f);
@webgpu6 жыл бұрын
After multiplying a vertex position by the projection matrix, is the resulting vertex in clip space or NDC space? (and does this distinction matter in any way?)
@pronobroy83896 жыл бұрын
Result will be in clip space then those vertex will divide by W component (vertex.x/vertex.w, vertex.y/vertex.w, vertex.z/vertex.w) and now it is NDC
@k1ngsavage155 жыл бұрын
I'm so confused on how your rendering a cube with only 4 rows of x, y, z vertices. My cube has 36 rows. I must be missing something important A mat4 matrix is used for 3d shapes, but can only have 4x4 rows and columns, but that's not enough information to render a cube is it?
@bankoftrustnwobot32185 жыл бұрын
I doesn‘t matter how many „rows“ your cube has. Projection is intended for three/two-dimensional shapes (with W for special rotation calculations). For a better understanding I recommend looking at „2blue1brown“ channel videos. He has awesome visualization of projections and rotations. Look for „quaternions“ on his channel.
@dwarfda4 жыл бұрын
@@bankoftrustnwobot3218 although i agree 3b1b videos would help him understand more, quaternions have nothing to do with his question. I believe his problem is, he didn't watch the video about index buffers, hence if hes trying to draw a cube with 6 sides made of 12 triangles, he has to repeat each vertex 3 times for the 3 sides they're connecting. Also he doesn't quite understand matrix multiplication and how matrices actually work.
@Byynx Жыл бұрын
This isn't a cube it's a square. And because he uses a index buffer ti select which vetlrtex will compose the flat square the vertex count is smaller.
@mario75014 жыл бұрын
If you guys are really interested in how the maths behind graphics processing works, javidx9 has a really good series on graphics programming where he dives into the maths :D
@karlsteinmeister72456 жыл бұрын
so in the end it will all have to be floats from -1 to 1... do they _have to_ be like that or is there a way for me to use ints instead? honestly i expect the answer to be no there is no way, but if there is, please let me know... i don't like floats at all. they are too impercise and unpredictable for my likeing (and i would think are more performance hungry since they are formated weridly, unlike ints (or shorts or longs or chars/bytes)). btw cherno, i love the in depth videos, i always hate it when i write code and have no good understanding of what is going on in the background. it also makes it a lot harder to optimize code.
@wva68096 жыл бұрын
You can of course, cast to an int. Try to fiddle around with that, but you won't have ANY control. As, You only have 3 positions to render in. In the left, middle or right
@szymonwojtala93346 жыл бұрын
When are you going to start "Game Engine" series?
@Xxp0r6 жыл бұрын
When do you think you will do a video about exception handling? I saw your vid about smart pointers and you mentioned you didn't like exceptions/would do a video about it :)
@oamost6 жыл бұрын
That's a bit offtopic here.
@jumbledfox20982 жыл бұрын
10x less views than the first video - dont give up, guys!
@wojtekpilwinski6 жыл бұрын
Hello Cherno, I love your tutorials but the music in the background isn't little bit too exaggerated? :)
@lyte696 жыл бұрын
thanks for the explanation it was good :).
@sphereman35724 жыл бұрын
My orthographic matrix rotates it for some reason
@d.a.t.67844 жыл бұрын
Is it just me or is there some creepy breathing sounds in the background right before ~19:00?
@ty_teynium6 жыл бұрын
This involves the world object and view coordinates right?
@BlackJar726 жыл бұрын
Coordinates would be used to transform the projection matrix to see a different areas / look different directions. A world object is something you might build later, though I've built couple beginner graphics engines that didn't use any such concept -- this just has a view port (window), that all it need up to this point.
@ty_teynium6 жыл бұрын
Jared Blackburn I'm sorry I meant object view and world views. I'm hoping that clears it up and thank you for the reply!
@noneofyourdamnbuisness34845 жыл бұрын
10:02 personal
@IllIlIIllIlIl6 жыл бұрын
Please start linking to in-depth resources in the description rather than saying "might do a video on it in the future". Your videos are great but are not as in-depth as they sometimes need to be to understand how something works.
@navaneeth61576 жыл бұрын
who disliked?
@mohammednihad67556 жыл бұрын
💙
@dattatreyapujar40685 жыл бұрын
Cool..
@platin21486 жыл бұрын
Don't forget to tell them that gl wants the stupid format for matrices and we need to transpose them wich takes time.
@user-lk2vo8fo2q6 жыл бұрын
column major? for whatever reason a lot of scientific libraries do it that way.
@platin21486 жыл бұрын
Agenda
@5Gazto6 жыл бұрын
Nice job. However I think that you shouldn't confuse your audience with mingling 2D movement with 3D graphics. You dedicated way too much time on It.
@SketchpunkLabs6 жыл бұрын
You have to spend a little time in the beginning with 2D, because OpenGL is really just 2D by nature. You... the developer, create the 3D content and data, then with the use of the projection matrix flatten it out to be displayed on a 2D canvas. So in the end of the day, all the fancy 3D stuff you make has to be brought back into 2D space. Besides, knowing ortho and the aspect of 2D, this is where you will create many of your UI elements that will live on top of your 3D content. So its all connected.
@giancedrick5074 жыл бұрын
I suppose this is one of the cases where you should make a PowerPoint, because I just replayed the whole video three times just to get it :(
@incredibletech50813 жыл бұрын
This video was very helpfull for my project. i want to donate through brave rewards can you please become a brave reward certified channel. lots of wishes
@h.hristov6 жыл бұрын
Ayy
@mandre966 жыл бұрын
I WANT 3D 3D 3D 3D GO GO GO HURRY UP! lol
@L2PTQ6 жыл бұрын
Stop this arm thing at the beginning. What the fuck.