The topic of this week assignment is texture and light point. The texture works in similar way as our box surfaces but the coordinate only ranged from (0,0) to (1,1). Btw, the texture coordinate John mentioned in class cannot be applied to DirectX. In DirectX, the texture coordinate is top-left: (0,0), top-right: (1,0), bottom-left: (0,1), and bottom-right: (1,1).
For this assignment, I did more DirectX tutorial research. This assignment made me realize that all the tutorial I found previously is applied in DirectX10 while my code is written in DirectX9. This is the tutorial that helped me figure out how to set the texture to my device: Drunken Hyena. This is a good tutorial. It helped me find a way to load my texture source into my graphics device.
Oh, when doing this assignment, I did one stupid mistake. I loaded and set my texture into my device per frame. Why did I created texture from file per frame!??? Of course after running for around a minute the texture will disappear. The memory will be overflown! Anyways, it's a good learning that creating texture per frame will cause a big problem!
From the video I learnt how to multiple the box colour with the texture but I decided to commented out the line which made this effect for this assignment. And this is my textured-box.
Of course that's not the only thing I learnt from the class. This is the key point I wrote down either from the class nor from the video:
Source code
For this assignment, I did more DirectX tutorial research. This assignment made me realize that all the tutorial I found previously is applied in DirectX10 while my code is written in DirectX9. This is the tutorial that helped me figure out how to set the texture to my device: Drunken Hyena. This is a good tutorial. It helped me find a way to load my texture source into my graphics device.
Oh, when doing this assignment, I did one stupid mistake. I loaded and set my texture into my device per frame. Why did I created texture from file per frame!??? Of course after running for around a minute the texture will disappear. The memory will be overflown! Anyways, it's a good learning that creating texture per frame will cause a big problem!
Shiny box with texture
From the video I learnt how to multiple the box colour with the texture but I decided to commented out the line which made this effect for this assignment. And this is my textured-box.
Box with texture
And this is the texture data read from PIX:
Texture resource in PIX
Of course that's not the only thing I learnt from the class. This is the key point I wrote down either from the class nor from the video:
- Output of vertex shader: (1) position for the graphics hardware and (2) any data we want to be interpolated for fragment shader's use
- Position passed to vertex shader is model space (origin of model and facing forward). For it to be seen in the screen as 3D, transformation need to be performed: model space to world space (position of the model in the world and can face any direction) --> world space to camera space (camera origin and facing forward) --> camera to projected (3D to 2D).
- Graphics hardware need projected position to decide which fragment to shade. This is the variable we output from vertex as POSITION. ==> that's why other data that need to be passed to fragment shader MUSTN'T be declared as POSITION. POSITION is 'exclusive' to GPU
- The reason why we didn't put the matrix transformation in vertex buffer is this operation is expensive. The matrix transformation is the same for every vertices and we need to lock/unlock data every frame to passed the information to vertex shader. This mean during the lock-unlock period GPU shouldn't do anything. This 'idle' period will become a big trouble when we have a large number of vertices
- Texture is specialized uniform 2D array of any kind of data (usually RGB). It can also be a 3D data or known as cube map. *I also learnt that texture can also be used as normal map. This is very interesting. In the Game Arts class from producer I was sitting on, I learnt that normal map often used in game to make a low-polygon model looks like a high-polygon model.
<vertex> -> start of vertices data
# ->
total number of vertices
{ ->
start of vertex data
<position> -> position tag opening
x, y, z
</position> -> end of position tag
<colour> -> colour tag opening
red, green, blue -> value range
0 - 255
</colour> -> end of colour tag
<normal> -> normal tag opening
x, y, z
</normal> -> end of normal tag
<uv> -> UV (texture
coordinate) tag opening
u, v
</uv> -> end of UV tag
} ->
end of vertex data
</vertex> -> end of vertices data
<index> ->
start of indices data
# ->
total number of indices
index#1, index#2, index#3 -> indices of a triangle
</index> -> end of indices data
I spent most of my coding time redoing my mesh input parser. I hoped this will be the last time I redoing it. For the next assignment, I hope, I only need to add more information. Btw, to make the mesh data more readable, my mesh input can also handle comment which started by '//'.
Oh, btw, the light position in this current program is (2, 2, 0). It's so close to the box that make the light seems not moving when change the position to left and right. I reused the box movement keys to move the light. So the control in this program is:
[W][A][S][D] move camera
[UP][DOWN][LEFT][RIGHT] move light
Oh, btw, the light position in this current program is (2, 2, 0). It's so close to the box that make the light seems not moving when change the position to left and right. I reused the box movement keys to move the light. So the control in this program is:
[W][A][S][D] move camera
[UP][DOWN][LEFT][RIGHT] move light
Source code
No comments:
Post a Comment