Projection Matrices in OpenGL

  Рет қаралды 106,275

The Cherno

The Cherno

Күн бұрын

Пікірлер: 115
@ryanmeyers3863
@ryanmeyers3863 5 жыл бұрын
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!
@_slep
@_slep 5 жыл бұрын
I made the same mistake (heh..) Was getting some really odd shapes being drawn with objects looking like they were smeared across the window
@thatKurtis
@thatKurtis 4 жыл бұрын
Almost did the same, but my brain froze for 2 minutes thinking about exactly this
@jinxblaze
@jinxblaze 4 жыл бұрын
opengl is column major so that fucks things up for me :( im so used to row major
@kiljeaden767
@kiljeaden767 3 жыл бұрын
Thanks brave man, you just saved me half an hour.
@Pdrum2
@Pdrum2 4 ай бұрын
ha, it messed up the numbers
@jrp2k9
@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.
@cykablyat2746
@cykablyat2746 3 жыл бұрын
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.
@rajasbondale6512
@rajasbondale6512 3 жыл бұрын
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-mj7vg
@Micha-mj7vg 3 жыл бұрын
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 )
@gr3yknigh1
@gr3yknigh1 2 жыл бұрын
thanks!
@SwarnimArun
@SwarnimArun 6 жыл бұрын
math! Math! MATH! I want some MATH.
@beProsto
@beProsto 5 жыл бұрын
javidx9 is the guy to go
@JaredThirsk
@JaredThirsk 3 жыл бұрын
It sounds like what you really want are maths.
@sids3194
@sids3194 8 ай бұрын
math....not even once.
@skrolikowski
@skrolikowski 6 жыл бұрын
More theory please. You can find thousands of videos already of people just coding without explanation.
@alanmejia1330
@alanmejia1330 4 жыл бұрын
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
@ASCENDANTGAMERSAGE
@ASCENDANTGAMERSAGE 4 жыл бұрын
I've heard that Graphics Programming:Practices and Principles is good. It's available online for free.
@regbot4432
@regbot4432 4 жыл бұрын
watch 3blue1brown series about linear algebra
@rauldragu9447
@rauldragu9447 3 жыл бұрын
@@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.
@bebekngayang
@bebekngayang 3 жыл бұрын
You can watch code it yourself 3d engine videos on javidx9 youtube channel
@finnbuhse4775
@finnbuhse4775 5 жыл бұрын
Just so everyone knows, he didn't mention that matrix multiplication is NOT commutative, and has to be matrix * vec4
@salihkavaf2864
@salihkavaf2864 3 жыл бұрын
My square wasn't rendering until I realized that I've flipped it in reverse to what it is in the video.
@Dodo17sky
@Dodo17sky 3 жыл бұрын
Thanks a lot. My square wasn't rendering ok until I read your comment
@nerijusvilcinskas7851
@nerijusvilcinskas7851 2 жыл бұрын
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
@nikoszervo
@nikoszervo 6 жыл бұрын
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)!!!!!!!!!!
@no5x937
@no5x937 3 жыл бұрын
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.
@BlackJar72
@BlackJar72 6 жыл бұрын
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-4242
@Jack-4242 6 жыл бұрын
why not just use the GL Matrix Utility functions for inverting matrices?
@BlackJar72
@BlackJar72 6 жыл бұрын
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?
@BichoPragmatico
@BichoPragmatico 5 жыл бұрын
you also have to use orthographic projection when implementing shadow mapping from a sun-like light source (outdoor scene), As "sun rays are parallel "
@violenceisfun991
@violenceisfun991 6 жыл бұрын
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
@vertigo6982
@vertigo6982 5 жыл бұрын
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.
@emanuelkokovics
@emanuelkokovics 3 жыл бұрын
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!
@jairoacosta8940
@jairoacosta8940 5 жыл бұрын
damn man, you saved me from pulling my hair out (edit: once again). thanks.
@not_halls
@not_halls Жыл бұрын
the emotionally motivating music at the start damn
@dmaster20ify
@dmaster20ify 2 жыл бұрын
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.
@timothyvandyke9511
@timothyvandyke9511 4 жыл бұрын
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!
@AxElKo440
@AxElKo440 6 жыл бұрын
I've been looking for this, good video. Thank you
@myaramon
@myaramon 6 жыл бұрын
Hey Yan. You are doing great job. Would you be interestend in making cmake tutorial for us not blessed with Visual Studio on linux? :)
@ianharvey9136
@ianharvey9136 6 жыл бұрын
Fantastic explanation! Thank you.
@Destroyer19941995
@Destroyer19941995 5 жыл бұрын
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.
@Neran280
@Neran280 4 жыл бұрын
glm::perspectivefov();
@vrysk7685
@vrysk7685 6 жыл бұрын
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?
@quaylynrimer11
@quaylynrimer11 5 жыл бұрын
13:39 your example here is not working the same on my machine it still keeps 0 , 0 as the center of the screen
@_slep
@_slep 5 жыл бұрын
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)
@goldenlava1019
@goldenlava1019 4 жыл бұрын
@@_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.
@_slep
@_slep 4 жыл бұрын
@@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)
@goldenlava1019
@goldenlava1019 4 жыл бұрын
@@_slep thanks
@simonvyhnis5813
@simonvyhnis5813 3 жыл бұрын
So many things now make sence..., thanks.
@kaushalchari5686
@kaushalchari5686 2 жыл бұрын
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/
@puyadaravi3109
@puyadaravi3109 4 жыл бұрын
Thank you for the great series! Could you also make a video about how projection works for 3D displays?
@xtiooplus
@xtiooplus 3 жыл бұрын
Nice explaination: 8/10
@tapanotbind
@tapanotbind 4 жыл бұрын
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?
@praveshgaire3437
@praveshgaire3437 6 жыл бұрын
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
@Byynx Жыл бұрын
How do you select and write down in two different places at the same time?
@infinitecmdz
@infinitecmdz 6 жыл бұрын
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?
@bankoftrustnwobot3218
@bankoftrustnwobot3218 5 жыл бұрын
Siddharth P Yes but I would suggest to use quaternions instead of matrices for projection/rotation.
@emanuelkokovics
@emanuelkokovics 3 жыл бұрын
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)?
@SketchpunkLabs
@SketchpunkLabs 6 жыл бұрын
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 :)
@dmitrykolesnikovich
@dmitrykolesnikovich 4 жыл бұрын
What kind of shader language are you using ?
@MaxwellsWitch
@MaxwellsWitch 6 жыл бұрын
Can you do a stencil buffer video?
@user-lk2vo8fo2q
@user-lk2vo8fo2q 6 жыл бұрын
3:32 you were using a projection matrix, right? it's just an identity projection.
@TheCherno
@TheCherno 6 жыл бұрын
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.
@soupman2177
@soupman2177 6 жыл бұрын
What is your favorite soup? your tutorials are amazing.
@10monthspregnant
@10monthspregnant 6 жыл бұрын
BeautifulSoup4
@praveen18p1
@praveen18p1 5 жыл бұрын
Great job !!! very well explained :)
@VoidAshen
@VoidAshen 3 жыл бұрын
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.
@simonbechara2814
@simonbechara2814 5 жыл бұрын
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
@logancheatum8397
@logancheatum8397 2 жыл бұрын
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.
@jakubkawczynski8854
@jakubkawczynski8854 6 жыл бұрын
only 8,5k views and nearly 50 comments? well.. only a few have come this far by seeking better understanding :p
@ryanbinter2447
@ryanbinter2447 6 жыл бұрын
yea im in no hurry to use open GL for a project so i would prefer to understand the underlying things.
@mikamulperi
@mikamulperi 4 жыл бұрын
How to transform so that we have 0,0 on top left?
@mikamulperi
@mikamulperi 4 жыл бұрын
Figured it out myself, just put height to bottom argument : glm::ortho(0.0f, (float)WIDTH, (float)HEIGHT, 0.0f, -1.0f, 1.0f);
@webgpu
@webgpu 6 жыл бұрын
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?)
@pronobroy8389
@pronobroy8389 6 жыл бұрын
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
@k1ngsavage15
@k1ngsavage15 5 жыл бұрын
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?
@bankoftrustnwobot3218
@bankoftrustnwobot3218 5 жыл бұрын
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.
@dwarfda
@dwarfda 4 жыл бұрын
​@@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
@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.
@mario7501
@mario7501 4 жыл бұрын
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
@karlsteinmeister7245
@karlsteinmeister7245 6 жыл бұрын
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.
@wva6809
@wva6809 6 жыл бұрын
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
@szymonwojtala9334
@szymonwojtala9334 6 жыл бұрын
When are you going to start "Game Engine" series?
@Xxp0r
@Xxp0r 6 жыл бұрын
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 :)
@oamost
@oamost 6 жыл бұрын
That's a bit offtopic here.
@jumbledfox2098
@jumbledfox2098 2 жыл бұрын
10x less views than the first video - dont give up, guys!
@wojtekpilwinski
@wojtekpilwinski 6 жыл бұрын
Hello Cherno, I love your tutorials but the music in the background isn't little bit too exaggerated? :)
@lyte69
@lyte69 6 жыл бұрын
thanks for the explanation it was good :).
@sphereman3572
@sphereman3572 4 жыл бұрын
My orthographic matrix rotates it for some reason
@d.a.t.6784
@d.a.t.6784 4 жыл бұрын
Is it just me or is there some creepy breathing sounds in the background right before ~19:00?
@ty_teynium
@ty_teynium 6 жыл бұрын
This involves the world object and view coordinates right?
@BlackJar72
@BlackJar72 6 жыл бұрын
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_teynium
@ty_teynium 6 жыл бұрын
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!
@noneofyourdamnbuisness3484
@noneofyourdamnbuisness3484 5 жыл бұрын
10:02 personal
@IllIlIIllIlIl
@IllIlIIllIlIl 6 жыл бұрын
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.
@navaneeth6157
@navaneeth6157 6 жыл бұрын
who disliked?
@mohammednihad6755
@mohammednihad6755 6 жыл бұрын
💙
@dattatreyapujar4068
@dattatreyapujar4068 5 жыл бұрын
Cool..
@platin2148
@platin2148 6 жыл бұрын
Don't forget to tell them that gl wants the stupid format for matrices and we need to transpose them wich takes time.
@user-lk2vo8fo2q
@user-lk2vo8fo2q 6 жыл бұрын
column major? for whatever reason a lot of scientific libraries do it that way.
@platin2148
@platin2148 6 жыл бұрын
Agenda
@5Gazto
@5Gazto 6 жыл бұрын
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.
@SketchpunkLabs
@SketchpunkLabs 6 жыл бұрын
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.
@giancedrick507
@giancedrick507 4 жыл бұрын
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 :(
@incredibletech5081
@incredibletech5081 3 жыл бұрын
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.hristov
@h.hristov 6 жыл бұрын
Ayy
@mandre96
@mandre96 6 жыл бұрын
I WANT 3D 3D 3D 3D GO GO GO HURRY UP! lol
@L2PTQ
@L2PTQ 6 жыл бұрын
Stop this arm thing at the beginning. What the fuck.
Model View Projection Matrices in OpenGL
15:53
The Cherno
Рет қаралды 90 М.
Perspective Projection Matrix (Math for Game Developers)
29:13
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
БОЙКАЛАР| bayGUYS | 27 шығарылым
28:49
bayGUYS
Рет қаралды 1,1 МЛН
SLIDE #shortssprintbrasil
0:31
Natan por Aí
Рет қаралды 49 МЛН
The Math behind (most) 3D games - Perspective Projection
13:20
Brendan Galea
Рет қаралды 431 М.
Tutorial 9 - Coordinate Systems in OpenGL
7:37
Jeffrey Chastine
Рет қаралды 30 М.
Texture Mapping & Polygon Rasterizing Tutorial (1/2) [C++20]
22:46
Perspective Projection - Part 1 // OpenGL Tutorial #11
24:13
Coding Challenge #112: 3D Rendering with Rotation and Projection
33:13
The Coding Train
Рет қаралды 209 М.
Index Buffers in OpenGL
16:54
The Cherno
Рет қаралды 137 М.
Android game graphics - OpenGL ES vs. Vulkan case study
26:10
Android Developers
Рет қаралды 17 М.
I tried coding my own graphics engine
4:23
Garbaj
Рет қаралды 217 М.
Model View Projection Matrices
16:29
Jamie King
Рет қаралды 96 М.
How Do Computers Display 3D on a 2D Screen? (Perspective Projection)
26:54
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.