Alright, time to cover some theory.
3D illusion:
You know how a computer screen is actually a 2D plane? Well how can it convey to our eyes and brain that something is in 3D? It does this by projecting a 3D environment to a 2D plane. This means the usual stuff like how things furhter away from the point of view are smaller, and things closer look bigger. If you have ever stood on abandoned train tracks and looked down you would notice that furthest away the train tracks dissappear into a vanishing point, this is why.
Lights and shadows also sell this illusion of 3D objects. It helps sell depth to an object and locational awareness. A primtive shape like a cube viewed would also just look like a 2D object without shadows and lights exadurating the lines forming the 3d illussion.
Model representation:
3D models are nothing but a bunch of triangles smooshed together in ways to make it's shape. Why triangles? Because triangles are the most effective way to store data, it is only 3 vertices you need to store per triangle. Anyways, 3D model files export from tools such as blender or maya can be exported as sort of giant .txt files. These often include just a list of an objects vertices and indices. This our program can read and build a 3D model.
Color:
Red, green, blue, Alpha.
Red = Red
Green = green
Blue = blue
Alpha = How strong color is
mix and match, colors often stored in vectors, badabing. Badaboom.
Overview of the pipeline:
Input assembler stage:
This stage takes in the data like vertices and indices from its memory and use them to assemble shapes.
*Vertices *
In Direct3D, vertices are stored in vertex buffers. We have to explicitly tell Direct3D how to assemble these points via functions on our commandlist that assign this logic. fore example we can define it as a line list, which interprets two vertices as an individual line, while a triangle strip interprets yknow a triangles, these are connected however, to seperate the triangles you would use a triangle list. This is better explained in the book because Luna provides some great pictures to explain this so if you dont get it. Go buy the book.
Indices
These are lists of often 3 vertices that define how to draw a triangle. If we have point A, B and C. We would define that triangle in our index list as A, B,C. Lets say however that we have another triangle above of our C point and our b point thats connected to this triangles side. Maybe we want to make a rectangle or square? Look at the image
We can define the green triangle as A, B, C on our index list. We can define the right triangle as B, C, D. So now we have reused vertices in our drawing of this square! Obviously reusing elements in computers make it run faster so thats why you want to use index lists like this.
Vertex Shader Stage
After the primitive shapes have been assembled. The vertices are fed into the vertex shader. This is important because vertices dont just hold data related to the location of each point, they can hold data such as, for example how strong the color should be at that vertex. This way you can determine gradient shift in color between two points as you often see in graphics demo examples. Its also important to note that we send of data from the vertex shader to the pixel (fragment) shader, which will be covered later.
Tessellation stage
Tessellation is essentially smart ways to optimize the load that graphics can take on computers. For example level of detail (LOD). Why draw a five-million vertex rich tree thats five thousand kilometers away? Really just a primtive shape at that point would sell the illusion of a tree for viewer looking at the screen. Once we get closer, That tree certainly has to increase in detail however.
Funny thing that I find with optimization with graphics is that it can basically boil down to: "Can the viewer notice?" And if the answer is no, then remove it or reduce its quality.
Geometry shader stage
The geomoetry shader stage is an optional stage, whats unique to this stage is that it can manipulate and even destroy/remove triangles / primitve shapes before shipping it of to the next stage. So it takes a look at the geometry! It doesn't look at the vertices it takes a look at the geometry hence its name.
Clipping
Don't render geometry that the player doesn't see. I just summarized that part for you.
Like geometry (Triangles) out of field of view, thankfully directx12 handles most of this for us.
Rasterization stage
I like to thing of this stage as from the perspective of each individual pixel. Am I inside this triangle? Yes, okay what color am I? etc. It's essentially just computing each individual pixel inside geometry.
Viewport Transform
This is the part were we convert all the weird coordinates and vertices and everything into a 2D plane to sell the illussion.
Backface culling
Important to note that Direct3D by default assumes the order of indices to be clockwise, if the indices end up going counter clockwise, the GPU will interpret them as facing backwards away from the camera. Therefore, it won't be drawn, So always make sure your indices are defined correctly.
Vertex Attribute interpolation
This is basically just talking about how vertices can store more than just positional data. Colours, normal vectors and texture coordinates for example.
Sidenote: I really love Lerp math formula, its probably my favorite formula of all time. CurrentPoint + (TargetPoint - CurrentPoint) * Scalar. Delicious
Pixel Shader Stage*
Pixel shaders are what we write, they are like fragment shaders in OpenGL. Fun stuff indeed. This will be covered more later on.
The output merger stage
Alright so now the final stage. Some pixel fragments might be rejected from our depth or stencil buffer tests. Fragments not rejected get written to a back buffer. Blending tricks can apply here, probably for glass and stuff or like water, seeing through stuff.
Alright that does it for this part, in the next part we will actually get deep into it and get a box rendered onto our screen. Exciting!

Top comments (0)