CSE 381 – Advanced Game Programming GLSL Lighting.

Slides:



Advertisements
Similar presentations
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Advertisements

Illumination Lighting and Shading CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
Illumination and Shading
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
Rendering (彩現 渲染).
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
Lighting and Shading Wen-Chieh (Steve) Lin
(conventional Cartesian reference system)
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Course Website: Computer Graphics 16: Illumination.
LIGHTING Part One - Theory based on Chapter 6. Lights in the real world Lights bounce off surfaces and reflect colors, scattering light in many directions.
Shading Surface can either (both) 1.Emit light. E.g. light bult 2.Reflect light. E.g. Mirror.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
LIGHTING JEFF CHASTINE 1. WHAT IS LIGHT? A very complex process Find a dark area – how is it being lit? Light bounces (mirrors, shiny objects) Light refracts.
SET09115 Intro Graphics Programming
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
CS 445 / 645: Introductory Computer Graphics
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
COMP 261 Lecture 14 3D Graphics 2 of 2. Doing better than 3x3? Translation, scaling, rotation are different. Awkward to combine them. Use homogeneous.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Modelling and Simulation Types of Texture Mapping.
CS324e - Elements of Graphics and Visualization Checkerboard World.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
Illumination and Shading
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Course Introduction to virtual engineering Óbuda University John von Neumann Faculty of Informatics Institute of Applied Mathematics Lecture and laboratory.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
CS 450: COMPUTER GRAPHICS BASIC ILLUMINATION SPRING 2015 DR. MICHAEL J. REALE.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
Local Illumination and Shading
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Computer Graphics: Illumination
Computer Graphics Lecture 26 Mathematics of Lighting and Shading Part II Taqdees A. Siddiqi
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
CSE 470 Introduction to Computer Graphics Arizona State University
Chapter IX Lighting.
14th Lecture – Final Lecture
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Material Colours and Lighting
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Lighting Calculations
Presentation transcript:

CSE 381 – Advanced Game Programming GLSL Lighting

Shading Adding shadows to a rendering –adds realism –improves viewer’s spatial understanding of scene –shadows need lights

Lighting Add light sources to a scene Compute effect of lights on: –vertices –fragments What effects? –makes lighter (closer to white)? –makes darker (closer to black)? –make a channel lighter/darker Combine effects with: –materials –textures

Lighting/Shading is the difference between this:

And this:

How does light behave in the real world? Light sources produce photons Photons have different wavelengths –i.e. colors Photons travel fast (duh) –hit surfaces and may be: absorbed OR reflected OR transmitted –depends on surface properties

Selective Frequencies Surfaces selectively absorb, reflect, & transmit –Meaning different frequencies Ex: a surface may: –reflect green light –absorb all other frequencies Note: reflected photons hit our eyes –that’s what we see

Light Absorption Energy converted to heat What kinds of surfaces? –those with similar natural frequencies –refers to atoms’ vibrations Other factors: –smoothness of surface –angle light hits surface –dark absorbs more than light

Absorption Example Pure Red Ball –reflects red light –absorbs green and blue light What happens if we have blue ambient lighting? –it appears black Why? –no red to reflect

Light Reflected Surfaces reflect photons selectively

Light Transmitted Light passes through a surface Partially redirected Transparent surface –glass –water –etc.

Lighting Calculations Many models to choose from –we’ll use Phong-Blinn –note, different models produce different results Lighting Calculation Components: –Ambient –Diffuse –Specular –Emissive

Lights Each can have their own components for: –Ambient –Diffuse –Specular –Emissive

Ambient Light Light reflected so many times, source not apparent Result on color of surface rendered not affected by –light position –viewer position So far, we’ve only had ambient light

Diffuse Light Light has a direction When it hits a surface, it reflects equally –is affected by position of light source –not affected by position of viewer

Specular Light Light comes from a direction Light reflects off in a direction Is affected by: –position of light source –position of viewer

Emissive Light Light an object emits Ex: glowing machinery

Normals 3D unit vector –denotes direction a surface is facing Derived from vertices using? –cross product of 2 edges Ex: E 1 = B – A E 2 = C – A N A = E 1 X E 2 AB C E2E2 E1E1 NANA NOTE: coordinate system matters

Can vertices share a normal? Yes, depending on geometry What’s good for sharing normals? –Flat faces with sharply angled corners –Ex: box, building, wall, etc. What’s bad? –ball, balloon, etc.

For Smooth Surfaces Compute a normal for each vertex How? –average of faces it is part of What if a mesh has smooth parts and hard edges? –use smoothing groups

Remember to normalize your normals To normalize a normal, first, get length: N Length = √ (N x 2 + N y 2 + N z 2 ) Then divide each component by length N x = N X /N Length N x = N Y /N Length N x = N Z /N length Make sure all normals have a length of 1 –of course you can just use GLSL’s normalize method

Materials Properties of a surface –effect on lighting calculation during rendering –i.e. is it shiny, matte, in between? Provides realistic contrast between objects

Material Properties For each surface, specify color and intensity of: –Diffuse light reflected –Ambient light reflected –Specular light reflected –Emissive light emitted –Shininess, size of specular highlight

Attenuation Dimming with distance Lights should illuminate objects less intensely if they are far away from light source Exception: really big lights –i.e. sun, moon, etc.

Calculating Attenuation Three factors to set: –Constant (k c ) –Linear (k l ) –Quadratic (k q ) And d = distance from light source What do we do with this value? –multiply the diffuse, specular, and source-specific ambient light colors by this factor to reduce the intensity of the light as the object moves away from it 1 k c + k c d + k c d 2 Attenuation Factor =

Blinn-Phong Model Calculate per vertex lighting Interpolate effect across fragment For calculation combine any or all of: –D: Diffuse effect (use Lambertian Reflection) –S: Specular term (use Blinn-Phong Reflection) –A: Light Specific Ambient Light OR –A: Global Ambient Light Color = Color + D + S + A

Lambertian Reflection Intensity of diffuse light on surface depends on angle of the surface to the light source Diffuse Light Intensity = max(L ∙ N, 0.0) × C × I L:light direction i.e., light position – vertex position N:surface normal C:material’s diffuse color I:light’s diffuse property (intensity)

Remember the Dot Product? V1 ∙ V2 > 0 V1 V2 V1 ∙ V2 = -1 V1 V2 V1 ∙ V2 < 0 V1 V2 V1 ∙ V2 = 0 V1 V2 V1 ∙ V2 == V2 ∙ V1

The Specular Term First calculate the half vector What’s that? –halfway between the eye vector and the light vector How? –add light and eye vectors: H = L + E Note again: –L is vertex to light source location –E is vertex to eye location

Using the Half Vector Specular Term = max(N ∙ H, 0) S × S m × S l H:half vector N:surface normal S:material’s shininess value S m :material’s specular color S l :light’s specular color What do we do with this? –multiply by an attenuation factor, then –add it to the final fragment color

Ambient Light Component Light-specific ambient light –use ambient values of a light source –can be attenuated OR Global ambient light –a constant that affects the whole scene –not attenuated To calculate: –multiply light’s ambient term by material’s ambient reflectance and add to final color

Normal Matrix As models rotate, so do their normals To update normals, use a 3x3 normal matrix –rotation component of modelview matrix To use:: // a_Normal is the normal vertex attribute // normal holds the final transformed normal mat3x3 normalMatrix = mat3x3(modelview_matrix); vec3 normal = normalize(normalMatrix * a_Normal);

GLSL Lighting Let’s look at different types of lights: –Directional –Point –Spotlights We can add multiples of each to our scenes

Directional Lighting Light comes from a direction Has no source location –infinitely far away (i.e., the sun) –affects all objects similarly Cheap to use –no attenuation/distance calculations In calculations, the light position is the direction Let’s look at the ch08_terrain_lighting example’s vertex shader

Point Lights Have a position, not a direction Radiates light in all directions Suffer from attenuation Otherwise, it’s a similar calculation Let’s look at the ch08_point_light example

Spotlights A specialized point light Radiates light only in a directional cone Properties: –location –direction –cutoff angle (θ) –spotlight exponent how rapidly the intensity drops from center to wall of cone Let’s look at ch08_spot_light example θ

What if we want multiple lights Simple Option: –render the scene multiple times, one for each light –blend results each pass using additive blending Expensive Better Option: –have shader loop through light sources passed as uniform variables Look at the ch_08_multiple_lights example