Hello everyone! Welcome to another of my.. posts. Lets talk about 3D rendering, shall we? I don't even remember if I've already made this post anywhere in the past, but screw it, I'll do it anyway. Let me know if you'd like to see a post on how damaged my brain is, haha. Anyway, so, there are couple of main methods of 3D rendering. There is the classic method which involves bunch of matrix multiplication, and then 2 which both involve ray something. So, lets start with the classic multiplication one. Nobody really knows what its called, but I call it the multiplication method, so we will stick to that for now. It basically involves having bunch of faces(polygons), consisting of edges(lines), consisting of 2 verticies(points) each. Basically, lets say we are drawing a simple cube, and there are 6 faces with 4edges each. But we know we don't have to multiply all 24edges, but only the half, because there is only 12 unique verticies in a cube, the other ones are just clones. So, first of all we have to apply 3 famous matrixes to it. Since we are rendering it in 3D, we use 4D matrixes. Quite funny, isnt it? Using 4D to display 3D.. well anyway, these matrixes are called: model matrix, view matrix, projection matrix Lets start with model matrix. Model matrix sets the rotation, position and scale of the model. Its very simple, and there isn't much to it. Then there is the view matrix(also known as world matrix or camera matrix), where things get a bit more interesting. Instead of rotating the model, it rotates the entire view of the camera. So if you rotate the object by 90 degrees trough the model matrix, our cube would remain the same(because 90degrees cube looks the same), but if we did the same trough the view matrix, the cube would become invisible, because we are looking down. If our FOV(field of view) was more than 90degrees however, we would be able to see the cube. Then is the projection matrix. This matrix allows you to change the projection planes, but not much more than that. The difference between view, model and projection matrixes is also that you can set anything preety much to both the model and view matrix and the result projection will propably still be correct(in terms of graphical transformation itself), however with the projection matrix if you set something wrong, the things will propably not look as well. How do we exactly.. multiply the point by the matrix tho? Good question. For it, you use something called a dot product. Lets say we have a simple vector, like this(also good to note I am using row-major here): A B C D E F G H I J K L M N O P and a simple vector X Y Z W The calculation will then work something like this: X2 = X * (A + E + I + M) Y2 = Y * (B + F + J + N) Z2... What is the W component of the so called vector(just a point with the W component added)? The W component is commonly the scaling component and after doing all this matrix vector multiplication, it stores the distance of the verticie to the camera, which is used to create distance map, for example. Now, its still not complete however. Now its time for something called clipping. Clipping is a process where you take all the polygons that you don't need and simply.. discard them or if they are only partially in the image, cut them off correctly. You can still use the multiplied vector outputs for this. What next? Well, its time to convert 4D vectors back to 2D image, and the process is suprisingly simple. You just have to divide the X and Y components(who woul've guessed) by the W component as well as the screen size(In my engine for some reason I am only using half of it.. and I wonder why..) and its almost done. Now the last part we need to do is to convert it into unsigned coordinates. The thing is, the screen now goes from -0.5 to 0.5 instead of 0 to 1. So we just need to add half of the screen size, and done! This calculation looks something like this: pixel(X) = (X2 / W2 / SIZE_X) + HALF_SIZE_X Now you just connect it with lines and done! Now, lets get to raytracing. Basically in raytracing, you simulate how real life light works. The light rays go from the sun(or any other light source), and bounce around to your eye. We are essentially doing the same thing, except opposite. Simply instead of firing bunch of rays from the light source(potentially bilions) and seeing if they land in the camera, we instead fire bunch of rays from the camera(few milions, preety much always multiple per each pixel of the screen) and we check if they reach the light source, and along the way there we check what has the light bounced off of, and what color did that item have, and this allows us to do realistic reflections. How do we check if it collided? Well that depends on what kind of shape it was, but it isn't too hard to do so, but by far the easiest it is for a sphere. What about raymarching? Well, its also very interesting. It works similiar to raytracing, except instead of checking if the ray collides with a shape it always checks where is the closest objects surface to it, travels that distance, and if it passes certain minimum treshold, it takes the objects texture or color, and displays it. If it reaches the maximum treshold, it simply displays the background color. Well, thats about it for today!