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.

Slides:



Advertisements
Similar presentations
POST-PROCESSING SET09115 Intro Graphics Programming.
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Optimized Stencil Shadow Volumes
Graphics Pipeline.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
Announcments Project 1 Project 2 Midterm Project 3.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
3D Rendering – A beginners guide Phil Carlisle – University of Bolton.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Hidden Surface Removal
Polygon Scan Conversion and Z-Buffering
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Culling Techniques “To cull” means “to select from group” In graphics context: do not process data that will not contribute to the final image The “group”
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
Stream Processing Main References: “Comparing Reyes and OpenGL on a Stream Architecture”, 2002 “Polygon Rendering on a Stream Architecture”, 2000 Department.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
CSCE 552 Spring D Models By Jijun Tang. Triangles Fundamental primitive of pipelines  Everything else constructed from them  (except lines and.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
OpenGL Shading Language
The Graphics Pipeline Revisited Real Time Rendering Instructor: David Luebke.
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
OpenGl Shaders Lighthouse3d.com.
2 3D Viewing Process  3D viewing process MC Model Space Model Transformation Model Transformation WC World Space Viewing Transformation Viewing Transformation.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Shaders, part 2 alexandri zavodny.
- Introduction - Graphics Pipeline
Deferred Lighting.
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
© University of Wisconsin, CS559 Fall 2004
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Day 05 Shader Basics.
Lecture 13 Clipping & Scan Conversion
Programming with OpenGL Part 3: Shaders
CS 480/680 Computer Graphics GLSL Overview.
Frame Buffer Applications
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Announcments Sign up for crits!

Reading for Next Week FvD – local lighting models GL 5 – lighting GL 9 (skim) – texture mapping

Modern Game Techniques CS248 Lecture Nov 13 Andrew Adams

Overview The OpenGL Pipeline Vertex and Fragment Shaders Multipass Techniques Culling and Collision Detection

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();

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterization Texturing

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterization Texturing Vertices with: Colors Texture coords Normals

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterization Texturing Vertices in eye coords with: Colors Texture coords Normals in eye coords

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterization Texturing Vertices in eye coords with: Lit colors Texture coords

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterization Texturing Vertices in clip coords with: Lit colors Texture coords

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterization Texturing Fragments with: Interpolated colors Interpolated texture coords

The OpenGL Pipeline Modelview Transform Lighting Perspective Transform Rasterize + Interpolate Texturing Fragments with: Colors Texture Memory

The OpenGL Pipeline with Shaders Vertex Shader Rasterize + Interpolate Fragment Shader

The OpenGL Pipeline with Shaders Vertex Shader Rasterize + Interpolate Fragment Shader Small programs that run on the graphics card

The OpenGL Pipeline with Shaders Vertex Shader Rasterize + Interpolate Fragment Shader Vertices with: Colors Texture coords Normals

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

The OpenGL Pipeline with Shaders Vertex Shader Rasterize + Interpolate Fragment Shader Fragments with: (Interpolated values from previous stage)

The OpenGL Pipeline with Shaders Vertex Shader Rasterize + Interpolate Fragment Shader Fragments with: Colors Texture Memory

How many times are the fragment and vertex shaders executed on this scene

Vertex shader runs once per vertex

Fragment shader runs once per pixel

Vertex Shader void main() { gl_Position = gl_Vertex; } Fragment Shader void main() { gl_FragColor = vec4(1, 0, 0, 1); }

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

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

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

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); }

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.

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

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

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

Creating your own shaders Get at the extension functions –use glew Load the shaders as strings Compile them Link them into a ‘program’ Enable the program Draw something (Live Demo)

References A great tutorial and reference: – The spec for GLSL, includes all the available builtin functions and state: – The OpenGL ‘orange book’ on shaders is also good

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

Motion Blur 1) T = empty texture 2) Render a slightly dimmed T 3) Render the scene 4) Copy the framebuffer into T 5) Goto 2 (Live Demo)

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?

Sharpen Filter Render the scene Save it as a texture Render the texture, using a shader to convolve the image (Live Demo)

Reflections Eye Scene Mirror

Reflections Eye Scene Mirror Reflected Eye

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

Question How could you use multipass rendering, vertex, and fragment shaders to render a pond with ripples that reflects a cloudy sky?

Question How did I do this? –4 quads, 3 are texture mapped –1 shader –2 framebuffer sized textures (Live Demo)

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(n 2 ) is bad –O(n ln(n)) is good

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

Portal Culling Your world is divided into cells, with rectangular doorways between the cells. Cell ACell B Eye

Portal Culling From cell A, what’s visible in cell B? Cell ACell B Eye

Portal Culling This is just frustum culling against the frustum subtended by the portal. Cell ACell B Eye

Portal Culling Some objects in C are NEVER visible from anywhere in A Cell A Cell B Eye Cell C

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

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.

Collision Detection Simplified Check (cheaply) against bounding volumes –spheres or boxes If they collide, do the expensive check HardEasy

Collision Detection Simplified Why do you think spaceships in computer games have spherical shields? HardEasy

Collision Detection = Sorting What’s a good collision detection algorithm for line segments of constant width in 1D?

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 xmax x

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)

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.

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

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

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

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))

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

Fast Objects Quickly moving objects might jump over each other:

Fast Objects This is a sampling problem. Test collisions against motion blurred object shapes instead

Fast Objects Use shortest distance between two line segments, or ellipsoids, or larger bounding spheres

Fast Objects Solve for precise time to do good physics calculations t = ?

Fast Objects Alternative solution: Up the sampling rate –Do many physics time steps per drawn frame

Detail Culling/LOD Things that are far away need not be drawn well –Use simplified meshes, simpler shaders, etc

Detail Culling/LOD Things that are far away need not be drawn well –Use simplified meshes, simpler shaders, etc

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!

3 Most Important Things?

Challenge How would you implement a rippling pond that accurately reflects the entire world, including near objects, far objects, and the sky?