Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Similar documents
Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Computer Graphics (CS 543) Lecture 9b: Shadows and Shadow Maps. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics. - Shading & Texturing -

Shading, lighting, & BRDF Theory. Cliff Lindsay, PHD

Shading 1: basics Christian Miller CS Fall 2011

Computer Graphics MTAT Raimond Tunnel

9. Illumination and Shading

Virtual Reality for Human Computer Interaction

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

CS5620 Intro to Computer Graphics

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Shading. Shading = find color values at pixels of screen (when rendering a virtual 3D scene).

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

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

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

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

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

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

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

Computer Graphics. Illumination and Shading

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

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

The Rasterization Pipeline

Computer Graphics. Illumination and Shading

Visualisatie BMT. Rendering. Arjan Kok

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

Illumination in Computer Graphics

Illumination Models & Shading

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

CPSC 314 LIGHTING AND SHADING

INF3320 Computer Graphics and Discrete Geometry

High-Quality Unstructured Volume Rendering on the PC Platform

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Lighting and Materials

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

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

Basic GPU techniques Josef Pelikán CGG MFF UK Praha.

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

CS452/552; EE465/505. Intro to Lighting

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Objectives. Introduce the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

Illumination and Shading

Illumination & Shading I

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Nearest Neighbor Learning

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

CS Illumination and Shading. Slide 1

Lighting Models. CS116B Chris Pollett Mar 21, 2004.

CEng 477 Introduction to Computer Graphics Fall

Lighting affects appearance

Computer Graphics Coursework 1

CPSC / Illumination and Shading

-=Bui Tuong Phong's Lighting=- University of Utah, but with shaders. Anton Gerdelan Trinity College Dublin

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS 432 Interactive Computer Graphics

Illumination and Shading

Chapter 7 - Light, Materials, Appearance

Introduction. Lighting model Light reflection model Local illumination model Reflectance model BRDF

Shading I Computer Graphics I, Fall 2008

Introduction to Visualization and Computer Graphics

Illumination & Shading: Part 1

CS452/552; EE465/505. Lighting & Shading

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Shading Models. Welcome!

Shading and Illumination

CS 4600 Fall Utah School of Computing

w Foley, Section16.1 Reading

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

CGT520 Lighting. Lighting. T-vertices. Normal vector. Color of an object can be specified 1) Explicitly as a color buffer

Illumination & Shading

A Two-Step Approach for Interactive Pre-Integrated Volume Rendering of Unstructured Grids

Virtual Reality for Human Computer Interaction

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

Color and Light. CSCI 4229/5229 Computer Graphics Summer 2008

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

Recall: Indexing into Cube Map

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

TDA361/DIT220 Computer Graphics, January 15 th 2016

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

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

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

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

Light Transport Baoquan Chen 2017

How do we draw a picture?

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

Shading and Texturing Due: Friday, Feb 17 at 6:00pm

CS 498 VR. Lecture 19-4/9/18. go.illinois.edu/vrlect19

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

LCD Video Controller. LCD Video Controller. Introduction Safety Precautions Indentifying the Components... 5

Mali Demos: Behind the Pixels. Stacy Smith

Surface Reflection Models

Pipeline Operations. CS 4620 Lecture 14

OpenGL Lighting Computer Graphics Spring Frank Palermo

Phong Lighting & Materials. Some slides modified from: David Kabala Others from: Andries Van Damm, Brown Univ.

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

Transcription:

Shading Sides by Uf Assarsson and Tomas Akenine-Möer Department of Computer Engineering Chamers University of Technoogy

Overview of today s ecture A simpe most basic rea-time ighting mode It is aso OpenGL s od fixed pipeine ighting mode Fog Gamma correction Transparency and apha

Compute ighting at vertices, then interpoate over triange ight bue Rasterizer Geometry red green How compute ighting? We coud set coors per vertex manuay For a itte more reaism, compute ighting from Light sources Materia properties Geometrica reationships Tomas Akenine-Mőer 2002

The ambient/diffuse/specuar/emission mode Aso the most basic rea-time mode: Light interacts with materia and change coors at bounces: outcoor rgb ~ materia rgb ightcoor rgb Diffuse ight: the part that spreads in a direction (view independent) due to that the surface is rough on microscopic eve n

The ambient/diffuse/specuar/emission mode Aso the most basic rea-time mode: Light interacts with materia and change coors at bounces: outcoor rgb ~ materia rgb ightcoor rgb Diffuse ight: the part that spreads in a direction (view independent) Specuar ight: the part that spreads mosty in the refection direction (often same coor as ight source) n

The ambient/diffuse/specuar/emission mode Aso the most basic rea-time mode: Light interacts with materia and change coors at bounces: outcoor rgb ~ materia rgb ightcoor rgb Diffuse ight: the part that spreads in a direction (view independent) Specuar ight: the part that spreads mosty in the refection direction (often same coor as ight source) Ambient ight: incoming background ight from a directions and spreads in a directions (view-independent and ight-position independent coor) n

The ambient/diffuse/specuar/emission mode Aso the most basic rea-time mode: Light interacts with materia and change coors at bounces: outcoor rgb ~ materia rgb ightcoor rgb Diffuse ight: the part that spreads in a direction (view independent) Specuar ight: the part that spreads mosty in the refection direction (often same coor as ight source) Ambient ight: incoming background ight from a directions and spreads in a directions (view-independent and ight-position independent coor) Emission: sef-gowing surface n

A basic ighting mode Materia: Ambient (r,g,b,a) Diffuse (r,g,b,a) Specuar (r,g,b,a) Light: Ambient (r,g,b,a) Diffuse (r,g,b,a) Specuar (r,g,b,a) DIFFUSE Base coor SPECULAR Highight Coor AMBIENT Low-ight Coor EMISSION Gow Coor SHININESS Emission (r,g,b,a) = sjävysande färg Surface Smoothness Tomas Added Akenine-Mőer by Uf Assarsson, 2002 2004

Ambient component: iamb Ad-hoc tries to account for ight coming from other surfaces Just add a constant coor: i amb = m amb Äs amb i.e., (i r, i g, i b, i a ) = (m r, m g, m b, m a ) ( r, g, b, a )

Diffuse component : idiff i=iamb+idiff+ispec Diffuse (Lambert s aw): i diff = n Photons are scattered equay in a directions i diff = ( n ) m diff Äs diff = cosf n and are assumed being unit vectors Tomas Akenine-Mőer 2002

Lambertian Surfaces Perfecty diffuse refector Light scattered equay in a directions Highy refective surface (specuar) Fuy diffuse surface (Lambertian)

Lighting Specuar component : ispec Diffuse is du (eft) Specuar: simuates a highight Tomas Akenine-Mőer 2002

Specuar component: Phong Phong specuar highight mode Refect around n: r r = - + 2(n )n i = ( r v) = (cos r) spec m shi m shi ( n ) n - n n must be unit vector n i spec = ((n ) < 0)? 0 : max(0,(r v)) m shi m spec s spec Next: Binns highight formua: (n. h) m Tomas Akenine-Mőer 2002

Hafway Vector Binn proposed repacing v r by n h where h = (+v)/ + v (+v)/2 is hafway between and v If n,, and v are copanar: y = f/2 Must then adjust exponent so that (n h) e (r v) e (e 4e)

Efficiency The Binn rendering mode is ess efficient than pure Phong shading in most cases, since it contains a square root cacuation. Whie the origina Phong mode ony needs a simpe vector refection, this modified form takes more into consideration. However, as many CPUs and GPUs contain singe and doube precision square root functions (as standard features) and other instructions that can be used to speed up rendering -- the time penaty for this kind of shader wi not be noticed in most impementations. However, Binn-Phong wi be faster in the case where the viewer and ight are treated to be at infinity. This is the case for directiona ights. In this case, the haf-ange vector is independent of position and surface curvature. It can be computed once for each ight and then used for the entire frame, or indeed whie ight and viewpoint remain in the same reative position. The same is not true with Phong's origina refected ight vector which depends on the surface curvature and must be recacuated for each pixe of the image (or for each vertex of the mode in the case of vertex ighting). In most cases where ights are not treated to be at infinity, for instance when using point ights, the origina Phong mode wi be faster.

Lighting i=iamb+idiff+ispec + + = This is just a hack! Has itte to do with how reaity works! Tomas Akenine-Mőer 2002

Additions to the ighting equation Accounting for distance: 1/(a+bt+ct 2 ) Severa ights: just sum their respective contributions Different ight types: Tomas Akenine-Mőer 2002

Carifications Energy is emitted at equa proportions in a directions from a spherica radiator. Due to energy conservation, the intensity is proportiona to the spherica area at distance r from the ight center. A = 4πr 2 Thus, the intensity scaes ~ 1/r 2 r

Shading Shading: do ighting (at e.g. vertices) and determine pixe s coors from these Three common types of shading: Fat, Goraud, and Phong Tomas Akenine-Mőer 2002

Shading Three common types of shading: Fat, Goraud, and Phong In standard Gouraud shading the ighting is computed per triange vertex and for each pixe, the coor is interpoated from the coors at the vertices. In Phong Shading the ighting is not computed per vertex. Instead the norma is interpoated per pixe from the normas defined at the vertices and fu ighting is computed per pixe using this norma. This is of course more expensive but ooks better. Fat Gouraud Phong Tomas Akenine-Mőer 2002

// Vertex Shader #version 130 Gouraud Shading Code in vec3 vertex; in vec3 norma; uniform vec4 mtramb, mtrdiffuse, mtrspec, mtremission; uniform vec4 ightamb, ightdiffuse, ightspec, ightemission; uniform foat shininess; uniform mat4 modeviewprojectionmatrix, normamatrix, modeviewmatrix; uniform vec4 ightpos; // in view space out vec3 outcoor; For one ight source // Fragment Shader: #version 130 in vec3 outcoor; out vec4 fragcoor; void main() { g_position = modeviewprojectionmatrix*vec4(vertex,1); // ambient outcoor = ightamb * mtramb; // diffuse vertex = vec3(modeviewmatrix * vec4(vertex,1)); norma = normaize(normamatrix * norma); vec3 ightdirection = normaize(ightpos vertex.xyz); foat intensity=max(0, dot(norma, ightdirection) outcoor += ightdiffuse*mtrdiffuse*intensity; void main() { } fragcoor = vec4(outcoor,1); } // specuar vec3 viewvec = -vertex.xyz; // because we are in view space vec3 refvec = -ightdirection + norma*(2*dot(norma*ightdirection)) r = - + 2(n )n intensity=pow(max(0,(dot(refvec, viewvec)), shininess)); outcoor += ightspec * mtrspec * max(0,intensity); i spec = ((n ) < 0)? 0 : max(0,(r v)) m shi m spec s spec

Phong Shading Code For one ight source // Vertex Shader #version 130 in vec3 vertex; in vec3 norma; uniform vec3 mtramb; uniform vec3 ightamb; uniform vec4 ightpos; uniform mat4 modeviewprojectionmatrix; uniform mat4 normamatrix; uniform mat4 modeviewmatrix; out vec3 outcoor; out vec3 N; out vec3 viewvec; out vec3 ightdirection; void main() { g_position = modeviewprojectionmatrix* vec4(vertex,1); } // ambient outcoor = ightamb * mtramb; N= normaize(normamatrix * norma); ightdirection = normaize(ightpos vertex.xyz); viewvec=-vec3(modeviewmatrix*vec4(vertex,1)); // Fragment Shader: #version 130 in vec3 outcoor, ightdirection, N, pos; in vec3 viewvec; uniform vec3 mtrdiffuse, mtrspec, mtremission; uniform vec3 ightdiffuse, ightspec, ightemission; uniform foat shininess; out vec4 fragcoor; void main() { } N = normaize(n); // renormaize due to the interpoation // diffuse foat intensity=max(0, dot(n, ightdirection) outcoor += ightdiffuse*mtrdiffuse*intensity; // specuar vec3 refvec = -ightdirection + N*(2*dot(N*ightDirection)); intensity=pow(max(0,(dot(refvec, viewvec)), shininess)); outcoor += ightspec * mtrspec * max(0,intensity); fragcoor = vec4(outcoor,1);

Transparency and apha Transparency Very simpe in rea-time contexts The too: apha bending (mix two coors) Apha (a) is the forth coor component (r,g,b,a) e.g., of the materia for a triange Represents the opacity 1.0 is totay opaque 0.0 is totay transparent The over operator: c = ac + ( 1-a) c o Rendered object s d

Transparency Need to sort the transparent objects Render back to front (bending is order dep.) See next side c = ac + ( 1-a) c Lots of different other bending modes Can store RGBa in textures as we o Rendered fragment s Background d So the texes with a=0.0 do not not hide the objects behind Uf Assarsson 2007

Transparency Need to sort the transparent objects First, render a non-transparent trianges as usua. Then, sort a transparent trianges and render them back-to-front with bending enabed. The reason for sorting is that the bending operation (i.e., over operator) is order dependent. Tomas Akenine-Mőer 2002

Bending Used for Transparency c = ac + ( 1-a) c o s d gbendfunc(gl_src_alpha, GL_ONE_MINUS_SRC_ALPHA) Effects (shadows, refections) (Compex materias) Quake3 used up to 10 rendering passes, bending toghether contributions such as: Diffuse ighting (for hard shadows) Bump maps Base texture Specuar and emissive ighting Voumetric/atmospheric effects Enabe with genabe(gl_blend) 26 Uf Assarsson 2003

Fog Simpe atmospheric effect A itte better reaism Hep in determining distances Tomas Akenine-Mőer 2002

Coor of fog: c c p = fc s + (1 f )c f How to compute f? f coor of surface: f [0,1] 3 ways: inear, exponentia, exponentia-squared Linear: f = z z end end - - z z p start cs Tomas Akenine-Mőer 2002

Fog exampe Often just a matter of Choosing fog coor Choosing fog mode Od OpenGL just turn it on. New OpenGL program it yoursef in the fragment shader Tomas Akenine-Mőer 2002

Fog in up-direction Tomas Akenine-Mőer 2002

rgb_out Gamma correction Lighting computes rgb coor intensities in inear space from [0,1] x γ γ = 2.2 darker brighter darker brighter rgb_in screen = rgb_in x γ : perceived in. intensity: inear intensity: However, CRT-monitor output is exponentia. Has more precision for darker regions. Very Good! But we need to adapt the input to utiize this. Ese, our images wi be too dark. Expon. distribution better for humans. Our eyes have noninear sensitivity and monitors have imited brightness Intensities: x γ vs inear Textures: store in gamma space for better ditributed precision. So, store coor intensities with more precision for darker coors: i.e., convert coor to x (1 / γ) before storing in 8- bits in the frame buffer. Conversion to x (1 / γ) is caed gamma correction. x (1 / γ) x γ (x (1 / γ) ) γ x (1 / γ) intensity Shader rgb coors Frame buffer rgb coors. Dark pixes are made brighter Dispayed by CRT Framebuf. rgb: 0 0.5 0.66 0.8 0.9 1 Shader rgb: 0 0.2 0.4 0.6 0.8 1 Linear output again, but redistributed precision.

Gamma correction If input to gun is 0.5, then you don t get 0.5 as output in intensity Instead, gamma correct that signa: gives inear reationship Tomas Akenine-Mőer 2002

Gamma correction I = a( V +e) g I=intensity on screen V=input votage (eectron gun) a,e, and g are constants for each system Common gamma vaues: 2.2-2.6 Assuming e=0, gamma correction is: c = c i ( 1/ g ) Tomas Akenine-Mőer 2002

Why is it important to care about gamma correction? Portabiity across patforms Image quaity Texturing Anti-aiasing One soution is to put gamma correction in hardware srgb asumes gamma=2.2 Can use EXT_framebuffer_sRGB to render with gamma correction directy to frame buffer

Gamma correction today Standard is 2.2 Happens to give more efficient coor space when compressing intensity from 32-bit foats to 8-bits. Thus, sti motivated. better distribution for humans Gamma of 2.2 Truth On most dispays (those with gamma of about 2.2), one can observe that the inear intensity output (bottom) has a arge jump in perceived brightness between the intensity vaues 0.0 and 0.1, whie the steps at the higher end of the scae are hardy perceptibe. A inear input that has a nonineary-increasing intensity (upper), wi show much more even steps in perceived brightness.

What is important Amb-, diff-, spec-, emission mode + formuas Phong s + Binn s highight mode Fat-, Gouraud- and Phong shading Transparency Fog Tomas Akenine-Mőer 2002

THE END