This page was last updated: March 1, 2018
So many of the shader experiments I run are inspired by something I saw in a movie. In this case, I was intriqued by some of the things I saw in the Lego movies. If you haven't seen any of them, try to see the Batman Lego movie -- I think that's the funniest. Example:
Barbara Gordon, squeezing into the Batmobile: "Batman, why didn't you build more than one seat?"
Batman: "Because, last I looked, I only have one butt."
Sometimes childish humor is the best...
##OpenGL GLIB Perspective 70 LookAt 0 0 3 0 0 0 0 1 0 Vertex lego.vert Geometry lego.geom Fragment lego.frag Program Lego \ uModelCoords <true> \ uLevel <0 3 3> \ uQuantize <2. 50. 50.> \ uColor { 1.00 0.65 0.40 } Teapot #Obj giraffe.obj #Obj cow.obj #Obj dino.obj
layout( triangles ) in; layout( triangle_strip, max_vertices=204 ) out;
in vec3 vNormal[3]; out float gLightIntensity;
vec3 v = V0 + s*V01 + t*V02;that we looked at before to create new (x,y,z)'s to form new triangle strips. Use the same equation to also create new (nx,ny,nz)'s:
vec3 n = N0 + s*N01 + t*N02;You can use the code from the Sphere Subdivision geometry shader.
vec3 QuantizeVec3( vec3 v ) { vec3 vv; vv.x = Quantize( v.x ); vv.y = Quantize( v.y ); vv.z = Quantize( v.z ); return vv; }
float Quantize( float f ) { f *= uQuantize; f += .5; // round-off int fi = int( f ); f = float( fi ) / uQuantize; return f; }
V0, V1, and V2 are the corner points of the original triangle. V01 = V1 - V0. V02 = V2 - V0. N0, N1, and N2 are the corner normals of the original triangle. N01 = N1 - N0. N02 = N2 - N0. for each new triangle created by the triangle subdivision: { for each (s,t) corner point in that new triangle: { Turn that (s,t) into an (nx,ny,nz) Transform and normalize that (nx,ny,nz) Use the (nx,ny,nz) to produce gLightIntensity Turn that same (s,t) into an (x,y,z) If you are working in ????? coordinates, multiply the (x,y,z) by the ModelView matrix Quantize that (x,y,z) If you are working in ????? coordinates, multiply the (x,y,z) by the ModelView matrix Multiply that (x,y,z) by the Projection matrix to produce gl_Position EmitVertex( ); } }
Be sure that your PDF file is turned-in separately (not part of a .zip file).
Feature | Points |
---|---|
uLevel correctly subdivides each triangle | 20 |
uQuantize correctly quantizes the position of each vertex | 40 |
Able to correctly switch between doing it in model coordinates and doing it in eye coordinates | 20 |
(The switch between model and eye coordinates will need to be demonstrated in your video.) | |
Your lighting is able to distinquish between the different faces | 20 |
Potential Total | 100 |