TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Similar documents
ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Comp 410/510 Computer Graphics. Spring Shading

Computer Graphics. Illumination and Shading

Illumination & Shading

Complex Shading Algorithms

CPSC / Illumination and Shading

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

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

Shading I Computer Graphics I, Fall 2008

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

CS5620 Intro to Computer Graphics

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Illumination & Shading: Part 1

Introduction to Computer Graphics 7. Shading

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

CS452/552; EE465/505. Intro to Lighting

Illumination Models & Shading

Illumination and Shading

Visualisatie BMT. Rendering. Arjan Kok

CPSC 314 LIGHTING AND SHADING

Shading and Illumination

Computer Graphics. Illumination and Shading

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

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

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

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

Interactive Real-Time Raycasting

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

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

Computer Graphics and GPGPU Programming

The Rasterization Pipeline

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

From Graphics to Visualization

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

Illumination and Shading

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

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

Introduction to Visualization and Computer Graphics

Computer Graphics Coursework 1

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

Virtual Reality for Human Computer Interaction

Shading. Why we need shading. Scattering. Shading. Objectives

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

CS230 : Computer Graphics Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

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

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

Chapter 7 - Light, Materials, Appearance

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

Illumination & Shading I

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

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

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

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

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

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

w Foley, Section16.1 Reading

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

Pipeline Operations. CS 4620 Lecture 10

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Turn on the Lights: Reflectance

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

Interpolation using scanline algorithm

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

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

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Pipeline Operations. CS 4620 Lecture 14

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

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

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

CSE 681 Illumination and Phong Shading

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

Illumination and Shading

CS 130 Exam I. Fall 2015

Local Illumination physics. Law of reflection and Snell s law of refraction

Computergraphics Exercise 15/ Shading & Texturing

CS 4600 Fall Utah School of Computing

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

CS 5625 Lec 2: Shading Models

Lighting and Shading

Raytracing CS148 AS3. Due :59pm PDT

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

CHAPTER 1 Graphics Systems and Models 3

Lab 9 - Metal and Glass

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

Models and Architectures

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

Shading. Brian Curless CSE 457 Spring 2017

Rendering Light Reflection Models

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

Sung-Eui Yoon ( 윤성의 )

CS 130 Final. Fall 2015

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

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

INFOGR Computer Graphics

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Transcription:

1(84) Information Coding / Computer Graphics, ISY, LiTH TSBK 07 Computer Graphics Ingemar Ragnemalm, ISY 1(84)

Lecture 5 3D graphics part 3 Illumination Illumination applied: Shading Surface detail: Mappings Texture mapping... 2(84)2(84)

3D models Bunny Utah Teapot Teddy 3(84)3(84)

The OpenGL pipeline Vertices Vertex processing: Transformations Primitive assembly Primitives Clip & cull Frame buffer operations: Z-buffer & stencil test, write pixel Fragment processing: shading & texture Fragments Rasterization Pixels Let's do something here 4(84)4(84)

Varying Values sent from vertex shaders are interpolated and sent to fragments Key component for all fragment shaders 5(84)5(84)

Illumination We know where to put a polygon. Now, what should we fill it with? What pixel value should we choose? Several factors to take into account. The most important ones: Shading, illumination. Texture mapping. Shading is determined according to an illumination model. 6(84)6(84)

Light sources Reflecting surface Light source Resulting light intensity 7(84)7(84)

Light sources Small sources can be modelled as point light source Others can be modelled as distributed light sources 8(84)8(84)

Reflections Diffuse reflection Specular reflection Paper Plastic Metal Mirror 9(84)9(84)

3-component illumination model A common simple illumination model is built from three components: Ambient light Diffuse reflections Specular reflections 10(84) 10(84)

Ambient light Same everywhere I amb = k d * I a Light emitted from surface Diffuse reflectivity Ambient light level of scene 11(84)11(84)

Diffuse reflections Ideal diffuse reflector = Lambertian surface Incoming light produces same intensity in all directions 12(84)12(84)

Lambert s cosine law I diff = k d *I l *cos θ θ Light emitted Light level of light source from surface Diffuse reflectivity 13(84)13(84)

Example: Diffuse sphere k d = 1 I l = 0.9 I a = 0.1 14(84)14(84)

Dot product is nicer than angles cos θ = s n s θ n I diff = k d *I l *s n 15(84)15(84)

Specular reflections Incoming light produces higher intensity around the mirroring angle The width of the highlight varies with surface types 16(84)16(84)

The Phong model I spec = W(θ)*I l *cos α φ s n r θ θ φ v or I spec = k s *I l *cos α φ cos φ = r v 17(84)17(84)

Calculation of R Mirror s by n s n r θ θ φ v 18(84)18(84)

Total contribution from one light source I amb = k d * I a s n r θ θ φ v I diff = k d *I l *s n I spec = k s *I l *(r v)α I total = I amb + I diff + I spec 19(84)19(84)

Clamping shading Note that the three-component light model will produce negative light This will cause problems in scenes with several light sources + - To avoid problems, clamp the resulting value, e.g. max(0, light) 20(84)20(84)

Complete formula I = I amb + I diff + I spec = = k d * I a + ( k d *I l *max(0, s n) + k s *I l *max(0, r v) α ) ) where sums over all light sources 21(84)21(84)

Examples Diffuse surface, k d = 0.9 Specular surface, n = 1 Specular surface, n = 5 Specular surface, n = 25 k d = 0.45 k s = 0.5 I l = 1.0 I a = 0.1 Specular surface, n = 125 22(84)22(84)

Examples Specular surface, n = 5 Specular surface, n = 25 k d = 0.45 k s = 0.5 I l = 1.0 I a = 0.1 Specular surface, n = 125 23(84)23(84)

Alternative formulation Blinn-Phong s n θ α h θ+α v Halfway vector h = (s+v) / s + v I spec = k s *I l *cos n α = = I spec = k s *I l *(n h) 24(84)24(84)

Advanced illumination models Make ks a function of the viewing angle - better modelling of glass and paper BRDF - highly general multi-dimensional function 25(84)25(84)

Global illumination models Radiosity: Models light exchange recusively Ray-tracing, trace viewing rays. Photon mapping, backwards ray-tracing, trace lighting rays. 26(84)26(84)

Polygon shading Using the illumination models in high-speed polygon rendering 27(84)27(84)

Three ways to render a shaded polygon: Flat shading Gouraud shading Phong shading 28(84)28(84)

Flat shading Intensity calculated once and for all for the whole polygon E.g. Ip = k d N L 29(84)29(84)

Flat shading is correct when: 1) The surfaces should be flat, not approximating a curved surface 2) Distance to light source high => N L constant 3) Distance to camera high => V R constant and in particular 4) When the problem is not lighting, but something else (Rendering surface identifications) 30(84)30(84)

Gouraud shading L N Intensity calculated once per vertex Each vertex has its own surface normal L L N Interpolate intensities N 31(84)31(84)

Gouraud shading can simulate curved surfaces fairly well, but many polygons may be needed, and edges remain visible Calculations in vertex shader - extremely fast 32(84)32(84)

Phong shading L N Each vertex has its own surface normal Normal vectors are interpolated L L N N 33(84)33(84)

Phong shading can simulate curved surfaces very well, even with low polygon counts Calculate the light in the fragment shader Computationally heavier 34(84)34(84)

Phong shading The Phong model Phong Shading doesn t necessarily use specular reflections. Phong Shading = normal-vector interpolation shading 35(84)35(84)

Example: Gouraud shader Transform normal vectors Calculate shading value per vertex, (here using diffuse only), by dot product with light direction Interpolate between vertices 36(84)36(84)

Gouraud shader - vertex shader #version 150 in vec3 inposition; in vec3 innormal; out vec3 excolor; void main(void) { const vec3 light = vec3(0.58, 0.58, 0.58); float shade; shade = dot(normalize(innormal), light); shade = clamp(shade, 0, 1); excolor = vec3(shade); gl_position = vec4(inposition, 1.0); } 37(84)37(84)

Gouraud shader - fragment shader #version 150 in vec3 excolor; out vec4 outcolor; void main(void) { outcolor = vec4(excolor,1.0); } 38(84)38(84)

Gouraud shader Note: The variable excolor is interpolated between vertices dot() och normalize() do what you expect. innormal is the normal vector in model coordinates (Should be transformed in a real program) The constant vector light is here hard coded 39(84)39(84)

Typical Gouraud shaded bunny 40(84)40(84)

Version 2: Add specular lighting to vertex shader // Specular vec3 reflectedlightdirection = reflect(-light, norm); vec3 eyedirection = vec3(normalize(-inposition)); float specularstrength = 0.0; specularstrength = dot(reflectedlightdirection, eyedirection); float exponent = 8.0; specularstrength = max(specularstrength, 0.01); specularstrength = pow(specularstrength, exponent); shade = (0.3*diffuseshade + 0.9*specularStrength); } (Again some transformations skipped.) 41(84)41(84)

Specular Gouraud shaded bunny A bit polygonal... 42(84)42(84)

Example: Phong shader Better shading Interpolate normal vectors between vertices Calculate shading value per fragment Practically the same operations, but the light calculation are done in the fragment shader 43(84)43(84)

Phong shader Vertex shader #version 150 in vec3 inposition; in vec3 innormal; out vec3 exnormal; out vec3 surf; void main(void) { exnormal = innormal; surf = inposition; // For specular gl_position = vec4(inposition, 1.0); } 44(84)44(84)

Phong shader Fragment shader #version 150 out vec4 outcolor; in vec3 exnormal; in vec3 surf; void main(void) { const vec3 light = vec3(0.58, 0.58, 0.58); float shade; shade = dot(normalize(exnormal), light); shade = clamp(shade, 0, 1); outcolor = vec4(shade, shade, shade, 1.0); } 45(84)45(84)

..and add specular part // Specular vec3 reflectedlightdirection = reflect(-lightdirection, n); vec3 eyedirection = normalize(-surf); float specularstrength = 0.0; if (dot(lightdirection, n) > 0.0) { specularstrength = dot(reflectedlightdirection, eyedirection); float exponent = 200.0; specularstrength = max(specularstrength, 0.01); specularstrength = pow(specularstrength, exponent); } outcolor = vec4(diffusestrength*0.5 + specularstrength*0.5); } 46(84)46(84)

Specular Phong shaded bunny Now we re talking 47(84)47(84)

Use the shading you need, balance computing and quality Gouraud Phong 48(84)48(84)

Same for Stanford bunny Gouraud Phong 49(84)49(84)