Kevin Song
I'm a student at UT (that's the one in Austin) who studies things.
these eyes will not be blinded by the lights
Bui Tuong Phong
An early doctoral student of Ivan Sutherland at Utah.
Invented the Phong shading model and algorithm.
Created the first computer graphics image that looked like its physical counterpart (the Beetle, right)
Died in 1975, age 32, to complications from squamous cell carcinoma.
Became professor at Stanford after graduation.
What if we want to map textures onto shapes that aren't spheres or boxes?
# Vertices
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 1.0 1.0 0.0
v 0.0 1.0 0.0
v 0.0 0.0 1.0
v 1.0 0.0 1.0
v 1.0 1.0 1.0
v 0.0 1.0 1.0
# Texture coordinates
vt 0.0 0.0
vt 1.0 0.0
vt 1.0 1.0
vt 0.5 0.7
vt 0.0 1.0
vt 0.4 0.2
# Faces (vertex/texture/normal)
f 1/1/1 2/2/1 3/3/1
f 1/1/1 3/3/1 4/4/1
f 5/1/2 8/2/2 7/3/2
f 5/1/2 7/3/2 6/4/2
f 1/1/3 4/2/3 8/3/3
f 1/1/3 8/3/3 5/4/3
f 2/1/4 6/2/4 7/3/4
f 2/1/4 7/3/4 3/4/4
f 4/1/5 3/2/5 7/3/5
f 4/1/5 7/3/5 8/4/5
How can we make textures that move with the shape and interact normally with lighting models?
Textures already do this.
You can think of a texture as a fill which varies across the surface of the shape.
When you use fill(), you don't worry about transforming the shape. Same with textures.
One exception: scaling the shape will stretch the texture, but there's not much you can do to avoid this (if mapping a square texture onto a rectangle, something has to stretch)
Unfortunately, not automatically. But you can manually make a sequence of textures and apply them per-frame to make the appearance of an animated texture.
For the textures we're examining in this class, no.
However, advanced techniques like bump mapping, displacement mapping, normal mapping, and parallax mapping can change the (apparent) geometry of a shape.
Many different variations:
Classical mechanics is the study of forces on bodies.
Based on well-understood laws (Newtonian)
If the car is going 25mph, it's kind of important to know whether it's moving left or right!
25 mph?
25 mph?
We can represent velocity and acceleration as vectors.
Vectors have direction and magnitude.
In 1D, vectors are just (signed) numbers.
Addition
Scaling
We can set rules and relationships between our three quantities to modify physical behavior.
For now, we'll work with a simple, intuitive version of Newton's Laws of Motion:
float y = 0.0;
float r = 30.0;
float vel = 0.0;
float accel = 0.03;
void setup(){
size(500, 500);
}
void draw() {
ellipse(250, y, r, r);
vel += accel;
y += vel;
if (y > height) {
y = 0.0;
}
}
Particle
class with at least the members shown to the right.class Particle {
float y = 0.0;
float r = 30.0;
float vel = 0.0;
float accel = 0.0;
float gravity = 0.05;
// Take a step using the current
// accleration + velocity settings
void update(){}
// Draw the particle
void draw(){}
}
Gravity is a downward force (we already have this).
Friction is a force which opposes the velocity.
Spring force is the force needed to compress a spring
Coefficient of restitution describes the loss of energy when objects collide.
float y = 0.0;
float r = 30.0;
float vel = 0.0;
float accel = 0.0;
float gravity = 0.05;
float coef_fric = 0.001;
float coef_rest = 0.8;
void setup(){
size(500, 500);
ellipseMode(RADIUS);
}
void draw() {
background(210);
ellipse(250, y, r, r);
accel = gravity;
vel += accel;
vel -= coef_fric * vel;
y += vel;
if (y > (height - r)) {
vel = -(coef_rest * vel);
y = height - r; // Massive hack
}
}
Note: we still haven't solved the problem that our simulation is unprincipled---but it sure looks more interesting!
where N > 1
In 2D, a particle will need six variables to hold its state:
In 3D, we'll need nine variables.
Now imagine that we have 50 particles (we're about to have that!). How many variables do we need?
class Particle {
float x;
float y;
float vx;
float vy;
float ax;
float ay;
void applyForce(){
// Code code code...
}
}
The PVector
class lets us store vectors in a class in Processing.
PVector p1 = new PVector(1,2);
PVector p2 = new PVector(2,4);
PVector p3 = p1.add(p2);
PVector p4 = p3.mult(2);
// Alternate way of creating p4
PVector p5 = p1.add(p2).mult(2);
Basic math operations (+, -, /, *, ^
) are not defined on classes, so we need to use methods like .add()
or .mult()
to do math on PVector
s.
class Particle {
PVector pos;
PVector vel;
PVector accel;
void update(){
// Code code code...
}
}
update()
so that it takes a PVector
indicating the force acting on the particle at the time.Examples: smoke, water, fire, clouds, dust, galaxies, etc.
Generally, there will be three "stages" in a particle system, though these can be thought more as decisions to make than as discrete stages.
Fireworks
Snowstorm
Particle
Additional rules (usually written as methods) can make the behavior of our Particle
class more complex and interesting:
Linked from https://en.wikipedia.org/wiki/Particle_system#/media/File:Particle_Emitter.jpg
https://github.com/zshipchandler/particle-simulator
Take the Particle class you've written and do one of the following with it:
In either case, you should add some randomness to the initial velocity of the particles so that they don't all do exactly the same thing. The random()
method may be useful for this.
https://www.youtube.com/watch?v=0Gi0ssQkWok&t=4120s
I hate to make it sound like everything is really difficult but....this is the kind of job that takes someone with 10 years of practice days to do really well.
No. Textures map onto a single surface, overlapping shapes are more than one surface. You would have to join the shapes.
Not in the Phong model, because all objects are opaque. If you allow object transparency, there are some analogues (but this falls squarely in the realm of "advanced shading models").
No. Light intensities are added.
Most systems require raster images for textures.
This is all handled for you, though we'll have a peek at how this is done at the end of next week.
By Kevin Song
I'm a student at UT (that's the one in Austin) who studies things.