Assembly Shaders 48hour assessment in DirectX9 using VS1.1


This project's starting point was a DirectX program which rendered a skull using only ambient lighting. The task had to be completed within 48 hours. In previous years, the coursework was 24 hours. My personal goal was to finish in less than 24 hours; in fact I managed to complete it in approximately 19 hours (one sitting).

Specular and Diffuse Lighting

The specular lighting in this shader is achieved by a simplified version of the Blinn Phong algorithm known as the Halfway Vector technique. It operates by, creating a vector from adding the view direction and the light direction vectors. This new vector is then normalised and used as an approximation for the intensity of the specular light. This is achieved by performing a dot product of the vertex's normal and the halfway vector, after which any negative numbers are discarded using the max function. Finally the resulting number is raised to the desired specular power and output into the specular component register.

Download shader file here

Two Diffuse Lights

Diffuse lighting is simple. This shader uses the Phong model. At first, it performs a dot product between the light direction and the vertex's normal. Then, the colour is scaled by the resulting dot product. Finally, this value is added to the ambient lighting and output into the colour register. However, we have two diffuse lights in this shader, so these calculations have to be done twice, and then the resulting colours added together to get the final colour. This is why the middle of the skull is the sum of the green and red.

Download shader file here

Cel Shading / Cartoon Shader

The Cel shader / Cartoon shader is my favourite. Despite its simplicity, I think it resulted in a nice effect. As usual, we calculate how much each vertex is facing the light by a dot product between the light direction and the vertex's normal. The resulting scalar is used as a lookup in a palette texture. This is a texture with a gradient from black to white. If the result of the dot product is low, e.g. 0.2, then it means it is facing away from the light source, therefore it would look up the first colour in the texture (black in this case). Conversely, if the resulting dot product was a high value, e.g. 0.8, it would look up the last colour (white in this case).

Notes: Observ the fine lines around the eyes and teeth; this required some tuning but improved the effect. Download shader file here

Marble Texture

In order to secure marks, but still have plenty of time for the more advanced shaders, I decided to find a simple solution for this shader; Instead of mapping a texture to a sphere, I used the light direction vector as a texture lookup ( this is why it has a unique look).

Download shader file here

Reflections

Without advanced graphics such as ray tracing, reflections are achieved by texture wrapping. This shader uses texture mapping of a sphere which is described below.

s and t are the texture co-ordinates:



where:


The reflected vector can be computed as:


denotes the normalised vector from the eye point to the vertex (this is equal to the location of the vertex in eye-space).

denotes the normalised normal. As usual it is transformed to eye coordinates by the inverse transpose of the modelview matrix (this is usually done outside the shader).

Download shader file here

"Two Tone"

The specification stipulated a "Two tone paint effect", which is often associated with pearlescent paint. A quintessential pearlescent effect is on some models of TVR cars; an example can be seen here.
To my disappointment, this was not the effect that the lecturer sought. Instead, it was supposed to have two colours which had no lighting. This was implemented by a dot product with the view direction and the vertex's normal. The resulting scalar is used to blend the colours. Since the camera view direction and the vertex's normals are fixed, the colours stay where they are. This provides the appearance of the skull having two colours.

Download shader file here

Vertex Manipulation aka Fat Face

This shader was not on the specification; I did it for fun. Its implementation is very simple. Each vertex is moved along its normal, thus increasing the object's size and changing its appearance. This resulted in a ghastly look.

Download shader file here

Hot Metal / Chrome

This effect was also not on the specification; I did it because it was fun. This effect combines reflections, specular, diffuse and a modified "Two tone". The "Two tone" effect was used to get the orange aura on each side of the skull. It is based on the dot product between the light direction and the vertex's normal to add colour to the object. This gave the skull a "hotter" look. Next, the colour of the specular lighting was changed to a pinky appearance to indicate a source of heat, such as a blow torch. Finally, the reflections were added to give it a chrome / shiny effect.

Download shader file here