More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.

Slides:



Advertisements
Similar presentations
Lecture 8 Transparency, Mirroring
Advertisements

Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
3D Graphics Rendering and Terrain Modeling
COMPUTER GRAPHICS CS 482 – FALL 2014 OCTOBER 6, 2014 TEXTURE MAPPING TEXTURES BUMP MAPPING ENVIRONMENT MAPPING PROCEDURAL TEXTURING.
Reflections from Bumpy Surfaces GPU Graphics. What are we trying to achieve?  Most surfaces are not flat like glass  Some of these surfaces still give.
Environmental Maps Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
Environmental Mapping CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
CS559: Computer Graphics Lecture 27: Texture Mapping Li Zhang Spring 2008 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Advanced Texturing Methods Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 8, 2003.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Polygon Lists & 3-D File Formats Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 18, 2002.
Computer Graphics Texture Mapping Eriq Muhammad Adams
Reflections Specular reflection is the perfect reflection of light from a surface. The law a reflection states that the direction of the incoming ray and.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
Advanced Computer Graphics March 06, Grading Programming assignments Paper study and reports (flipped classroom) Final project No written exams.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann.
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
Texture Mapping Applications 2. Parallax Mapping with Slope  parallax mapping assumes that the surface is a single plane  a better approximation  surface.
Implementing Scene Graphs, CSG Trees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, January 26, 2004.
Bézier Algorithms & Properties Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, March 3, 2004.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Advanced HSR Methods Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, January 30, 2004.
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
October 9, 2002Serguei A. Mokhov, 1 COMP471 – Computer Graphics OpenGL: Texture Mapping.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Bézier Curves & Surfaces Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, March 1, 2004.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Improving the appearance of 3D OpenGL scenes
Module 06 –environment mapping Module 06 – environment mapping Module 06 Advanced mapping techniques: Environment mapping.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
CS3241 C OMPUTER G RAPHICS Tutorial 8. Q UESTION #1 Given an object represented in polygons, how to find its bounding sphere?
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
09/23/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Reflections Shadows Part 1 Stage 1 is in.
Texture Coordinates CS418 Computer Graphics John C. Hart.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Week 7 - Monday CS361.
Reflections from Bumpy Surfaces
Class 26 more textures environmental textures Color ramps
Projection in 3-D Glenn G. Chappell
Class 27 more textures environmental textures Color ramps
Texture Mapping Jung Lee.
Presentation transcript:

More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003

10 Dec 2003CS 3812 Review: More on Procedural Texture [1/2] One way to convert a noise function into an image: Choose colors for specified values in [–1,1]. Then determine the color associated with a value by lirping between the two nearest specified values. Create the image by mapping noise values to colors. –1.01.0– –1.01.0–0.30.4–0.1

10 Dec 2003CS 3813 Review: More on Procedural Texture [2/2] Code for color generation will often look something like this: // mapcolor - map value in [-1,1] to an RGB color. void mapcolor(double value, GLubyte color[3]) { if (value < -0.3) { t = (value – (-1.)) / ((-0.3) – (-1.)); color[0] = (1.-t)*1.0*255 + t*0.8*255; // lirp between white (1.0, 1.0, 1.0) color[1] = (1.-t)*1.0*255 + t*0.6*255; // and brown (0.8, 0.6, 0.4) color[2] = (1.-t)*1.0*255 + t*0.4*255; } else if (value < 0.4) { t = (value – (-0.3)) / ((0.4) – (-0.3)); color[0] = (1.-t)*0.8*255 + t*0.9*255; // lirp between brown (0.8, 0.6, 0.4) color[1] = (1.-t)*0.6*255 + t*0.1*255; // and magenta (0.9, 0.1, 0.9) color[2] = (1.-t)*0.4*255 + t*0.9*255; } else …

10 Dec 2003CS 3814 Review: Environment Mapping [1/4] In environment mapping, we simulate mirror-like reflection using texturing. Generate texture coordinates based on the direction that light, originating from the viewer, would reflect off the surface. Need: Viewing location (always (0,0,0) in OpenGL). Vertex coordinates (transformed by model/view). Surface normal (transformed by model/view).

10 Dec 2003CS 3815 Review: Environment Mapping [2/4] A simple environment-mapping technique is to use a sphere map. Take the reflected light direction, add 1 to z, normalize. Use the resulting x, y as texture coordinates. The texture is a fish-eye-lens picture of the environment. E.g., see plate 21 in the red book.

10 Dec 2003CS 3816 Review: Environment Mapping [3/4] Chrome mapping is a type of environment mapping in which we do not attempt to produce a realistic picture of the environment. Just make mirror-like reflections of something. Then objects look metallic, regardless of the incorrect reflections. Note: Some people would not call chrome mapping a type of environment mapping. I would. In particular, it is legal on assignment #11.

10 Dec 2003CS 3817 Review: Environment Mapping [4/4] OpenGL includes automatic texture-coordinate generation. One of the options does a sphere map. In initialization (or whereever): glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); To enable: glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); Disabling is as usual. Normals must be specified. glTexCoord * is not necessary. In particular, all the glutSolid … functions work!

10 Dec 2003CS 3818 More on Environment Mapping: Introduction We have seen how to create mirror-like reflections cheaply using a texture. Disadvantages No object-object reflections. The reflected scene is considered to lie at infinity. Often get errors at the edge of the silhouette. With sphere mapping, anyway. Creating the texture can be tricky. We look at this now.

10 Dec 2003CS 3819 More on Environment Mapping: Creating the Texture [1/4] The hard part of environment mapping is creating the texture itself. When to Create A sphere-map texture depends on: The environment. The viewing position. Thus, the texture needs to be recomputed whenever these change. It does not need to be computed when an environment-mapped object moves. Another way to think about it: Environment mapping is good for a stationary viewer viewing moving objects in a static environment. Next: How to Create

10 Dec 2003CS More on Environment Mapping: Creating the Texture [2/4] In environment mapping, given a reflected-ray direction in eye coordinates, texture coordinates are computed. To make the texture do this backwards: Look at each texel in turn. For each, determine what reflected-ray direction it corresponds to. Use the color of the environment, seen in that direction, for the color of the texel. Procedure for reflected-ray determination: Given texture coordinates a, b. Scale a, b so they are in [–1,1]. Find c  0 so that (a, b, c) is a unit vector. Reflected-ray direction is (2ca, 2cb, 2c 2 –1).

10 Dec 2003CS More on Environment Mapping: Creating the Texture [3/4] We want to write some code to generate the sphere-map texture. Suppose that the image array is declared as usual: const int img_width = … ; const int img_height = … ; GLubyte the_image[img_height][img_width][3]; Now suppose we have a function void envgetcolor(double x, double y, double z, GLubyte color[3]) Given a unit vector (x, y, z). Returns a color in the given array (RGB are ). Color is the color of the environment, see when looking in direction (x, y, z).

10 Dec 2003CS More on Environment Mapping: Creating the Texture [4/4] Then here is code to make the sphere-map texture: void envmakeimage() { for (int i=0; i<img_width; ++i) for (int j=0; j<img_height; ++j) { double a = 2.*i/img_width-1.; double b = 2.*j/img_height-1.; double k = 1.-a*a-b*b; double c = ((k <= 0.) ? 0. : sqrt(k)); double x = 2.*c*a; double y = 2.*c*b; double z = 2.*c*c-1.; envgetcolor(x, y, z, the_image[j][i]); }

10 Dec 2003CS More on Environment Mapping: The Environment Looks Like … So, how do we determine the color of the environment, seen in a particular direction? Answer 1: Render the environment in a buffer, and read this to determine colors. Tricky … Answer 2: Ray tracing. Yes, this is slow, but it only needs to be done when the texture is computed. Answer 3: Do it backwards. Decide: The color in this direction is … Then draw the environment as a large sphere, colored according to the above decisions.

10 Dec 2003CS More on Environment Mapping: EXAMPLE We put together an example environment- mapped object (which actually reflected its environment) using the following pieces from envmapfuncs.cpp (on the web page): Function envgetcolor was written to make an interesting background. Function envmakeimage created a sphere-map texture using envgetcolor. Function envdrawsphere drew the environment: a sphere colored using envgetcolor. The sphere was drawn with a large radius, to simulate an environment at infinity.

10 Dec 2003CS More on Environment Mapping: Some Hints When using environment mapping: Disable lighting for environment-mapped objects. Environment mapping is lighting … sort of. Other objects may still need lighting. Perfect reflectors are unrealistic; do not draw them. Set GL_MODULATE mode, and give your reflecting objects a color other than full white. Color (0.9, 0.9, 0.9) is not bad for silvery metal. Lower B (and maybe lower G) gives gold/coppery colors. Make your environment-mapped objects move. This adds realism. It is also cheap, since the texture does not need to be recomputed.

10 Dec 2003CS More on Environment Mapping: Cube Maps We have discussed how to store a picture of the environment as a sphere map. Another way to store it is as a cube map. Instead of a single, warped texture (as in a sphere map), we use 6 textures, forming the sides of a cube. The 6 textures form a picture of the environment, as seen from the center of the cube. Computations are simpler. Generating the images is much easier. Not supported by standard OpenGL.  Although it is available in extensions.