Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5...
-
date post
19-Dec-2015 -
Category
Documents
-
view
213 -
download
0
Transcript of Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5...
![Page 1: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/1.jpg)
Announcments
• Sign up for crits!
![Page 2: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/2.jpg)
Reading for Next Week
• FvD 16.1-16.3 – local lighting models• GL 5 – lighting• GL 9 (skim) – texture mapping
![Page 3: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/3.jpg)
Modern Game Techniques
CS248 Lecture Nov 13Andrew Adams
![Page 4: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/4.jpg)
Overview
• The OpenGL Pipeline
• Vertex and Fragment Shaders
• Multipass Techniques
• Culling and Collision Detection
![Page 5: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/5.jpg)
The OpenGL Pipeline
glBegin(GL_TRIANGLES);
glTexCoord2i(0, 0);
glNormal3f(0, 0, 1);
glColor3f(1, 0, 0);
glVertex3f(0, 0, 0);
glTexCoord2i(0, 1);
glColor3f(0, 1, 0);
glVertex3f(0, 1, 0);
glTexCoord2i(1, 0);
glColor3f(0, 0, 1);
glVertex3f(1, 0, 0);
glEnd();
![Page 6: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/6.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterization
Texturing
![Page 7: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/7.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterization
Texturing
Vertices with:
Colors
Texture coords
Normals
![Page 8: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/8.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterization
Texturing
Vertices in eye coords with:
Colors
Texture coords
Normals in eye coords
![Page 9: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/9.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterization
Texturing
Vertices in eye coords with:
Lit colors
Texture coords
![Page 10: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/10.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterization
Texturing
Vertices in clip coords with:
Lit colors
Texture coords
![Page 11: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/11.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterization
Texturing
Fragments with:
Interpolated colors
Interpolated texture coords
![Page 12: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/12.jpg)
The OpenGL Pipeline
Modelview Transform
Lighting
Perspective Transform
Rasterize + Interpolate
TexturingFragments with:
Colors
Texture Memory
![Page 13: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/13.jpg)
The OpenGL Pipeline with Shaders
Vertex Shader
Rasterize + Interpolate
Fragment Shader
![Page 14: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/14.jpg)
The OpenGL Pipeline with Shaders
Vertex Shader
Rasterize + Interpolate
Fragment Shader
Small programs that run on the graphics card
![Page 15: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/15.jpg)
The OpenGL Pipeline with Shaders
Vertex Shader
Rasterize + Interpolate
Fragment Shader
Vertices with:
Colors
Texture coords
Normals
![Page 16: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/16.jpg)
The OpenGL Pipeline with Shaders
Vertex Shader
Rasterize + Interpolate
Fragment Shader
Transformed Vertices with:
(Anything you want here, eg normals, colors, texture coords)
Texture Memory
![Page 17: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/17.jpg)
The OpenGL Pipeline with Shaders
Vertex Shader
Rasterize + Interpolate
Fragment Shader
Fragments with:
(Interpolated values from previous stage)
![Page 18: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/18.jpg)
The OpenGL Pipeline with Shaders
Vertex Shader
Rasterize + Interpolate
Fragment ShaderFragments with:
Colors
Texture Memory
![Page 19: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/19.jpg)
How many times are the fragment and vertex shaders executed on this scene
![Page 20: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/20.jpg)
Vertex shader runs once per vertex
![Page 21: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/21.jpg)
Vertex shader runs once per vertex
Fragment shader runs once per pixel
![Page 22: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/22.jpg)
Vertex Shader
void main() {
gl_Position = gl_Vertex;
}
Fragment Shader
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
![Page 23: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/23.jpg)
Vertex Shader
void main() {
gl_Position = gl_Vertex;
}
Fragment Shader
void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
Note:
Ignores modelview and projection matrices
![Page 24: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/24.jpg)
GLSL Types
• Float types:– float, vec2, vec3, vec4, mat2, mat3, mat4
• Bool types:– bool, bvec2, bvec3, bvec4
• Int types:– int, ivec2, ivec3, ivec4
• Texture types:– sampler1D, sampler2D, sampler3D
![Page 25: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/25.jpg)
GLSL Types
• A variable can optionally be:– Const– Uniform
• Can be set from c, outside glBegin/glEnd
– Attribute• Can be set from c, per vertex
– Varying• Set in the vertex shader, interpolated and
used in the fragment shader
![Page 26: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/26.jpg)
Vertex Shader
attribute float vertexGrayness;
varying float fragmentGrayness;
void main() {
gl_Position = gl_Vertex;
fragmentGrayness = vertexGrayness
}
Fragment Shader
uniform float brightness;
varying float fragmentGrayness;
void main() {
const vec4 red = vec4(1, 0, 0, 1);
const vec4 gray = vec4(0.5, 0.5, 0.5, 1);
gl_FragColor = brightness * (red * (1 – fragmentGrayness) +
gray * fragmentGrayness);
}
![Page 27: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/27.jpg)
Vertex Shader
attribute float vertexGrayness;
varying float fragmentGrayness;
void main() {
gl_Position = gl_Vertex;
fragmentGrayness = vertexGrayness
}
Fragment Shader
uniform float brightness;
varying float fragmentGrayness;
void main() {
const vec4 red = vec4(1, 0, 0, 1);
const vec4 gray = vec4(0.5, 0.5, 0.5, 1);
gl_FragColor = brightness * (red * (1 – fragmentGrayness) +
gray * fragmentGrayness);
}
Set once per vertex, like color, normal, or texcoord.
![Page 28: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/28.jpg)
Vertex Shader
attribute float vertexGrayness;
varying float fragmentGrayness;
void main() {
gl_Position = gl_Vertex;
fragmentGrayness = vertexGrayness
}
Fragment Shader
uniform float brightness;
varying float fragmentGrayness;
void main() {
const vec4 red = vec4(1, 0, 0, 1);
const vec4 gray = vec4(0.5, 0.5, 0.5, 1);
gl_FragColor = brightness * (red * (1 – fragmentGrayness) +
gray * fragmentGrayness);
}
Set once per polygon, outside glBegin/glEnd
![Page 29: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/29.jpg)
Vertex Shader
attribute float vertexGrayness;
varying float fragmentGrayness;
void main() {
gl_Position = gl_Vertex;
fragmentGrayness = vertexGrayness
}
Fragment Shader
uniform float brightness;
varying float fragmentGrayness;
void main() {
const vec4 red = vec4(1, 0, 0, 1);
const vec4 gray = vec4(0.5, 0.5, 0.5, 1);
gl_FragColor = brightness * (red * (1 – fragmentGrayness) +
gray * fragmentGrayness);
}
Matching Declarations
![Page 30: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/30.jpg)
Vertex Shader
attribute float vertexGrayness;
varying float fragmentGrayness;
void main() {
gl_Position = gl_Vertex;
fragmentGrayness = vertexGrayness
}
Fragment Shader
uniform float brightness;
varying float fragmentGrayness;
void main() {
const vec4 red = vec4(1, 0, 0, 1);
const vec4 gray = vec4(0.5, 0.5, 0.5, 1);
gl_FragColor = brightness * (red * (1 – fragmentGrayness) +
gray * fragmentGrayness);
}
Set at each vertex in vertex shader
Interpolated in hardware
Available in fragment shader
![Page 31: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/31.jpg)
Creating your own shaders
• Get at the extension functions– use glew http://glew.sourceforge.net/
• Load the shaders as strings• Compile them• Link them into a ‘program’• Enable the program• Draw something • (Live Demo)
![Page 32: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/32.jpg)
References
• A great tutorial and reference:– http://www.lighthouse3d.com/opengl/gls
l/
• The spec for GLSL, includes all the available builtin functions and state:– http://www.opengl.org/documentation/gl
sl/
• The OpenGL ‘orange book’ on shaders is also good
![Page 33: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/33.jpg)
Multipass Techniques
• Many cool effects are easier to achieve by rendering the scene multiple times:
– Render the scene– Read the scene into a texture– Render that texture on the screen in
some interesting way
![Page 34: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/34.jpg)
Motion Blur
1) T = empty texture2) Render a slightly dimmed T3) Render the scene4) Copy the framebuffer into T5) Goto 2
(Live Demo)
![Page 35: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/35.jpg)
Motion Blur: Two Questions
• Question 1: What’s incorrect about this motion blur?
(from a sampling point of view)
• Question 2: How could this be modified to make a zoom blur?
![Page 36: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/36.jpg)
Sharpen Filter
• Render the scene• Save it as a texture• Render the texture, using a shader to
convolve the image
(Live Demo)
![Page 37: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/37.jpg)
Reflections
Eye
Scene
Mirror
![Page 38: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/38.jpg)
Reflections
Eye
Scene
Mirror
Reflected Eye
![Page 39: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/39.jpg)
Reflections
• Reflect the eye about the plane of the mirror
• Render a view from that point, with frustum subtended by the mirror.
• Save the framebuffer into a texture• Render the scene as normal, placing
that texture over the mirror
![Page 40: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/40.jpg)
Question
• How could you use multipass rendering, vertex, and fragment shaders to render a pond with ripples that reflects a cloudy sky?
![Page 41: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/41.jpg)
Question
• How did I do this?– 4 quads, 3 are texture mapped– 1 shader– 2 framebuffer sized textures
(Live Demo)
![Page 42: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/42.jpg)
Collision Detection and Culling
• The collision detection problem: – Given n objects with arbitrary shapes
and positions, efficiently detect which objects intersect with which other objects.
– O(n2) is bad– O(n ln(n)) is good
![Page 43: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/43.jpg)
Collision Detection and Culling
• The frustum culling problem: – Given n objects with arbitrary shapes
and positions, efficiently detect which objects intersect with the viewing frustum.
– O(n) is bad– O(ln(n)) is good
• Frustum culling is a special case of collision detection – collision with the frustum
![Page 44: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/44.jpg)
Portal Culling
• Your world is divided into cells, with rectangular doorways between the cells.
Cell A Cell B
Eye
![Page 45: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/45.jpg)
Portal Culling
• From cell A, what’s visible in cell B?
Cell A Cell B
Eye
![Page 46: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/46.jpg)
Portal Culling
• This is just frustum culling against the frustum subtended by the portal.
Cell A Cell B
Eye
![Page 47: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/47.jpg)
Portal Culling
• Some objects in C are NEVER visible from anywhere in A
Cell A Cell B
Eye
Cell C
![Page 48: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/48.jpg)
Portal Culling
• For all pairs of cells x, y, precompute the set of objects in cell x that could be seen from cell y. Draw only them.
Cell A Cell B
Eye
Cell C
![Page 49: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/49.jpg)
Collision Detection and Culling
• Frustum Culling and portal culling are just collision detection against frustums.
• A good collision detection framework solves these culling problems for you.
![Page 50: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/50.jpg)
Collision Detection Simplified
• Check (cheaply) against bounding volumes– spheres or boxes
• If they collide, do the expensive check
Hard Easy
![Page 51: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/51.jpg)
Collision Detection Simplified
• Why do you think spaceships in computer games have spherical shields?
Hard Easy
![Page 52: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/52.jpg)
Collision Detection = Sorting
• What’s a good collision detection algorithm for line segments of constant width in 1D?
![Page 53: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/53.jpg)
Collision Detection = Sorting
• Sort by min x, then scan along, checking backwards until max x of the earlier polygon < min x of this polygon
• Complexity O(n ln(n))• Still works for segments of varying
width?
min x max x
![Page 54: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/54.jpg)
Collision Detection = Sorting
• Algorithm 1:– Sort all your bounding spheres along an
arbitrary direction, eg z– Scan along the list, checking sphere/sphere
distance between each sphere and the previous k
– For spheres that collide, do more expensive polygon/polygon checks (for culling we can be conservative and skip expensive checks).
• Only works if spheres have known max size, and are small. Otherwise k = O(n)
![Page 55: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/55.jpg)
Collision Detection = Sorting
• Algorithm 2: Bucket sorting– Make a big array of cells for all space– Put a reference to each sphere in each
cell it intersects (O(1) cells)– Traverse all the cells, looking for cells
with more than one thing in them, do more accurate comparisons on those things.
![Page 56: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/56.jpg)
Collision Detection = Sorting
• Algorithm 2: Bucket sorting– Have to be careful to avoid double counting
collisions– Can rasterize large objects like frustums into
the cells using a 3D rasterizer algorithm– Complexity = number of cells– Small cells make each object appear in
many cells - inefficient– Large cells may have many objects per cell
![Page 57: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/57.jpg)
Collision Detection = Sorting
• Algorithm 3: Hierachical bucket sorting– Apply algorithm 2 on n objects with k
large cells– Each cell has O(n/k) objects in it that we
need to check for collisions– Recurse with smaller cells!– If few objects in a cell, don’t bother
recursing
![Page 58: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/58.jpg)
Collision Detection = Sorting
• k = 8– ‘octtree collision detection’– Divide each cell in half in x, y, and z
• k = 2– ‘kd-tree collision detection’– Divide each cell in two in x OR y OR z– Doesn’t necessarily divide in half
• Both are good
![Page 59: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/59.jpg)
Temporal Coherency
• We don’t want to recreate this whole recursive data structure every frame
• Static objects need not be reinserted every frame
• Moving objects don’t jump around at random, so you can be clever about moving them in the tree – O(1) insert cost instead of O(ln(n))
![Page 60: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/60.jpg)
Low level collision detection
• You’ve detected two objects might collide based on bounding volumes... now what?
• A) Triangle vs triangle tests for each pair of triangles in the objects.– Tedious algorithm, look it up online
• B) Nearly collided is good enough – Culling– Arcade game collision detection
![Page 61: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/61.jpg)
Fast Objects
• Quickly moving objects might jump over each other:
1 2 3 4
1
2
3
![Page 62: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/62.jpg)
Fast Objects
• This is a sampling problem. Test collisions against motion blurred object shapes instead.
1 2 3 4
1
2
3
![Page 63: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/63.jpg)
Fast Objects
• Use shortest distance between two line segments, or ellipsoids, or larger bounding spheres.
1 2 3 4
1
2
3
![Page 64: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/64.jpg)
Fast Objects
• Solve for precise time to do good physics calculations
1 2 3 4
1
2
3
t = ?
![Page 65: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/65.jpg)
Fast Objects
• Alternative solution: Up the sampling rate– Do many physics time steps per drawn
frame
1 2 3 4
1
2
3
![Page 66: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/66.jpg)
Detail Culling/LOD
• Things that are far away need not be drawn well– Use simplified meshes, simpler shaders,
etc
![Page 67: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/67.jpg)
Detail Culling/LOD
• Things that are far away need not be drawn well– Use simplified meshes, simpler shaders,
etc
![Page 68: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/68.jpg)
Detail Culling/LOD
• You need to transition between different levels of details
• As an object approaches you can – Pop from one model to the next
• most games do this
– Alpha blend from one model to the next– Subdivide polygons and morph into the
new shape• Dynamic meshes are expensive!
![Page 69: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/69.jpg)
3 Most Important Things?
![Page 70: Announcments Sign up for crits!. Reading for Next Week FvD 16.1-16.3 – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping.](https://reader033.fdocuments.us/reader033/viewer/2022051618/56649d3f5503460f94a18973/html5/thumbnails/70.jpg)
Challenge
• How would you implement a rippling pond that accurately reflects the entire world, including near objects, far objects, and the sky?