Recall: Indexing into Cube Map

Similar documents
Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

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

Computer Graphics (CS 543) Lecture 8c: Environment Mapping (Reflections and Refractions)

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS Computer Graphics: Hidden Surface Removal

Computer Graphics. Shadows

Computer Graphics 10 - Shadows

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Computer Graphics (CS 563) Lecture 4: Advanced Computer Graphics Image Based Effects: Part 2. Prof Emmanuel Agu

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

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

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

Computer Graphics (CS 543) Lecture 10: Normal Maps, Parametrization, Tone Mapping

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Rasterization Overview

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computergrafik. Matthias Zwicker. Herbst 2010

Computer Graphics CS 543 Lecture 1 (Part I) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Models and Architectures

CS451Real-time Rendering Pipeline

Advanced Shading I: Shadow Rasterization Techniques

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

Introduction to Computer Graphics with WebGL

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Computer Graphics (CS 543) Lecture 1 (Part 1): Introduction to Computer Graphics

lecture 18 - ray tracing - environment mapping - refraction

Shadow Rendering EDA101 Advanced Shading and Rendering

Pipeline Operations. CS 4620 Lecture 10

CS 4620 Program 3: Pipeline

Painter s HSR Algorithm

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

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

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Chapter 7 - Light, Materials, Appearance

Pipeline Operations. CS 4620 Lecture 14

Real-Time Shadows. Last Time? Schedule. Questions? Today. Why are Shadows Important?

Real-Time Shadows. MIT EECS 6.837, Durand and Cutler

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Computer Graphics Lecture 11

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

Shaders. Slide credit to Prof. Zwicker

CS 464 Review. Review of Computer Graphics for Final Exam

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

Computer Graphics Shadow Algorithms

Lecture 4. Viewing, Projection and Viewport Transformations

Computer Graphics (CS 543) Lecture 4a: Introduction to Transformations

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

COMP371 COMPUTER GRAPHICS

Graphics and Interaction Rendering pipeline & object modelling

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

The Rasterization Pipeline

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

CS 130 Final. Fall 2015

03 RENDERING PART TWO

CS452/552; EE465/505. Intro to Lighting

Shadows. Shadows. Spatial relationship between objects. Shadows as depth cue. Spatial relationship between objects

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Texture Mapping II. Light maps Environment Maps Projective Textures Bump Maps Displacement Maps Solid Textures Mipmaps Shadows 1. 7.

Shadows. COMP 575/770 Spring 2013

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

Shadows. Shadows. Spatial relationship between objects. Shadows as depth cue. Spatial relationship between objects

Deferred Rendering Due: Wednesday November 15 at 10pm

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

Render methods, Compositing, Post-process and NPR in NX Render

CS559 Computer Graphics Fall 2015

Graphics Hardware. Instructor Stephen J. Guy

Computer Graphics Introduction. Taku Komura

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

Illumination & Shading I

CHAPTER 1 Graphics Systems and Models 3

Transforms 3: Projection Christian Miller CS Fall 2011

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

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Shadows. Real-Time Hard Shadows. Collected by Ronen Gvili. Most slides were taken from : Fredu Durand Stefan Brabec

Introduction to Visualization and Computer Graphics

lecture 19 Shadows - ray tracing - shadow mapping - ambient occlusion Interreflections

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

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

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

CSE4030 Introduction to Computer Graphics

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

Lecture 8 Ray tracing Part 1: Basic concept Yong-Jin Liu.

Shadows in the graphics pipeline

Computer Science 426 Midterm 3/11/04, 1:30PM-2:50PM

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Transcription:

Recall: Indexing into Cube Map Compute R = 2(N V)N-V Object at origin Use largest magnitude component of R to determine face of cube Other 2 components give texture coordinates V R

Cube Map Layout

Example R = (-4, 3, -) Same as R = (-,.75, -.25) Use face x = - and y =.75, z = -.25 Not quite right since cube defined by x, y, z = ± rather than [, ] range needed for texture coordinates Remap by from [-,] to [,] range s = ½ + ½ y, t = ½ + ½ z Hence, s =.875, t =.375

Sphere Environment Map Cube can be replaced by a sphere (sphere map)

Sphere Mapping Original environmental mapping technique Proposed by Blinn and Newell Uses lines of longitude and latitude to map parametric variables to texture coordinates OpenGL supports sphere mapping Requires a circular texture map equivalent to an image taken with a fisheye lens

Sphere Map

Capturing a Sphere Map

Normal Mapping Store normals in texture Very useful for making low-resolution geometry look like it s much more detailed

Computer Graphics (CS 473) Lecture 9: Shadows and Fog Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

Introduction to Shadows Shadows give information on relative positions of objects Use ambient + diffuse + specular components Use just ambient component

Introduction to Shadows Two popular shadow rendering methods:. Shadows as texture (projection) 2. Shadow buffer Third method used in ray-tracing (covered in grad class)

Projective Shadows Oldest method: Used in early flight simulators Projection of polygon is polygon called shadow polygon Actual polygon Shadow polygon

Projective Shadows Works for flat surfaces illuminated by point light For each face, project vertices V to find V of shadow polygon Object shadow = union of projections of faces

Projective Shadow Algorithm Project light-object edges onto plane Algorithm: First, draw ground plane/scene using specular+diffuse+ambient components Then, draw shadow projections (face by face) using only ambient component

Projective Shadows for Polygon. If light is at (x l, y l, z l ) 2. Vertex at (x, y, z) 3. Would like to calculate shadow polygon vertex V projected onto ground at (x p,, z p ) (x,y,z) (x p,,z p ) Ground plane: y =

Projective Shadows for Polygon If we move original polygon so that light source is at origin Matrix M projects a vertex V to give its projection V in shadow polygon y l m

Building Shadow Projection Matrix. Translate source to origin with T(-x l, -y l, -z l ) 2. Perspective projection 3. Translate back by T(x l, y l, z l ) l l l l l l l z y x z y x M y Final matrix that projects Vertex V onto V in shadow polygon

Code snippets? Set up projection matrix in OpenGL application float light[3]; // location of light mat4 m; // shadow projection matrix initially identity M[3][] = -./light[]; y l M

Projective Shadow Code Set up object (e.g a square) to be drawn point4 square[4] = {vec4(-.5,.5, -.5,.} {vec4(-.5,.5, -.5,.} {vec4(-.5,.5, -.5,.} {vec4(-.5,.5, -.5,.} Copy square to VBO Pass modelview, projection matrices to vertex shader

What next? Next, we load model_view as usual then draw original polygon Then load shadow projection matrix, change color to black, re-render polygon. Load modelview draw polygon as usual 2. Modify modelview with Shadow projection matrix Re-render as black (or ambient)

Shadow projection Display( ) Function void display( ) { mat4 mm; // clear the window glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); // render red square (original square) using modelview // matrix as usual (previously set up) gluniform4fv(color_loc,, red); gldrawarrays(gl_triangle_strip,, 4);

Shadow projection Display( ) Function // modify modelview matrix to project square // and send modified model_view matrix to shader mm = model_view * Translate(light[], light[], light[2] *m * Translate(-light[], -light[], -light[2]); gluniformmatrix4fv(matrix_loc,, GL_TRUE, mm); //and re-render square as // black square (or using only ambient component) gluniform4fv(color_loc,, black); gldrawarrays(gl_triangle_strip,, 4); glutswapbuffers( ); } l l l l l l l z y x z y x M y

Shadow Buffer Approach Uses second depth buffer called shadow buffer Pros: not limited to plane surfaces Cons: needs lots of memory Depth buffer?

OpenGL Depth Buffer (Z Buffer) Depth: While drawing objects, depth buffer stores distance of each polygon from viewer Why? If multiple polygons overlap a pixel, only closest one polygon is drawn Depth......3.3. Z =.5 Z =.3.5.3.3..5.5.. eye

Setting up OpenGL Depth Buffer Note: You did this in order to draw solid cube, meshes. glutinitdisplaymode(glut_depth GLUT_RGB) instructs opengl to create depth buffer 2. glenable(gl_depth_test) enables depth testing 3. glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT) Initializes depth buffer every time we draw a new picture

Shadow Buffer Theory Along each path from light Only closest object is lit Other objects on that path in shadow Shadow buffer stores closest object on each path Lit In shadow

Shadow Buffer Approach Rendering in two stages: Loading shadow buffer Render the scene

Loading Shadow Buffer Initialize each element to. Position a camera at light source Rasterize each face in scene updating closest object Shadow buffer tracks smallest depth on each path

Shadow Buffer (Rendering Scene) Render scene using camera as usual While rendering a pixel find: pseudo-depth D from light source to P Index location [i][j] in shadow buffer, to be tested Value d[i][j] stored in shadow buffer If d[i][j] < D (other object on this path closer to light) point P is in shadow lighting = ambient Otherwise, not in shadow Lighting = amb + diffuse + specular D[i][j] D In shadow

Loading Shadow Buffer Shadow buffer calculation is independent of eye position In animations, shadow buffer loaded once If eye moves, no need for recalculation If objects move, recalculation required

Soft Shadows Point light sources => simple hard shadows, unrealistic Extended light sources => more realistic Shadow has two parts: Umbra (Inner part) => no light Penumbra (outer part) => some light

Fog example Fog is atmospheric effect Better realism, helps determine distances

Fog Fog was part of OpenGL fixed function pipeline Programming fixed function fog Parameters: Choose fog color, fog model Enable: Turn it on Fixed function fog deprecated!! Shaders can implement even better fog Shaders implementation: fog applied in fragment shader just before display

Rendering Fog Mix some color of fog: c f + color of surface: cs c p fc f ( f ) c f [,] s If f =.25, output color = 25% fog + 75% surface color f computed as function of distance z 3 ways: linear, exponential, exponential-squared Linear: f z z end end z z p start z P z start z End

Fog Shader Fragment Shader Example float dist = abs(position.z); Float fogfactor = (Fog.maxDist dist)/ f Fog.maxDist Fog.minDist); fogfactor = clamp(fogfactor,.,.); z z end end z z p start vec3 shadecolor = ambient + diffuse + specular vec3 color = mix(fog.color, shadecolor,fogfactor); FragColor = vec4(color,.); c p fc f ( f ) cs

Fog Exponential Squared exponential f d f z p Exponential derived from Beer s law e e ( d f z p ) Beer s law: intensity of outgoing light diminishes exponentially with distance f 2

Fog Optimizations f values for different depths ( z P )can be pre-computed and stored in a table on GPU Distances used in f calculations are planar Can also use Euclidean distance from viewer or radial distance to create radial fog

References Interactive Computer Graphics (6 th edition), Angel and Shreiner Computer Graphics using OpenGL (3 rd edition), Hill and Kelley Real Time Rendering by Akenine-Moller, Haines and Hoffman