HOMEWORK XP
The year is winding down and tommorow is the last day to hand in homework questions to get XP. Everyone who doesnt have 40 xp is scrambling trying to get that amount so they can write the final exam. Luckly for me I am not one of those people how are scrambling. I currently have 55 XP and I'm happy with that. I'm going to try my best to get 20 more XP to get full marks for homework but we will see what happens because our game is also due in a couple of days. I would be extremely happy if i could hit that but if not that okay.
So you may ask how I got to 55 XP well... i will explain.
I first thing that was done was toon shading using sobel edge detection and its upgrade to support hatching which i think is really cool looking.
So above is the toon shading with sobel edge applied to an Ambient occlusion texture which gave me 10 XP.
BELOW IS SOME CODE ON HOW TO DO TOON SHADING
#version 120
// 2 varyings
varying vec2 texcoord;
varying vec3 normal;
// 2 uniforms
uniform sampler2D inputImage;
uniform sampler2D qmap;
// 1 constant
const vec3 lightEyeDir = vec3(0,0,1);
void main()
{
vec3 n = normalize(normal);
//this is our q-map input
float diffuse = max(0.0,dot(n, lightEyeDir));
//alternative lighting coefficient
float blocky = texture2D(qmap, vec2(diffuse, 0.5)).r;
vec3 c = texture2D(inputImage, texcoord).rgb;
//gl_FragColor.rgb = c * diffuse * blocky;
gl_FragData[0].rgb = c * blocky;
gl_FragData[1].rgb = n*0.5+0.5;
}
The next thing i did was object and tangent space normal mapping. This was one of the most interesting homework question for me. I am more of an artist than a programmer and to get a better understanding of how normals work in video game was awesome. Object space is cool with normals maps the are very colorful.
For those who do not know how object space normal mapping is done you must:
sample from a texture (an object space normal map)
uncompress the normal's(this because normals are from 0-1 when we need them to be from -1 to 1
calculate displacement of light from object
normalize that displacement calculation
calculate diffuse
output color + diffuse
Object space is a good technique for static objects but when you have animating objects it is not good. This is where tangent space normal maps come in. Tangent space is similar to object space but the light must be brought into tangent space and uses a TBN matrix(tangent, bitangent and normals). To bring the light into tangent space requires math which is very important and i will explain how to do it. So your normal is already given to you by your map so that is covered but now we need to find your tangent and bitangent. This may seems complicated but its really not too difficult. To find them you get triangle from an object. Each triangle has a U and a V and we can use them to find e1 and e2 which are you tangent and bitangent.
So you take your U1 - U0 + your V1 - V0 and your U2 - U0 + your V2-V0 and you can get your e1 and e2 which is what you are looking for.
Once you have the information you need the you apply a transpose and your light is in tangent space. This allows you to use maps like this:
and you can get your model to look all bumpy.
So that was another 10 xp and alot with the art question it put me to 55 XP.
Doing the homework questions were both frustrating and enjoyable once you see the effects a shader can do. If only i started earlier and worked alot harder maybe i could of done alot more but there is always the summer for that!












