You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/1-introduction/1-3-basics/1-3-3-setting-up-3d-rendering.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Now that we know how to work with simple predefined 2D geometry, it's time to take the next step.
4
4
5
-
Here we're dive into the 3rd dimension, but before we do that, we need to explain some things we're going to need in order to properly display a 3D object.
5
+
Here we dive into the 3rd dimension, but before we do that, we need to explain some things we're going to need in order to properly display a 3D object.
6
6
7
7
In this chapter we'll talk about the following items:
8
8
@@ -14,7 +14,7 @@ Because our screen is 2D, we need to be able to "transform" our 3D model into a
14
14
15
15
## The Math
16
16
17
-
For this we'll need to take a light dive into "Matrix Math", whilst understanding the math behind it all can be really helpful (especially once you start doing more advanced stuff), We'll use a library for all of this and only stick to top-level concepts as not to make this tutorial a math-lesson.
17
+
For this we'll need to take a light dive into "Matrix Math", whilst understanding the math behind it all can be really helpful (especially once you start doing more advanced stuff), we'll use a library for all of this and only stick to top-level concepts as not to make this tutorial a math-lesson.
18
18
19
19
The "Transformation" we're concerned with is composed out of a set of multiple matrices:
20
20
@@ -65,17 +65,17 @@ And our 3D object will use the resulting model matrix:
Because all these main matrix multiplications happen infrequently enough, we "can" do this on the CPU, we only have to recalculate the matrices of 3D objects when/if they move/scale/rotate which for most level geometry is almost never. However...
68
+
Because all these matrix multiplications happen infrequently enough, we "can" do this on the CPU, we only have to recalculate the matrices of 3D objects when they move/scale/rotate which for most level geometry is almost never. However...
69
69
70
70
The only exception is the camera, which tends to move almost every frame, however we tend to only have 1 of them (or an insignificant amount in other cases).
71
-
The keen readers might realize that because of the the fact that we recalculate the camera matrix, we have to recalculate the world matrix for 'every' 3D object.
71
+
The keen readers might realize that because of the fact that we recalculate the camera matrix, we have to recalculate the world matrix for 'every' 3D object.
72
72
73
73
What we cannot do however (or well, not with high-poly objects) is transform every vertex on the CPU with the world matrix, luckily GPU's are practically built for this and thus are very good at it.
74
74
But that means we need a way to get the matrix we need over there somehow.
75
75
76
76
## Constant Buffers
77
77
78
-
In D3D11 we have a thing called "Constant Buffers", this is special buffer to contain values that the GPU can expect not to change during a draw call, this means the values are "constant" or "uniform" for the entire shader invocation.
78
+
In D3D11 we have a thing called a "Constant Buffer", this is a special buffer that contains values that the GPU can expect not to change during a draw call, this means the values are "constant" or "uniform" for the entire shader invocation.
79
79
This is a great place to put our matrix.
80
80
81
81
In `CreateConstantBuffers()` we create our buffer pretty much the same as we did our vertex buffer back in Hello Triangle, except now in the BindFlags, we specify D3D11_BIND_FLAG::BIND_CONSTANT_BUFFER
@@ -124,15 +124,15 @@ The syntax for this is a little bit different than we're used to in C/C++ but si
124
124
125
125
cbuffer PerFrame : register(b0)
126
126
{
127
-
row_major matrix viewprojection;
127
+
matrix viewprojection;
128
128
};
129
129
130
130
cbuffer PerObject : register(b1)
131
131
{
132
-
row_major matrix modelmatrix;
132
+
matrix modelmatrix;
133
133
};
134
134
135
-
We basically declare and define our structure in a single line, `cbuffer` tells the shader it will be a Constant Buffer (and expect the structurelike layout), followed by the name of the object `PerFrame`/`PerObject` and lastly which slot to expect it on `: register(b0)`
135
+
We basically declare and define our structure in a single line, `cbuffer` tells the shader it will be a Constant Buffer (and expect the structure-like layout), followed by the name of the object `PerFrame`/`PerObject` and lastly which slot to expect it on `: register(b0)`
136
136
after that we just tell it to expect a single row_major matrix in both buffers.
0 commit comments