This assignment is really a big challenge. I overestimated myself and didn't think that it will take me a whole day to finish it. I had written my own camera class in XNA before and I had already understood the graphics pipeline from the class. However, I still felt as if I was in a dark place with no direction to proceed. Thus, I went through some tutorial: Rastertek DirectX tutorial and and Microsoft DirectX introduction. These tutorials helped implanting the graphics pipeline into my head deeper. I had also watched the video and looked at John's code in class to help me start.
This is the basic pipeline: the information of the object to be drawn on screen comes from a vertex list (in our assignment, this comes from mesh input data). This information will be passed to vertex shader where it will be interpolated and sent to fragment shader. The information passed to vertex shader can be anything (in this assignment is vertex position and colour). The reason why we passed any information to fragment shader through vertex shader is because we want it to be interpolated which is performed by graphics device. Then using the received information, fragment (potential pixel) shader will draw the object on screen.
In 3D, we need to add more consideration: the space of the camera, world and the model. Each model has it's own model space which is the exact original position of the model and it is facing forward. When the object is placed on the world, it will have a position on regard to the world, called world space. In graphics, we got this position by transformed the model space into the world space. Then for us to able to see in the world, the position need to adjusted again in regard to the position of the camera. Again, to obtain the model position relative to the camera, we need to transform the world space into the view space (wherever the camera view). Finally, for it to be drawn in the 2D space of screen, we need to transform the camera view into the projected view of screen. So, total there are three transformations needed for the model to appear on the camera's eye: model to world, world to view, and finally view to projected.
My first colourful 3D box with DirectX
My mesh data before vertex shader
My mesh data after vertex shader
It was not only a rotating-3D colourful box. The camera can be moved using [W][A][S][D] keys and the cube itself can be moved using [UP][DOWN][LEFT][RIGHT] keyboard button.
Btw, I changed my mesh input format into:
<vertex> --> start of vertex tag
# -> total numbers of vertex
{ --> start of vertex data
x,
y, z --> vertex position
r,
g, b --> vertex colour (in RGB
format and value range from 0 to 255)
} --> end of vertex data
</vertex> --> end of vertex tag
<index> --> start of index tag
# --> total number of index
index1
index2 index3 --> 3 indices of vertices of a
triangle
</index> --> end of index tag
It was quite a lot to learn and study for this assignment. There was also a lot of stress during coding this assignment. Now after this assignment was done, I feel I had more understanding on camera and 3D pipeline than before I did the coding. Thank you for Cody's help, John's great lecture and code example on class, and Derek's who helped me looking at my strange error on release build. (We haven't completely fix the memory access violation error on running the release build through the Visual Studio yet. However, we were sure the program can be run perfectly through the executable file).
No comments:
Post a Comment