Input Assembler Stage[IA]:
The purpose of the Input Assembler Stage is to read Primitive Data Points i.e. points or lines, this can be Thought as the building Block stage or the entry point of the pipeline and lays the foundation for reaching the final goal of the pipeline which is to output an image on the screen. In this stage we supply vertex and index data of the objects you want to render the IA Will Then Assemble this Data into Primitives and send the output to the Vertex Shader Stage. This is sent to the IA Stage using the DirectX11 Buffer Objects. Below Is some Examples of some of the various DirectX Primitive Types used:
• Triangle List
• Point List (D311_PRIMITIVE_TOPOLOGY_POINTLIST)
• Line List
• Line Strip
• Triangle Strip
Direct X Also Supports Patches which are surfaces with a number of control points for example a triangle will have 3 control points.
Vertex Shader Stage [VS]:
This is the first programmable Stage of the program pipeline and this is where are data from the IA Stage which was used to assemble primitives is pumped into the vertex shader stage.
This stage will input a vertex and output a vertex, and this stage also will handle operations such as Transformations and Per Pixel Lighting and all vertices will be run through this process, it is Primarily Responsible for Positioning the geometry in the scene and also converting 3D geometry Data into 2D Geometry ready to render to the screen.
https://i-msdn.sec.s-msft.com/dynimg/IC822974.jpeg
Rasterizer Stage[RS]: Pixel Shader Stage[PS]:
In this stage The primitives created in the previous stages are converted into pixels whilst interpolating per vertex values across the primitives in preparation for displaying 3d graphics. Clipping the vertices to the view frustum also takes place mapping primitives to the 2D Viewport which was setup in the vertex shader Stage. A divide by z is also performed to provide perspective. The pixel shader stage contains constant values, texture details and interpolated per-vertex values to output per-pixel data. The rasterizer stage will invoke the pixel shader stage for every pixel covered by a primitive. The Rasterizer stage will also determine what pixels will remain visible by using culling, it will determine which parts of the geometry are out of the view frustum set up in the VS stage and discard them which is vital for performance, it will also use another method called clipping which is when any part of the geometry which lies partly outside the frustum is reshaped with new primitives in our case triangles.
Output Merger Stage[OM]:
The Output Merger Stage is the Final Stage of the Program Pipeline this is the stage that puts everything together and displays it on the screen it combines the newly rendered pixels with the existing content of the buffers to produce new values in these buffers:
Mathematical Concepts of 3D Transformations:
When Performing 3D Transformation, we use matrices to handle the mathematical operations, a Matrix is a table of scalars in square brackets and as we are working in 3d space and not 2D space we have to use a 3×3 matrix which includes z rather than a 2×2 matrix which would be used in 2D Space. Entries in a Matrix are numbered from 1 and not from zero and are numbered by row and column below is an example of a 3×3 matrix:
Translation:
A translation in a 3d Space is simple moving an object for example moving a object that I have created from point A to Point B in a 3D Space, in a three dimensional homogeneous coordinate system a point, in this case point A is transformed from Position P:
Essential Mathematics for Games and Interactive Application:
“Since all the points are Shifted equally in space, the size and shape of the object will not change” (James M. Van Verth Lars M. Bishop page 115)
Point B in this Case is which the new point of the object after it has been moved from Point A
Below is the Matrix Representation of the Translation:
Rotation:
When Rotating an Object, we can rotate On the X, Y or Z Axis in 3D Space or a combination of axis, Rotation can be seen as the turning of an object or coordinate system by an angle around a fixed point the matrixes for these can be seen in figure. The orientation of the object is preserved however, making rotation an orthogonal transformation. This point is generally called the axis of rotation and this was shown in Euler’s theorem This was Summarised Well in Essential Mathematics for Games and Interactive Applications “Euler Showed that when applying a rotation in Three Dimensional Space there is a linear set of points (I.e., a line) that does not change. This is called the Axis of Rotation” (James M. Van Verth Lars M. Bishop page 122)
figure
in addition to Cartesian coordinates we can also show the point of rotation in polar coordinates or alternatively we can convert polar co-ordinates to Cartesian coordinates like so:
Going on to how we can represent Rotations in a 3D space we have:
• Euler Angles
• Quaternions
Euler Angles are a Common way to represent Orientation in a 3D space and were Created by the famous mathematician Leonhard Euler. Euler angles can specify the orientation of an object as a series of three angular displacements from upright space to object space:
• Heading: rotation about the y axis
• Pitch: rotation about the x axis
• Bank/Yaw: rotation about the z axis
The Figure Below is A great way to visualize this as they terms are also commonly used in the aviation industry.
Implementation of Euler angles into a game is as follows, a game object for example an airplane in a flight simulation game this airplane will keep track of its current heading,pitch and bank angles and the frequency of change between these Euler angles in each frame whether this be thirty frames or sixty frames per second the game will calculate per frame how much the airplane has changed its Euler angles since the last frame and will add this to the angles and recalculate it, this is the exact same method we use to calculate the rotation of are spinning cube the frame timer in the code keeps track of the frames per second and the scene will update and calculate the rotations on a frame by frame basis
Using Euler angles has advantages because it easy to use for humans and as its visually straightforward, it is also very commonly used in the animation sector due to it only containing three numbers in its data allowing us to store a lot of data in a relatively small space, as said before it is very easy to just look at the data and understand it rather than matrixes or quaternions which can be confusing to someone who is not fully familiar with their concepts.
Euler Angles do have some Draw backs though one of the biggest issues is the Gimbal lock this is when all three axis are lined up on the same plane causing two of these planes to act as one meaning only two dimensions of movement and not three. This however does not mean some angles and orientations are unachievable in Euler as all orientations can be accurately described using Euler angles the gimbal lock is an aliasing issue and will only pose a problem when trying to interpolate there are some work arounds but generally it is recommended to use quaternions in this case.
figure
Scale:
Scaling an object is when the object increases in size equally in all directions this is achieved through multiplication of a vector through one multiplication factor we can also do this is a negative sense as well and change the objects size by decreasing it equally in all directions.
This is uniform scaling. However, we have Non Uniform scaling as well which is increasing differently on each axis the direction to make an object wider for example or taller.
Mathematical Concepts of a Rotating 3D Cube:
Offline VS Real Time Rendering:
When Using a Real Time Rendering system the user will be constrained, that is generally because real time rendering is generally used for computer games were performance is critical. For Example, a Game may be targeting sixty frames per second meaning the games assets, lighting model, geometry and textures, all have to have compromises to be able to keep the program running at peak performance. A real time render is generated the instant you run the solution or program with the calculations and systems in running in “real-time”.
For Comparison we have used a Game Running at Sixty frames as an Example for are real time render, however if we are speaking about an offline render an example of this would be a Model Generated in a CAD Software or Special Effects in a film. The Geometry, Lighting and overall look of an offline render if done correctly will always look better than what could be achieved if we were using a real time render. The main reason for this is very simple time, an offline render there are no time constraints meaning the computer can take as long as it needs to render each frame and to the highest quality. A more precise Example of this is the Global Illumination Model this is a very heavy processing load on the GPU of a computer and generally can only be achieved to its full potential in an Offline rendering scenario as trying to render all the processes involved in real time would seriously hamper performance and would not be efficient in a real time rendered application which is why most video Games will use a local illumination model instead.
A Global Illumination Model will take into account:
• Reflection
• Refraction
• Absorption
• Shadowing
These Algorithms Are Extremely Complex However allow the global Illumination model to create incredible lighting effects and also create photorealism if performance is not a seen as vital, for example if you were rendering a 3D scene for a video.
The light sources in this example are modelled using ray tracing to model the various light sources and paths.
Global Illumination follows a lot of complex algorithms however the main one which sets it apart and really allows it to add fidelity to a scene is the modelling of diffuse inter-reflections.
Global Illumination using these methods can create Extremely realistic scenes which can mimic how light reacts in the real world for example caustic/optics an example of this would be the reflection of light waves of a glass or the light waves reflecting on the bottom of a pool.
However, rendering all these methods comes at a performance cost as said before to render in real time there are time constraints:
To run a game at 60fps:
1/60 = 16.7ms processing time per frame.
We simply do not have enough time to render the complexities of the global illumination model meaning in a real time this is why offline rendering is favoured in an example like CGI
As it allows a higher level of fidelity due to being able to handle these algorithms that real time rendering simply does not have the time to do without sacrificing performance and this is where the local illumination model comes into favour.
Unlike Global Illumination Local Illumination only calculates the effects of direct light rather than indirect lighting and the algorithms used by global illumination, the local model instead uses a set of equations the compute the lighting. Because only direct lighting is processed it’s a lot easier for it to be rendered making it a lot more efficient and suitable for real time rendering however complex lighting can still be mimicked.
The local illumination model incorporates the intensity of light radiating from the object the normal and the proportion of light reflected from the object these can be represented as follows:
intensity
Normal
Proportion
The three main components of the lighting models are Ambient, Diffuse, Specular
When Modelling the Ambient Light, the equation is:
Ambient light has no direction and is an indirect lighting source and was summarised well in
Essential Mathematics for Games and Interactive Application “Ambient Light is the term used in real- time lighting as an umbrella under which all forms of indirect lighting are grouped and approximated” (James M. Van Verth Lars M. Bishop page 343) we use the equation above to light our scene rather than trying to process light particles being scattered by particles in the air like in real life.
Diffuse light is when light is reflected of a surface in various direction, and can vary due to the roughness of a surface for example a very shiny object like a cue ball for example will be extremely smooth, whereas a rough object like a golf ball the light will reflect differently causing the light particles to spread making them subtler and therefore leaving a duller surface with less obvious reflections. To simulate these effects in a real time renderer we use the Lambertian Model:
The Above Diagram shows visually Lamberts law which is the assumption that light scatters equally in all direction also the apparent brightness of a Lambertian surface will be proportional to the cosine of the angle Between the surface Normal and the direction of the incident light:
This can be written as:
Were N is the Normal, I is the Incident light.
The dot represents the Cosine angle between the surface normal and direction of the incident light
When Combining Ambient Light and Diffuse Light the Equation is as Follows:
The final Method is Specular and this is generally seen as the reflection seen on an object, for example the bright white spot on a ball illuminated from a point light.