Sign up for crits! Announcments

Similar documents
Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

OPENGL RENDERING PIPELINE

Pipeline Operations. CS 4620 Lecture 14

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Introduction to the OpenGL Shading Language (GLSL)

Programming shaders & GPUs Christian Miller CS Fall 2011

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Rasterization Overview

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

CS4620/5620: Lecture 14 Pipeline

Performance OpenGL Programming (for whatever reason)

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

12.2 Programmable Graphics Hardware

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Introduction to Shaders.

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Content. Building Geometry Appearance Lights Model Loaders

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

CS452/552; EE465/505. Clipping & Scan Conversion

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

2.11 Particle Systems

Programmable Graphics Hardware

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

The Rasterization Pipeline

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

The Traditional Graphics Pipeline

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Supplement to Lecture 22

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

The Traditional Graphics Pipeline

CS559 Computer Graphics Fall 2015

CSE 167: Introduction to Computer Graphics Lecture #11: Visibility Culling

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Outline. Introduction Surface of Revolution Hierarchical Modeling Blinn-Phong Shader Custom Shader(s)

LOD and Occlusion Christian Miller CS Fall 2011

Pipeline Operations. CS 4620 Lecture 10

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

2D graphics with WebGL

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Hidden surface removal. Computer Graphics

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

CS 4620 Program 3: Pipeline

Particle systems, collision detection, and ray tracing. Computer Graphics CSE 167 Lecture 17

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Dave Shreiner, ARM March 2009

The Traditional Graphics Pipeline

Computergrafik. Matthias Zwicker. Herbst 2010

The Graphics Pipeline and OpenGL IV: Stereo Rendering, Depth of Field Rendering, Multi-pass Rendering!

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

CS451Real-time Rendering Pipeline

Graphics Hardware. Instructor Stephen J. Guy

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Shaders. Slide credit to Prof. Zwicker

Adaptive Point Cloud Rendering

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Programmable shader. Hanyang University

Overview. By end of the week:

Computer graphic -- Programming with OpenGL I

The Application Stage. The Game Loop, Resource Management and Renderer Design

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

TSBK03 Screen-Space Ambient Occlusion

Clipping and Scan Conversion

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Building scalable 3D applications. Ville Miettinen Hybrid Graphics

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Transformation Pipeline

LECTURE 4. Announcements

Quick Shader 0.1 Beta

CS 248 Assignment 2 Polygon Scan Converter. CS248 Presented by Abe Davis Stanford University October 17, 2008

Deferred Rendering Due: Wednesday November 15 at 10pm

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Introduction to the OpenGL Shading Language

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

- Rasterization. Geometry. Scan Conversion. Rasterization

CS 354R: Computer Game Technology

Visibility and Occlusion Culling

Transcription:

Sign up for crits! Announcments

Reading for Next Week FvD 16.1-16.3 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 Vertices with: Colors Texture coords Normals Modelview Transform Lighting Perspective Transform Rasterization Texturing

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

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

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

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

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

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

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

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

The OpenGL Pipeline with Shaders Transformed Vertices with: (Anything you want here, eg normals, colors, texture coords) Vertex Shader Rasterize + Interpolate Texture Memory Fragment Shader

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

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

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 runs once per vertex

Vertex Shader void main() { } gl_position = gl_vertex; Fragment Shader void main() { } gl_fragcolor = vec4(1, 0, 0, 1);

void main() { gl_position = gl_vertex; } Vertex Shader Note: Ignores modelview and projection matrices Fragment Shader void main() { } gl_fragcolor = vec4(1, 0, 0, 1);

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 } Set once per vertex, like color, normal, or texcoord. 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 } Set once per polygon, outside glbegin/glend 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); }

attribute float vertexgrayness; varying float fragmentgrayness; void main() { gl_position = gl_vertex; Vertex Shader } fragmentgrayness = vertexgrayness Matching Declarations 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); }

attribute float vertexgrayness; varying float fragmentgrayness; void main() { } gl_position = gl_vertex; Vertex Shader fragmentgrayness = vertexgrayness uniform float brightness; varying float fragmentgrayness; void main() { } Fragment Shader const vec4 red = vec4(1, 0, 0, 1); const vec4 gray = vec4(0.5, 0.5, 0.5, 1); Set at each vertex in vertex shader Interpolated in hardware Available in fragment shader gl_fragcolor = brightness * (red * (1 fragmentgrayness) + gray * fragmentgrayness);

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)

References A great tutorial and reference: http://www.lighthouse3d.com/opengl/glsl/ The spec for GLSL, includes all the available builtin functions and state: http://www.opengl.org/documentation/glsl/ 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 Scene Mirror Eye

Reflections Scene Mirror Reflected Eye 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 A Cell B Eye

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

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

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

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 Cell C Eye

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 Hard Easy

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

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 x max 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: 3 1 2 3 4 2 1

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

Fast Objects Use shortest distance between two line segments, or ellipsoids, or larger bounding spheres. 3 1 2 3 4 2 1

Fast Objects Solve for precise time to do good physics calculations 3 t =? 1 2 3 4 2 1

Fast Objects Alternative solution: Up the sampling rate Do many physics time steps per drawn frame 3 1 2 3 4 2 1

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?