The first class is pretty basic. It's all about introducing the rendering pipeline, which is, of course, very important and useful for us to know. Since we are starting from 2D, the basic process is (if I'm not getting anything wrong):
Loading vertex information from a mesh file (grouped by three - at least for now, since we are using the triangle list)
-> process each vertex in the vertex shader (where you get all the inputs you want from your program - written through DirectX in our case and only has position of the vertices for now) and output positions and colors of those vertices to the hardware
->the hardware interpolates everything the vertex shader sends to it and send those fragment information to the pixel shader (or fragment shader)
--BTW, a fragment is a potential pixel on the screen (which means there is a chance they may not be rendered because they could be a bad pixel - for example, blocked by another object).
->for each fragment information that sends in, the pixel shader process through them (doing modifications if you want) and output them as a fragment. Then the hardware decides which fragment to render at the end.
Anyway, learning this really helps me to clear my vague understanding of this pipeline.
As for the assignment, it's just load from a file that holds a rectangle information (two triangles - six vertices to be exact) and render it onto the screen through the pipeline. Basically, all we have to do is to write a file loader that parse through the vertex position and play around with the vertex shader and pixel shader. Nothing much.
Since I figured we are gonna write a FBX parser eventually, I might as well do some simple practices now, that's why I used this format: (Not exactly the same as fbx, but kind of similar. And yes, it's 2D for now, baby-steps.)
VertexNumber = [number of vertices];
VertexData =
{
[x0], [y0],
[x1], [y1],
...
[xn], [yn]
}
As for the actual shader, there is nothing much to do, I added some funny equations to the vertex shader to see how it behaved. As for the pixel shader, I only pass through the color information since I really want to check out the interpolation effect. Anyway, here is part of the code for the vertex shader:
o_position = float4(
i_position.x * abs(cos( g_secondsElapsed * 0.3)) + abs( ( 0.5 * i_position.x ) * cos(g_secondsElapsed * i_position.y ) ),
i_position.y * abs(sin( g_secondsElapsed * 0.5)) + ( ( 0.3 * i_position.y ) * sin( g_secondsElapsed * i_position.x ) ),
0.0, 1.0 );
// Calculate color
float red = ( sin( g_secondsElapsed ) * 0.5 * i_position.x ) + 0.5;
float green = ( cos( 5.0 * g_secondsElapsed ) * 0.5 * i_position.y) + 0.5f;
float blue = 1.0 - sin( g_secondsElapsed * 4.0);
o_color = float4( red, green, blue, 1.0 );
Here is how it looks:
Also, the debug information from the PIX:
| Pixel Shader |
![]() |
| Vertex Shader |
BTW,
the project file for the assignment:
Code


No comments:
Post a Comment