Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.

Slides:



Advertisements
Similar presentations
SI23 Introduction to Computer Graphics
Advertisements

5.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 5 A Simple Reflection Model.
Computer Graphics I, Fall 2010 Shading II.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6.
EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 3: Lighting and Materials.
Non-photorealistic Rendering.  a longtime goal of graphics research has been to render a scene that is indistinguishable from a photograph of the scene.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
Illumination and Shading
Based on slides created by Edward Angel
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
Rendering (彩現 渲染).
3/23/2005 © Dr. Zachary Wartell 1 Illumination Models and Surface- Rendering Methods.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Lighting and Shading Week.
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.
Illumination.
Computer Graphics Lighting.
Lecture 5: 3D Rendering Pipeline (II) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology.
Geometry Shaders. Visualizing Normal Vectors  textbook calls this a “hedgehog plot” but (I think) that this is a misuse of the term  a hedgehog plot.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Computer Graphics I, Fall 2010 Shading in OpenGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 381 – Advanced Game Programming GLSL Lighting.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Illumination.
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
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
CS 450: COMPUTER GRAPHICS BASIC ILLUMINATION SPRING 2015 DR. MICHAEL J. REALE.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
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
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Current Student – University of Wisconsin – Stout Applied Mathematics and Computer Science: Software Development Associate Degree in Computer Programming.
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Lighting.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
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)
03/19/2002(c) University of Wisconsin, CS 559 Last Time BSP Tree rendering and exact visibility in mazes Local Shading –Diffuse term –Specular term.
Light. Intensity calculation = wavelength I( ) = wavelength intensity of light reaching eye I( ) = I diff ( ) + I spec ( ) + I refl ( ) + I trans ( )
Computer Graphics: Illumination
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
Shading To determine the correct shades of color on the surface of graphical objects.
Introduction to Computer Graphics with WebGL
Tips for Shading Your Terrain
CS 480/680 Computer Graphics Shading.
Day 05 Shader Basics.
Introduction to Computer Graphics with WebGL
CSE 470 Introduction to Computer Graphics Arizona State University
Lighting – Light Sources
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Chapter IX Lighting.
Simple Illumination CSE 681.
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
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:

Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting

Ambient Reflection  ambient light reflected by an object depends on the incident light intensity and the material ambient reflection coefficient  ambient r,g,b = light r,g,b * ambreflcoeff r,g,b

Ambient Reflection  uniforms // light intensity (assuming white light) uniform float uI; // ambient reflection coefficients uniform vec4 uAmb;

Ambient Reflection  code // ambient intensity vec3 ambient = uI * vec3(uAmb);

Diffuse Reflection  diffuse light reflected by an object depends on the incident light intensity, the angle between the normal vector and light direction, and the material diffuse reflection coefficient  diffuse r,g,b = light r,g,b * cos( θ ) * diffreflcoeff r,g,b

Diffuse Reflection  attributes // vertex location in vec4 aVertex; // normal direction at aVertex in vec3 aNormal;

Diffuse Reflection  uniforms uniform mat4 uModelViewMatrix; uniform mat4 uNormalMatrix; // diffuse reflection coefficients uniform vec4 uDiff; // light location in eye coordinates uniform float uX; uniform float uY; uniform float uZ;

Diffuse Reflection  code // surface normal in eye coordinates vec3 eyeNormal = normalize(vec3(uNormalMatrix * aNormal)); // vertex position in eye coordinates vec4 vPosition4 = uModelViewMatrix * aVertex; vec3 vPosition3 = vPosition4.xyz / vPosition4.w; // vector to light source vec3 lightPosition = vec3(uX, uY, uZ); vec3 lightDir = normalize(lightPosition - vPosition3); // dot product gives us diffuse intensity float diff = max(0.0, dot(eyeNormal, lightDir)); // multiply intensity by diffuse color and light intensity vec3 diffuse = uI * diff * vec3(uDiff);

Specular Reflection  specular light reflected by an object depends on the incident light intensity, the angle between the reflection and viewing directions, the material specular reflection coefficient, and the specular exponent (shininess)  specular r,g,b = light r,g,b * cos f ( Φ ) * specreflcoeff r,g,b

Specular Reflection  uniforms // specular reflection coefficients uniform vec4 uSpecular; // specular exponent uniform float uShininess;

Specular Reflection  code // reflection direction vec3 refl = reflect(-lightDir, eyeNormal); // viewer direction vec3 view = normalize(-vPosition3); // cosine of angle between reflection and viewer directions float cosPhi = max(0.0, dot(view, refl)); // specular intensity float spec = pow(cosPhi, uShininess); // specular color vec3 specular = uI * spec * vec3(uSpecular);

Total Reflection  just the sum of the ambient, diffuse, and specular components  total r,g,b = ambient r,g,b + diffuse r,g,b + specular r,g,b

Total Reflection  out // total out vec4 vColor;

Total Reflection  code // total color vColor.rgb = clamp(ambient + diffuse + spec, 0.0, 1.0); vColor.a = 1.0; // don’t forget to transform the geometry gl_Position = uModelViewProjectionMatrix * aVertex;

Halfway Vector  instead of computing the reflection direction you can use the halfway vector (the vector halfway between V and L)  H = V + L (then normalize H)  specular r,g,b = light r,g,b * cos f ( Φ ) * specreflcoeff r,g,b Φ

Emitted Light  fixed pipeline OpenGL also has an emission term in the lighting calculation  just a constant color added to the total // total color vColor.rgb = clamp(ambient + diffuse + spec + emission, 0.0, 1.0); vColor.a = 1.0;

Attenuation  for point light sources the intensity of the light source can be made to fall off with distance  multiply the source intensity by a falloff function where r is the distance between the light source and the vertex/fragment and s c, s l, and s q are constants

Attenuation  an alternative falloff function used in games

Attenuation  Pixar

Spotlights  θ s angle between source direction s and direction to vertex/fragment –l  θ p penumbra angle (angle where the intensity starts to decrease)  θ u umbra angle (angle where the intensity goes to zero) Real-Time Rendering, 3 rd Edition

Spotlights  OpenGL spotlight function  two zones:  spotlight zone where the light intensity varies  outside where the light intensity is zero

Spotlights  DirectX spotlight function  three zones:  inner zone where the light intensity is constant  spotlight zone where the light intensity varies  outside where the light intensity is zero