Information Coding / Computer Graphics, ISY, LiTH
Lecture 11
Volumetric representation
Animation
Information Coding / Computer Graphics, ISY, LiTH
Last time: Almost-midcourse
evaluation
Information Coding / Computer Graphics, ISY, LiTH
Information Coding / Computer Graphics, ISY, LiTH
Time to decide on a project
• Should be preliminary decided wednesday the 3th
(second to last lecture)
• Final specification same day as last lecture (friday 5h)
Title
Participants
Brief summary
Information Coding / Computer Graphics, ISY, LiTH
Project ideas:
• 3D labyrinth
• Interactive solar system • Robot with moveable limbs
• Driving simulator • Flight simulator
Information Coding / Computer Graphics, ISY, LiTH BEZ0,3 = (1-u)3 BEZ1,3 = 3u(1-u)2u BEZ2,3 = 3(1-u)u2 BEZ3,3 = u3 P0 P1 P2 P3 1 1
u
Information Coding / Computer Graphics, ISY, LiTH
de Casteljau’s algorithm
Linear interpoations of linear interpolations
until only one point remains
Information Coding / Computer Graphics, ISY, LiTH
Catmull-Rom splines
Specified only by control points on the curve
Calculated from 4 control points, define between the middle two!
P(u) = pk-1 (-u3/2 + u2 - u/2) +
pk (3u3/2 - 5u2/2 + 1) +
Information Coding / Computer Graphics, ISY, LiTH
Continuity
Catmull-Rom
always
C
and G
continuous!
Information Coding / Computer Graphics, ISY, LiTH
u
Bézier surfaces
Blending of the 16 control points as a
2-dimensional sum
P(u,v) = ∑ ∑ p
j,kBEZ
j,3(v) BEZ
k,3(u)
k=0j=0 3 3
Information Coding / Computer Graphics, ISY, LiTH
Density volumes
3D grid of density values.
• Pre-computed blobby objects
• Voxelization of 3D models
Information Coding / Computer Graphics, ISY, LiTH
Case of particular interest to
some students?
Information Coding / Computer Graphics, ISY, LiTH
MRI of MIR
Information Coding / Computer Graphics, ISY, LiTH
Rendering:
Information Coding / Computer Graphics, ISY, LiTH
Recent projects on raymarching of
medical images
Information Coding / Computer Graphics, ISY, LiTH
Marching Cubes
Information Coding / Computer Graphics, ISY, LiTH
Example: Marching Squares
Information Coding / Computer Graphics, ISY, LiTH
Ray marching relatively easy
Step to next potential voxel wall (3 possible in 3D)
Pick the closest, check neighbor space
Repeat until filled space is found.
Information Coding / Computer Graphics, ISY, LiTH
Cheapass ray marching
Information Coding / Computer Graphics, ISY, LiTH
Conclusions for density volumes
Usually considered for the advanced course - but
from 2018 supported as course project in TSBK07
primarily for students on the medical technology
program.
Information Coding / Computer Graphics, ISY, LiTH
Animation
Essentially a question of flipping between
many still images, fast enough
Information Coding / Computer Graphics, ISY, LiTH
Animation as a topic
• Page flipping, double-buffering
• Sprite animation
• Movement and posing
Information Coding / Computer Graphics, ISY, LiTH
Information Coding / Computer Graphics, ISY, LiTH
The double buffering problem
When animating a scene with many objects in real time, it is not just a question of showing images:
• Erase the entire scene
• Draw each visible object in new positions
Information Coding / Computer Graphics, ISY, LiTH
Single buffered animation
Flicker
Screen update
beam
Information Coding / Computer Graphics, ISY, LiTH
Solutions
1) Don’t erase-and-redraw near the update beam
Unreliable.
Doesn’t work on all screens.
2) Double buffering.
Information Coding / Computer Graphics, ISY, LiTH
Double buffering
VRAM Buffer 1 Buffer 2 VRAM Buffer 1 Buffer 2 Choose buffer CopyInformation Coding / Computer Graphics, ISY, LiTH
Double buffered animation
Tearing
Occurs if buffers switch while the screen is being redrawn.
Screen
Information Coding / Computer Graphics, ISY, LiTH
Built-in VBL sync (vsync)
Modern systems have VBL sync built-in -
even mandatory double buffering. You
Information Coding / Computer Graphics, ISY, LiTH
Double buffering in OpenGL
Double buffer
• Pass GLUT_DOUBLE to glutInitDisplayMode • glutSwapBuffers();
Repeated redraw
Information Coding / Computer Graphics, ISY, LiTH
Sprite animation
2D animation based on 2D images.
Information Coding / Computer Graphics, ISY, LiTH
Sprites in OpenGL
Use textured polygons with
transparency! (Like billboards but
without 3D.)
Information Coding / Computer Graphics, ISY, LiTH
Take advantage of OpenGL in 2D!
High performance - use
high-performance effects
Particle systems
Information Coding / Computer Graphics, ISY, LiTH
Pseudo-3D effects
Scaled sprites on background with perspective: Depth cue by sizeSide-scrolling with parallax scroll: Depth cue by movement
Information Coding / Computer Graphics, ISY, LiTH
Information Coding / Computer Graphics, ISY, LiTH
Information Coding / Computer Graphics, ISY, LiTH
Classic pseudo-3D game with depth
from shadows and depth from size
Information Coding / Computer Graphics, ISY, LiTH
Depth from movement
Parallax scroll
Information Coding / Computer Graphics, ISY, LiTH
Not only history
Information Coding / Computer Graphics, ISY, LiTH
Pseudo-3D effects vs 3D
• Depth from size = perspective projection
• Parallax scroll: Comes for free to some extent,
but can be emphasized with cameras observing
the viewer
Information Coding / Computer Graphics, ISY, LiTH
Animation techniques for moving
objects
• Procedural animation
• Physics-based animation
Information Coding / Computer Graphics, ISY, LiTH
Procedural animation
Simple frame by frame movement
following some procedural rule.
What we are already doing in the labs!
x = x + 1
Information Coding / Computer Graphics, ISY, LiTH
Animation paths
Information Coding / Computer Graphics, ISY, LiTH
Character animation
• Pre-defined poses • Key-frame animation • Forward kinematics • Inverse kinematicsInformation Coding / Computer Graphics, ISY, LiTH
Key-frame animation
Pre-rendered animations
Key-frames are designed at suitable intervals
Information Coding / Computer Graphics, ISY, LiTH
Kinematics
Kinematics = movement without forces Forward kinematics:
Specify poses by specifying rotation of joints. Easy to implement, but specifying poses is much
trial-and-error.
Inverse kinematics:
Information Coding / Computer Graphics, ISY, LiTH
Motion capture
Extremely common in movies! • Record by natural visuals only • Tracking markers
• Active sensors on the body
Information Coding / Computer Graphics, ISY, LiTH
Face animation
Hard problem - we are very sensitive to errors!
Animate by action units (muscle based) or face animation parameters (extreme detail)
Information Coding / Computer Graphics, ISY, LiTH
Some advanced animation topics
• Bones and skinning systems
• Deformations
• Physics-based animation
• Quaternions, SLERP
Information Coding / Computer Graphics, ISY, LiTH
Particle systems
Spectacular effects with little effort!
Many small moving objects.
• Explosions
• Water
• Fire
Information Coding / Computer Graphics, ISY, LiTH
Particle system
Information Coding / Computer Graphics, ISY, LiTH
Particle system
Information Coding / Computer Graphics, ISY, LiTH
Particle system
• Initial position
• Initial speed (usually with some
randomness))
• Movement (usually independent, physically
realistic)
Information Coding / Computer Graphics, ISY, LiTH
Particle system
Movement according to fundamental
physics:
acceleration = gravity + forces/mass
speed = speed + acceleration
Information Coding / Computer Graphics, ISY, LiTH
Particle system on GPU
CPU-driven particle systems OK up to a
certain size
Data transfer (new positions) of all particles
can be a bottleneck
Information Coding / Computer Graphics, ISY, LiTH
Texture based particle systems
Use textures to store x, y, z, dx, dy, dz
Store as color components (r, g, b)
Needs advanced texturing features (render
to texture, floating-point buffers)
Information Coding / Computer Graphics, ISY, LiTH
Separate compute kernels for
particle systems
CUDA, OpenCL, Compute shaders
Free choice of data formats
Information Coding / Computer Graphics, ISY, LiTH
Drawing particle systems
Large number of very simple models
(billboards)!
Modest demands on GPU, but very large
number of function calls!
Information Coding / Computer Graphics, ISY, LiTH
Instancing
Draw a large number of the same model!
Each instance has an index, the instance number.
glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 10);
draws a triangle 10 times!
Information Coding / Computer Graphics, ISY, LiTH
Billboard instancing demo
#version 150
in vec3 in_Position; uniform mat4 myMatrix; uniform float angle; uniform float slope; out vec2 texCoord; void main(void) {
mat4 r;
float a = angle + gl_InstanceID * 0.5;
float rr = 1.0 - slope * gl_InstanceID * 0.01; r[0] = rr*vec4(cos(a), -sin(a), 0, 0);
r[1] = rr*vec4(sin(a), cos(a), 0, 0); r[2] = vec4(0, 0, 1, 0);
Position trivially affected by gl_Instance ID
One single call to
Information Coding / Computer Graphics, ISY, LiTH
Instancing complex models
Information Coding / Computer Graphics, ISY, LiTH
Basic: Start on CPU
Intermediate: Simple instancing
Advanced: Dependent particles
Performance is important, but advanced GPU
based particle systems are beyond basic
Information Coding / Computer Graphics, ISY, LiTH