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

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

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

CS452/552; EE465/505. Lighting & Shading

CS 4600 Fall Utah School of Computing

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

CS Surface Rendering

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

Introduction to Computer Graphics with WebGL

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

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment 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

Why we need shading?

CS 432 Interactive Computer Graphics

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

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

Computer Graphics. Illumination and Shading

Display Issues Week 5

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

Shading and Illumination

Illumination Models & Shading

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

CSE 167: Lecture #8: Lighting. 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

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

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Illumination and Shading ECE 567

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

Computer Graphics (CS 4731) Lecture 18: Lighting, Shading and Materials (Part 3)

INF3320 Computer Graphics and Discrete Geometry

CHAPTER 1 Graphics Systems and Models 3

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

Deferred Rendering Due: Wednesday November 15 at 10pm

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

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

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

CS 130 Exam I. Fall 2015

Pipeline Operations. CS 4620 Lecture 14

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

CEng 477 Introduction to Computer Graphics Fall

Comp 410/510 Computer Graphics. Spring Shading

CS559 Computer Graphics Fall 2015

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

Illumination and Shading

CS5620 Intro to Computer Graphics

Shading. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller/Fuhrmann

Illumination & Shading: Part 1

Shading 1: basics Christian Miller CS Fall 2011

Illumination and Shading

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Introduction to Computer Graphics 7. Shading

Illumination and Shading

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

Pipeline Operations. CS 4620 Lecture 10

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

Illumination & Shading I

9. Illumination and Shading

To Do. Demo for mytest3. Methodology for Lecture. Importance of Lighting. Brief primer on Color. Computer Graphics

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

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

The Rasterization Pipeline

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

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

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

For each question, indicate whether the statement is true or false by circling T or F, respectively.

5.2 Shading in OpenGL

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

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

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

Ligh%ng and Shading. Ligh%ng and Shading. q Is this a plate or a ball? q What color should I set for each pixel?

Illumination and Shading

Lights, Colour and Materials In OpenGL

[175 points] The purpose of this assignment is to give you practice with shaders in OpenGL.

Efficient and Scalable Shading for Many Lights

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

How do we draw a picture?

CSE Intro to Computer Graphics. ANSWER KEY: Midterm Examination. November 18, Instructor: Sam Buss, UC San Diego

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

CS 130 Exam I. Fall 2015

Models and Architectures

CS452/552; EE465/505. Intro to Lighting

To Do. Demo for mytest3. Methodology for Lecture. Importance of Lighting. Brief primer on Color. Foundations of Computer Graphics (Spring 2012)

Reflection and Shading

Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

Virtual Reality for Human Computer Interaction

Topics and things to know about them:

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

Computer Graphics I Lecture 11

Light Transport Baoquan Chen 2017

Introduction to Programmable GPUs CPSC 314. Real Time Graphics

Virtual Reality for Human Computer Interaction

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Shading I Computer Graphics I, Fall 2008

Computer Graphics Coursework 1

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

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

Transcription:

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 1

Steps in OpenGL shading Enable shading and select model Specify normals Specify material properties Specify lights State-based shading function have been dropped:glnormal, glmaterial, gllight. Compute in application or in shaders 2

Normalization Cosine terms in lighting calculations can be computed using dot product Unit length vectors simplify calculation Usually we want to set the magnitudes to have unit length but Length can be affected by transformations Note that scaling does not preserved length GLSL has a normalization function 3

Normal for Triangle plane n (p - p 0 ) = 0 n p 2 n = (p 2 - p 0 ) (p 1 - p 0 ) p p 1 normalize n n/ n p 0 Note that right-hand rule determines outward face 4

Specifying a Point Light Source For each light source, we can set an RGBA for the diffuse, specular, and ambient components, and for the position var diffuse0 = vec4(1.0, 0.0, 0.0, 1.0); var ambient0 = vec4(1.0, 0.0, 0.0, 1.0); var specular0 = vec4(1.0, 0.0, 0.0, 1.0); var light0_pos = vec4(1.0, 2.0, 3,0, 1.0) 5

Distance and Direction The source colors are specified in RGBA The position is given in homogeneous coordinates If w =1.0, we are specifying a finite location If w =0.0, we are specifying a parallel source with the given direction vector The coefficients in distance terms are usually quadratic (1/(a+b*d+c*d*d)) where d is the distance from the point being rendered to the light source 6

Spotlights Derive from point source Direction Cutoff Attenuation Proportional to cos 7

Moving Light Sources Light sources are geometric objects whose positions or directions are affected by the model-view matrix Depending on where we place the position (direction) setting function, we can Move the light source(s) with the object(s) Fix the object(s) and move the light source(s) Fix the light source(s) and move the object(s) Move the light source(s) and object(s) independently 8

Material Properties var materialambient = vec4( 1.0, 0.0, 1.0, 1.0 ); var materialdiffuse = vec4( 1.0, 0.8, 0.0, 1.0); var materialspecular = vec4( 1.0, 0.8, 0.0, 1.0 ); var materialshininess = 100.0; 9

Using MV.js for Products var ambientproduct = mult(lightambient, materialambient); var diffuseproduct = mult(lightdiffuse, materialdiffuse); var specularproduct = mult(lightspecular, materialspecular); gl.uniform4fv(gl.getuniformlocation(program, "ambientproduct"), flatten(ambientproduct)); gl.uniform4fv(gl.getuniformlocation(program, "diffuseproduct"), flatten(diffuseproduct) ); gl.uniform4fv(gl.getuniformlocation(program, "specularproduct"), flatten(specularproduct) ); gl.uniform4fv(gl.getuniformlocation(program, "lightposition"), flatten(lightposition) ); gl.uniform1f(gl.getuniformlocation(program, "shininess"),materialshininess); 10

Front and Back Faces Every face has a front and back For many objects, we never see the back face so we don t care how or if it s rendered If it matters, we can handle in shader back faces not visible back faces visible 11

Emissive Term We can simulate a light source in OpenGL by giving a material an emissive component This color is unaffected by any sources or transformations 12

Transparency Material properties are specified as RGBA values The A value can be used to make the surface translucent The default is that all surfaces are opaque regardless of A Later we will enable blending and use this feature However with the HTML5 canvas, A<1 will mute colors 13

Efficiency Because material properties are part of the state, if we change materials for many surfaces, we can affect performance We can make the code cleaner by defining a material structure and setting all materials during initialization typedef struct materialstruct { GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; GLfloat shineness; } MaterialStruct; We can then select a material by a pointer 14

Polygonal Shading Shading calculations are done for each vertex Vertex colors become vertex shades By default, vertex colors are interpolated across the polygon glshademodel(gl_smooth); If we use glshademodel(gl_flat); the color at the first vertex will determine the color of the whole polygon 15

Polygon Normals Polygons have a single normal Consider model of sphere Want different normals at each vertex even though this concept is not quite correct mathematically 16

Smooth Shading We can set a new normal at each vertex Easy for sphere model If centered at origin n = p Now smooth shading works Note silhouette edge 17

Mesh Shading The previous example is not general because we knew the normal at each vertex analytically For polygonal models, Gouraud proposed we use the average of normals around a mesh vertex n n 1 n1 n n 2 2 n3 n 3 n 4 n 4 18

Gouraud and Phong Shading Gouraud Shading Find average normal at each vertex (vertex normals) Apply Phong model at each vertex Interpolate vertex shades across each polygon Phong shading Find vertex normals Interpolate vertex normals across edges Find shades along edges Interpolate edge shades across polygons 19

Comparison If the polygon mesh approximates surfaces with a high curvatures, Phong shading may look smooth while Gouraud shading may show edges Phong shading requires much more work than Gouraud shading Usually not available in real time systems Both need data structures to represent meshes so we can obtain vertex normals Gouraud shading is all standard opengl implements. To get Phong shading must use fragment shader. 20