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

Similar documents
Recall: Indexing into Cube Map

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

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

Lab 9 - Metal and Glass

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

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

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

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

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

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

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

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

CS452/552; EE465/505. Texture Mapping in WebGL

CS 432 Interactive Computer Graphics

Illumination & Shading I

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

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

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

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

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Objectives. Open GL Shading Language (GLSL)

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

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

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

Reflection & refraction

GLSL II. Objectives. Coupling GLSL to Applications Example applications

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Real-time Graphics 6. Reflections, Refractions

CPSC 436D Video Game Programming

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

CS452/552; EE465/505. Lighting & Shading

Supplement to Lecture 16

Objectives. Coupling GLSL to Applications Example applications

Yazhuo Liu Homework 3

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Overview. By end of the week:

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

Computer Graphics (CS 4731) & 2D Graphics Systems

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

Transforms 3: Projection Christian Miller CS Fall 2011

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

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

The Projection Matrix

Introduction to Computer Graphics with WebGL

Texture Mapping. Mike Bailey.

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

OPENGL RENDERING PIPELINE

Computer Graphics Lecture 11

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

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

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Ray Tracing: Special Topics CSCI 4239/5239 Advanced Computer Graphics Spring 2018

11.2 Refraction. December 10, Wednesday, 11 December, 13

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Lecture 14: Refraction

CS179: GPU Programming

Computer Graphics Coursework 1

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

Ø Sampling Theory" Ø Fourier Analysis Ø Anti-aliasing Ø Supersampling Strategies" Ø The Hall illumination model. Ø Original ray tracing paper

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University

CS452/552; EE465/505. Intro to Lighting

INF3320 Computer Graphics and Discrete Geometry

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Quick Shader 0.1 Beta

Sign up for crits! Announcments

Waves, Displacement, Reflections. Arun Rao CS 594

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

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

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

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

COMP371 COMPUTER GRAPHICS

Shaders. Slide credit to Prof. Zwicker

INFOGR Computer Graphics

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

lecture 18 - ray tracing - environment mapping - refraction

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

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

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

INFOGR Computer Graphics

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Shading 1: basics Christian Miller CS Fall 2011

All forms of EM waves travel at the speed of light in a vacuum = 3.00 x 10 8 m/s This speed is constant in air as well

1 of 5 9/10/ :11 PM

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

Transcription:

Computer Graphics (CS 543) Lecture 8c: Environment Mapping (Reflections and Refractions) Prof Emmanuel Agu (Adapted from slides by Ed Angel) Computer Science Dept. Worcester Polytechnic Institute (WPI)

Environment Mapping Environmental mapping is way to create the appearance of highly reflective and refractive surfaces without ray tracing 2

Types of Environment Maps Assumes environment infinitely far away Options: Store object s environment as a) Sphere around object (sphere map) b) Cube around object (cube map) V N R OpenGL supports cube maps and sphere maps

Cube mapping eye n y z x r Need to compute reflection vector, r Use r by for environment map lookup

Cube Map: How to Store Stores environment around objects as 6 sides of a cube (1 texture) Load 6 textures separately into 1 OpenGL cubemap

Cube Maps Loaded cube map texture can be accessed in GLSL through cubemap sampler vec4 texcolor = texturecube(mycube, texcoord); Texture coordinates must be 3D (x, y, z)

Creating Cube Map Use 6 cameras directions from scene center each with a 90 degree angle of view 7

Indexing into Cube Map Compute R = 2(N V)N-V Object at origin Perform lookup: vec4 texcolor = texturecube(mycube, R); Largest magnitude component of R (x,y,z) used to determine face of cube Other 2 components give texture coordinates More on this later. V R 8

Declaring Cube Maps in OpenGL gltexturemap2d(gl_texture_cube_map_positive_x, level, rows, columns, border, GL_RGBA, GL_UNSIGNED_BYTE, image1) Repeat similar for other 5 images (sides) Make 1 cubemap texture object from 6 images Parameters apply to all six images. E.g gltexparameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAP_WRAP_S, GL_REPEAT) Note: texture coordinates are in 3D space (s, t, r)

Cube Map Example (init) // colors for sides of cube GLubyte red[3] = {255, 0, 0}; GLubyte green[3] = {0, 255, 0}; GLubyte blue[3] = {0, 0, 255}; GLubyte cyan[3] = {0, 255, 255}; GLubyte magenta[3] = {255, 0, 255}; GLubyte yellow[3] = {255, 255, 0}; This example generates simple Colors as a texture You can also just load 6 pictures of environment glenable(gl_texture_cube_map); // Create texture object glgentextures(1, tex); glactivetexture(gl_texture1); glbindtexture(gl_texture_cube_map, tex[0]);

Cube Map (init II) Load 6 different pictures into 1 cube map of environment glteximage2d(gl_texture_cube_map_positive_x, 0,3,1,1,0,GL_RGB,GL_UNSIGNED_BYTE, red); glteximage2d(gl_texture_cube_map_negative_x, 0,3,1,1,0,GL_RGB,GL_UNSIGNED_BYTE, green); glteximage2d(gl_texture_cube_map_positive_y, 0,3,1,1,0,GL_RGB,GL_UNSIGNED_BYTE, blue); glteximage2d(gl_texture_cube_map_negative_y, 0,3,1,1,0,GL_RGB,GL_UNSIGNED_BYTE, cyan); glteximage2d(gl_texture_cube_map_positive_z, 0,3,1,1,0,GL_RGB,GL_UNSIGNED_BYTE, magenta); glteximage2d(gl_texture_cube_map_negative_z, 0,3,1,1,0,GL_RGB,GL_UNSIGNED_BYTE, yellow); gltexparameteri(gl_texture_cube_map, GL_TEXTURE_MAG_FILTER,GL_NEAREST);

Cube Map (init III) GLuint texmaplocation; GLuint tex[1]; texmaplocation = glgetuniformlocation(program, "texmap"); gluniform1i(texmaplocation, tex[0]); Connect texture map (tex[0]) to variable texmap in fragment shader (texture mapping done in frag shader)

Adding Normals void quad(int a, int b, int c, int d) { static int i =0; normal = normalize(cross(vertices[b] - vertices[a], vertices[c] - vertices[b])); normals[i] = normal; points[i] = vertices[a]; i++; Calculate and set quad normals // rest of data

Vertex Shader out vec3 R; in vec4 vposition; in vec4 Normal; uniform mat4 ModelView; uniform mat4 Projection; void main() { gl_position = Projection*ModelView*vPosition; vec4 eyepos = vposition; // calculate view vector V vec4 NN = ModelView*Normal; // transform normal vec3 N =normalize(nn.xyz); // normalize normal R = reflect(eyepos.xyz, N); // calculate reflection vector R } 14

Fragment Shader in vec3 R; uniform samplercube texmap; void main() { vec4 texcolor = texturecube(texmap, R); // look up texture map using R } gl_fragcolor = texcolor;

Refraction using Cube Map Can also use cube map for refraction (transparent) Reflection Reflection Refraction Refraction

Reflection and Refraction At each vertex I I amb I diff I spec I refl I tran r I R m I dir s P h v I T t Refracted component I T is along transmitted direction t

Finding Transmitted (Refracted) Direction Transmitted direction obeys Snell s law Snell s law: relationship holds in diagram below faster 1 m sin( c 2 2 ) sin( 1) c 1 slower P h 2 t c 1, c 2 are speeds of light in medium 1 and 2

Finding Transmitted Direction If ray goes from faster to slower medium (e.g. air to glass), ray is bent towards normal If ray goes from slower to faster medium (e.g. glass to air), ray is bent away from normal c1/c2 is important. Usually measured for medium-to-vacuum. E.g water to vacuum Some measured relative c1/c2 are: Air: 99.97% Glass: 52.2% to 59% Water: 75.19% Sapphire: 56.50% Diamond: 41.33%

Transmission Angle Vector for transmission angle can be found as t c dir m dir 2 c2 ( ) cos( 2) m c1 c1 dir m where Medium #1 1 c 2 2 cos( c1 2 ) 1 1 ( m dir) c 1 Medium #2 P h 2 t c2 Or just use GLSL built-in function refract to get T

Refraction Vertex Shader out vec3 T; in vec4 vposition; in vec4 Normal; uniform mat4 ModelView; uniform mat4 Projection; void main() { gl_position = Projection*ModelView*vPosition; vec4 eyepos = vposition; // calculate view vector V vec4 NN = ModelView*Normal; // transform normal vec3 N =normalize(nn.xyz); // normalize normal T = refract(eyepos.xyz, N, iorefr); // calculate refracted vector T } Was previously R = reflect(eyepos.xyz, N);

Refraction Fragment Shader in vec3 T; uniform samplercube RefMap; void main() { vec4 refractcolor = texturecube(refmap, T); // look up texture map using T refractcolor = mix(refractcolor, WHITE, 0.3); // mix pure color with 0.3 white } gl_fragcolor = refractcolor;

Caustics Caustics occur when light is focussed on diffuse surface Courtesy Chris Wyman, Univ Iowa

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 24

Cube Map Layout

Example R = (-4, 3, -1) Same as R = (-1, 0.75, -0.25) Use face x = -1 and y = 0.75, z = -0.25 Not quite right since cube defined by x, y, z = ± 1 rather than [0, 1] range needed for texture coordinates Remap by from [-1,1] to [0,1] range s = ½ + ½ y, t = ½ + ½ z Hence, s =0.875, t = 0.375

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