Introduction to Visualization and Computer Graphics

Similar documents
Graphics The Rasterization Pipeline Projection, Visibility, & Shading

Pipeline Operations. CS 4620 Lecture 10

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Pipeline Operations. CS 4620 Lecture 14

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

CS 130 Final. Fall 2015

CS5620 Intro to Computer Graphics

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Complex Shading Algorithms

Computer Vision Systems. Viewing Systems Projections Illuminations Rendering Culling and Clipping Implementations

The Rasterization Pipeline

Introduction to Computer Graphics 7. Shading

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CS 325 Computer Graphics

Lighting and Shading

Comp 410/510 Computer Graphics. Spring Shading

Computer Graphics. Illumination and Shading

Illumination Models & Shading

Homework #2. Shading, Ray Tracing, and Texture Mapping

Deferred Rendering Due: Wednesday November 15 at 10pm

Simple Lighting/Illumination Models

Shading, Advanced Rendering. Week 7, Wed Feb 28

COMP371 COMPUTER GRAPHICS

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

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

Illumination & Shading: Part 1

Illumination & Shading

CS452/552; EE465/505. Intro to Lighting

Photorealism: Ray Tracing

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

CS4620/5620: Lecture 14 Pipeline

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Visualisatie BMT. Rendering. Arjan Kok

Computer Graphics. Illumination and Shading

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

CHAPTER 1 Graphics Systems and Models 3

COMP environment mapping Mar. 12, r = 2n(n v) v

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Rasterization Overview

Graphics for VEs. Ruth Aylett

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

CPSC 314 LIGHTING AND SHADING

Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

CS 130 Exam I. Fall 2015

Graphics for VEs. Ruth Aylett

Illumination and Shading

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CPSC / Illumination and Shading

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

Topics and things to know about them:

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

The Rasterizer Stage. Texturing, Lighting, Testing and Blending

CPSC GLOBAL ILLUMINATION

Institutionen för systemteknik

Illumination and Shading

Reflection and Shading

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

The Traditional Graphics Pipeline

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Game Technology. Lecture Physically Based Rendering. Dipl-Inform. Robert Konrad Polona Caserman, M.Sc.

03 RENDERING PART TWO

Computergrafik. Matthias Zwicker. Herbst 2010

Raytracing CS148 AS3. Due :59pm PDT

The Traditional Graphics Pipeline

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

w Foley, Section16.1 Reading

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

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

RASTERISED RENDERING

Rendering Light Reflection Models

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Level of Details in Computer Rendering

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

Computer Graphics. Shadows

Models and Architectures

Course Title: Computer Graphics Course no: CSC209

Shading I Computer Graphics I, Fall 2008

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Graphics and Interaction Rendering pipeline & object modelling

The Traditional Graphics Pipeline

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

lecture 18 - ray tracing - environment mapping - refraction

Computer Graphics and GPGPU Programming

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Computer Graphics Lecture 11

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Ray Tracing. Kjetil Babington

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Computer Graphics. Ray Tracing. Based on slides by Dianna Xu, Bryn Mawr College

Shading. Brian Curless CSE 557 Autumn 2017

CEng 477 Introduction to Computer Graphics Fall 2007

The exam begins at 2:40pm and ends at 4:00pm. You must turn your exam in when time is announced or risk not having it accepted.

The Rasterization Pipeline

Transcription:

Introduction to Visualization and Computer Graphics DH2320, Fall 2015 Prof. Dr. Tino Weinkauf Introduction to Visualization and Computer Graphics Visibility Shading

3D Rendering Geometric Model Color Perspective Visibility Local Illumination Smooth Shading Simple Shadows Global Illumination

Visibility Algorithms

Rasterization Two Rendering Pipelines Project all triangles to the screen Rasterize them (convert to pixels) Determine visibility Apply shading (compute color) Raytracing Iterate over all pixels Determine visible triangle Compute shading, color pixel next lecture

Triangle / Polygon Rasterization Observations Straight lines remain straight! Triangles mapped to triangles After Perspective Projection Polygons to polyogns

3D Scene Rasterization Visiblity preprocessing or during rasterization Projection Visibility Rasterization

Two main algorithms Painter s algorithm (old) Simple version Correct version z-buffer algorithm Rasterization Dominant real-time method today

Painter s Algorithm

Painters Algorithm Sort primitives back-to-front Draw with overwrite Drawbacks Slowish Painter s Algorithm O(n log n) for n primitives Millions per second Wrong Not guaranteed to always work

Counter Example Correct Algorithm Need to cut primitives Several strategies Notable: BSP Algorithm in Quake Old graphics textbooks list many variants No need for us to go deeper

z-buffer Algorithm

Algorithm Store depth value for each pixel Initialize to MAX_FLOAT Rasterize all primitives z-buffer Algorithm Compute fragment depth & color Do not overwrite if fragment is farer away than the one stored the one in the buffer color depth

Advantages Extremely simple Discussion: z-buffer Versatile only primitive rasterization required Very fast GeForce 2 Ultra: 2GPixel /sec (release year: 2000) GeForce 700 GTX Titan: 35 GPixel / sec (release year: 2013)

Disadvantages Extra memory required Discussion: z-buffer This was a serious in obstacle back then... Invented 39 years ago (1974; Catmull / Straßer) Only pixel resolution Need painter s algorithm for certain vector graphics computations No transparency This is a real problem for 3D games / interactive media Often fall-back to sorting Solution: A-Buffer, but no hardware support

Rasterization and Clipping

Rasterization How to rasterize Primitives? Two problems Rasterization Clipping color depth

Assumption Triangles only Triangle not outside screen No clipping required Rasterization

Several Algorithms... Triangle Rasterization

Example: two slabs Triangle Rasterization

Triangle Rasterization Δx constant precompute and add in each step Incremental rasterization

Incremental Rasterization Precompute steps in x, y-direction For boundary lines For linear interpolation within triangle Colors Texture coordinates (more later) Inner loop Only one addition ( DDA algorithm) Floating point value Strategies Fixed-point arithmetics Bresenham / midpoint algorithm (requires if; problematic on modern CPUs)

Rasterization How to rasterize Primitives? Two problems Rasterization Clipping color depth

Why Clipping? Crashes write to off-screen memory!

Pixel Rejection if (x,y screen) continue; Clipping Strategies Can be arbitrarily slow (large triangles) Nope. Not a good idea. Screen space clipping Modify rasterizer to jump to visible pixels See tutorial 5 Efficient Still problems with when crossing camera plane (w = 0) a semi-good idea

Smart Slab Renderer Does not crash, optimal complexity O(k) for k output fragments

Problem camera plane y 1 z 2 f z 1 y = f y z y 2 image plane Problem: Triangles crossing camera plane! Wrong results Need object space clipping

View Frustum Clipping near clipping plane far clipping plane four side planes six planes clip triangles against all six planes

Incremental Algorithm

Incremental Algorithm

Incremental Algorithm Output: Multiple Triangles

View Frustum Culling Further Optimization Complex shapes (whole bunnies) Coarse bounding volume (superset) Cube, Sphere Often: Axis-aligned bounding box Reject all triangles inside if bounding volume outside view frustrum

3D Rendering Geometric Model Color Perspective Visibility Local Illumination Smooth Shading Simple Shadows Global Illumination

Shading Models

Reflectance Models mirror glossy surface diffuse surface

Interaction with Surfaces Viewer v n Light l object surface Local Shading Model Single point light source Shading model / material model Input: light vector l = pos light pos object Input: view vector v = pos camera pos object Input: surface normal n (orthogonal to surface) Output: color (RGB)

Interaction with Surfaces Viewer v n Light l object surface General scenario Multiple light sources? Light is linear Multiple light sources: add up contributions Double light strength double light output

Simplify notation Remark Define component-wise vector product x 1 y 1 x 1 y 1 x y = x 2 x 3 y 2 y 3 x 2 y 2 x 3 y 3 No fixed convention in literature The symbol only used in these lecture slides!

Lighting Calculations Remark Need to perform calculations for r, g, b-channels Often: output r = light r material r function v, l, n output g = light g material g function(v, l, n) output b = light b material b function(v, l, n) Shorter output = light_strength material function v, l, n

Shading effects Diffuse reflection Ambient reflection Perfect mirrors Glossy reflection Phong / Blinn-Phong (Cook Torrance) Transparency & refraction Shading Effects

Shading effects Diffuse reflection Ambient reflection Perfect mirrors Glossy reflection Phong / Blinn-Phong (Cook Torrance) Transparency & refraction Shading Effects

Diffuse ( Lambertian ) Surfaces n surface normal n θ n θ Equation (set to zero if negative) c ~ cos θ Less light received at flat angles c = c r c l cos θ light color surface color c intensity (scalar) c color (RGB, R 3 ) c r surface color (RGB) c l light color (RGB)

Diffuse ( Lambertian ) Surfaces n surface normal n θ n θ Equation c ~ cos θ Less light received at flat angles Attenuation: (point lights) 1 dist 2 c = c r c l cos θ 1 dist 2 light color surface color c intensity (scalar) c color (RGB, R 3 ) c r surface color (RGB) c l light color (RGB) 1 dist 2

Diffuse Reflection Diffuse Reflection Very rough surface microstructure Incoming light is scattered in all directions uniformly Diffuse surface (material) Lambertian surface (material)

Surface Normal? What is a surface normal? Tangent space: Plane approximation at a point x S Normal vector: Perpendicular to that plane Oriented surfaces: Pointing outwards (by convention) Orientation defined only for closed solids S tangent space surface normal n x R 3 point x

Triangles p 3 n p 2 Single Triangle Parametric equation p 1 + λ p 2 p 1 p 1 + μ p 3 p 1 λ, μ R Tangent space: the plane itself Normal vector p 2 p 1 p 3 p 1 Orientation convention: p 1, p 2, p 3 oriented counter-clockwise Length: Any positive multiple works (often n = 1)

Triangle Meshes Smooth Triangle Meshes Store three different vertex normals E.g., from original surface (if known) Heuristic: Average neighboring triangle normals

Lambertian Surfaces n surface normal n θ n θ Equation c = c r c l cos θ = c r c l n, l n light direction normal vector (assuming: n = l = 1) θ l

Lambertian Bunny Face Normals Interpolated Normals

Shading effects Diffuse reflection Ambient reflection Perfect mirrors Glossy reflection Phong / Blinn-Phong (Cook Torrance) Transparency & refraction Shading Effects

Ambient Reflection Problem Shadows are pure black Realistically, they should be gray Some light should bounce around... Solution: Add constant c = c a c a ambient light color surface color Not very realistic Need global light transport simulation for realistic results

Ambient Bunny Pure Lambertian Mixed with Ambient Light

Shading effects Diffuse reflection Ambient reflection Perfect mirrors Glossy reflection Phong / Blinn-Phong (Cook Torrance) Transparency & refraction Shading Effects

Perfect Reflection Perfect Reflection Rays are perfectly reflected on surface Reflection about surface normal r = 2 n, l n l r n l

Perfect Reflection Difficult to compute Need to match camera and light emitter More later: Recursive raytracing Right image: Environment mapping Silver Bunny Reflective Bunny (Interpolated Normals)

Shading effects Diffuse reflection Ambient reflection Perfect mirrors Glossy reflection Phong / Blinn-Phong (Cook Torrance) Transparency & refraction Shading Effects

Glossy Reflection Glossy Reflection Imperfect mirror Semi-rough surface Various models

Phong Illumination Model Traditional Model: Phong Model Physically incorrect (e.g.: energy conservation not guaranteed) But looks ok Always looks like plastic On the other hand, our world is full of plastic...

How does it work? Phong Model: Specular (glossy) part: (high-) light color c = c p c l r r, v v cos r,v Ambient part: c = c r c a Diffuse part: c = c r c l n, l Add all terms together p 1,2 1 0,8 0,6 0,4 0,2 0 Phong Exponents -90-60 -30 0 30 60 90 p=1 p=2 p=5 p=10 p=50 p=100 v r n l

Blinn-Phong Blinn-Phong Model: Specular (glossy) part: c = c p c l h h, n n p v h n l cos h,n Half-angle direction h = 1 2 l l + v v In the plane: h h, n Approximation in 3D n = 1 2 r r, v v

Phong+Diffuse+Ambient Bunny Blinn-Phong Bunny Interpolated Normals

Phong+Diffuse+Ambient Bunny Blinn-Phong Bunny Interpolated Normals

Better Models Phong Bunny Cook-Torrance Model

Shading effects Diffuse reflection Ambient reflection Perfect mirrors Glossy reflection Phong / Blinn-Phong (Cook Torrance) Transparency & refraction Shading Effects

Transparency Transparency Alpha-blending α = opacity Color + opacity: RGBα Blending Mix in α of front color, keep 1 α of back color 0.0 1.0 0.0 0.5 50% red, 50% green 1.0 0.0 0.0 0.5 front back c = α c front + 1 α c back Not commutative! (order matters) unless monochrome

Refraction Materials of different index of refraction Refraction: Snell s Law Light rays change direction at interfaces Snell s Law sin θ 1 sin θ 2 = n 2 n 1 n 1, n 2 : indices of refraction vacuum: 1.0, air: 1.000293 water: 1.33, glass: 1.45-1.6 θ 2 n θ 1 n n 1 n 2

Refraction Reflection Refraction Implementation (raytraced) Not a local shading model Global algorithms: mostly raytracing Various fake approximations for local shading

3D Rendering Geometric Model Color Perspective Visibility Local Illumination Smooth Shading Simple Shadows Global Illumination

Shading Algorithms

Flat Shading Flat Shading constant color per triangle

Flat Shading Gouraud Shading Algorithm compute color at vertices, interpolate color for pixels

Flat Shading Phong Shading Algorithm interpolate normals for each pixel

3D Rendering Geometric Model Color Global Illumination: next lecture Perspective Visibility Local Illumination Smooth Shading Simple Shadows Global Illumination