Course notes for November 27 (more detail and diagrams coming soon)
Perspective interpolation:
What Graphics Processing Units (GPUs) are actually doing when they "linearly interpolate" the from output values of vertex shaders, to create the input values for fragment shaders, is not simply linear interpolation. Rather, it is perspective linear transformation. Linear transformation between two values u_{0} and u_{1} by fraction t is very simple: lerp(t , u_{0} , u_{1}) = (1-t) u_{0} + t u_{1} But this doesn't work when objects are at different distances in the presence of perspective. For any parameter u at distance z, the perspective transformation is, essentially: u → u/z So in order to do a proper linear transformation between value u_{0} at distance z_{0} and u_{1} at distance z_{1}, we need to do: lerp(t , u_{0}/z_{0} , u_{1}/z_{1}) / lerp(t , 1/z_{0} , 1/z_{1}) Local surface mesh refinement: In class we talked about two different approaches to local refinement of polygon meshes: Local refinement by subdivision: To locally add detail to just one part of a triangular mesh, we can convert a single triangle to four smaller triangles, by adding a vertex to the midpoint of each of the triangle's three edges. To avoid creating cracks in the mesh, we need to split each of the three adjoining triangles into two triangles. This doesn't work well if our original triangle is continually subdivided. So we need to "spread out" the detail amongst adjoining triangles in the mesh, as I showed in class. I will add those details to these course notes shortly.
Refinement by deleting shortest edge, dividing longest edge: Another approach is to define some metric for edge length (which doesn't need to be the literal edge length), and then iteratively remove the smallest edge from the mesh while splitting the longest edge. Deleting the smallest edge removes two triangles and one vertex, whereas splitting the longest edge adds two triangles and one vertex. To make this run reasonably fast, you should use a binary min heap and max heap to keep track of the current shortest and longest edges. By choosing interesting "edge length" metrics, you can create more detail in some parts of the mesh, while removing detail from other parts. I wil be adding detail on this topic to the course notes over the next few days. spring/mass dynamics:
Double integral
The simplest form of dynamics is a double integral of force (which is mass times accelaration), to get position. This integral can be modified by a damping factor (to model frictional forces on the spring) and mass. The code for the behavior of a spring object, whose function getPosition() { return P; } function setDamping(t) { damp = t; } function setForce (t) { F = t; } function setMass (t) { mass = Math.max(0.001, t); } function update(elapsed) { V += (F - P) / mass * elapsed; P = (P + V) * (1 - damp * elapsed); } var P = 0, V = 0, F = 0, mass = 1.0, damp = 1.0; } On-line examples:
Springs connecting each pair of atoms The key to implementing something like the molecules example above (and the springy guy as well) is that for every pair of atoms that are not connected by a molecular bond, we place an invisible spring, which is continually trying to maintain its original length. Any any graph with n nodes there are n(n-1)/2 possible edges, so for a model with A atoms and L links, we need A(A-1)/2 - L springs. Chrome mapping:
Collision avoidance: When trying to figure out whether two objects intersect (say, for doing physics or character animation), it can be very expensive to run through all of the triangles of two objects, since the number of pair-wise comparisons needed goes up as the square of the number of triangles involves. For this reason, we often do simplified approximations using simple shapes that are roughly correspond to the model shape. Two common shapes used for this purpose are spheres and cylinders. To see whether two spheres intersect, we just need to do the following:
Rather than using spheres, you can also use cylinders. It's trade-off, since the computation between two cylinders is slower, but for things like character body limbs you need fewer cylinders than spheres for a good shape approximation. The key to seeing whether two cylinders intersect is to compute the points where their center axes approach each other most closely, and then compute the separation between those two points exactly as you would for two spheres. Graphics in the fourth dimension: We ended the lecture with a discussion of graphics in the fourth dimension, touching on such topics as the hypercube, the four dimensional simplex, a 4D virtual trackball, shading, perspective, and a very brief discussion of my favorite shape, the 24 cell (the close packing formation of hyperspheres). In the coming days I will add to the notes on this topic, for those of you who want to do a project in four dimensions, or are just interested in the topic. Homework Some time during the next week, please email me a proposal for an individual final project. Your project will be due by Friday, December 20. After you email me, I may not get back to you right away, because it make take some thinking to give you the best advice, so please try to be patient. |