OpenGL and You I Cast, Therefore I Am. Ray Casting Idea is simple, implementation takes some work –Cast rays as if you were the camera –Determine intersection.

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.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Graphics Pipeline.
3D Graphics Rendering and Terrain Modeling
Projection Matrix Tricks Eric Lengyel Outline  Projection Matrix Internals  Infinite Projection Matrix  Depth Modification  Oblique Near Clipping.
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.
Ray Tracing Tutorial. Ray Casting One type of visibility algorithm.
Now Playing: Melody Day Caribou from Andorra Released August 21, 2007.
Parallelizing Raytracing Gillian Smith CMPE 220 February 19 th, 2008.
Now Playing: Gong Sigur Rós From Takk... Released September 13, 2005.
CV: 3D sensing and calibration
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
OpenGL (II). How to Draw a 3-D object on Screen?
Now Playing: Quicksand Under Carpet New Radiant Storm King from Leftover Blues: Released 2004.
1 Computer Graphics Week7 -2D Rotation. 3-Rotation A shape can be rotated about any of the three axes. A rotation about the z-axis will actually rotate.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
COMP 175: Computer Graphics March 10, 2015
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Sky Rendering The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: –Constant backdrop –Skybox.
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
Foundations of Computer Graphics (Fall 2012) CS 184, Lectures 13,14: Reviews Transforms, OpenGL
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Gene Au-yeung, Daniel Quach, Jeffrey Su, Albert Wang, Jessica Wang, David Woo.
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
Games Development 1 Camera Projection / Picking CO3301 Week 8.
David Luebke11/26/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Computer Graphics Lecture 08 Fasih ur Rehman. Last Class Ray Tracing.
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Introduction to Computer Graphics: Viewing Transformations Rama C
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Viewing and Projection
CS5500 Computer Graphics April 23, Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct.
Real-Time Dynamic Shadow Algorithms Evan Closson CSE 528.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
RENDERING : Global Illumination
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
- Introduction - Graphics Pipeline
CSCE 441 Computer Graphics 3-D Viewing
3D Graphics Rendering PPT By Ricardo Veguilla.
CS451Real-time Rendering Pipeline
Projection in 3-D Glenn G. Chappell
Chapter V Vertex Processing
Computer Graphics Computer Viewing
CS5500 Computer Graphics April 24, 2006.
Presentation transcript:

OpenGL and You I Cast, Therefore I Am

Ray Casting Idea is simple, implementation takes some work –Cast rays as if you were the camera –Determine intersection of closest shape –Calculate/apply shading –Repeat for all pixels

Nothing to it That really is all there is to it The rest is just math, which can get a little hairy Ray tracing introduces recursive ray casting, but that is for the next assignment

Matrix 2: No nmap this time Remember matrices? They’re back When dealing with matrices, MATLAB is your best friend Spend some time testing your matrix functions 1 or 2 hours in the beginning can save many many many hours later Many

getting the matrix glGetFloatv(GL_MODELVIEW_MATRIX,mat); Will retrieve the current modelview matrix and store it in ‘mat’ Remember, what happens in the modelview matrix, stays in the modelview matrix

Perspective Why not get the perspective matrix? –This creates the viewing frustum through which the world is seen –We can create this on our own –Avoids a matrix multiplication

Example glMatrixMode(perspective) gluPerspective(xxxx) x y z

Example Sets up a frustum that extends in the –z direction x y z eye

A different view Eye z=0 (pretend like it’s centered) z=x near clipping plane z = x’ far clipping plane x y

Modelview Changes in the modelview matrix affect objects in your scene graph zOMG!1! Even gluLookAt is in modelview! You can still think of gluLookAt as moving the camera if that helps you conceptually In terms of matrices, gluLookAt is transforming your geometry around a static camera

Let’s add a sphere glutSolidSphere will put a sphere at the origin with a given radius. We’ll assume 1 for now

Let’s add a sphere Based on the current viewing frustum, this sphere will not be visible, so you translate it into the viewing area

Let’s add a sphere The modelview matrix used to draw this sphere reflects this translation

Cool, now what So if that modelview matrix is used to move that sphere into its position, what would the inverse do? It would perform the opposite move (duh)

How does this apply to rays? When we prepare to shoot rays into the scene, we know a few things –The modelview matrix associated with each object –The eye point (0,0,0) –The perspective we are trying to achieve –The pre-transformed coordinates of our geometry

How to build a ray Since you know the perspective you want, cast the rays from the eye towards the near clipping plane Need to scale your pixels to fit the range of x, y values for your perspective For our version, x will range between -1 and 1, and y will range between -1 and 1 So if you have 512 pixels by 512 pixels, you need to scale pixel (0,0) to be (-1,1) and (512,512) to be (1,-1)

Ray part 2 Rays have two parts: origin and direction R0 + Rd*t Origin can be the eye Direction will be the pixel you want to determine minus the origin For this example, any intersection with t>=1 and t<= (time to travel to far clipping plane) will be a valid intersection

Example x y z eye This ray follows the z-axis. R0 is (0,0,0) and Rd is (0,0,-1)

Remember this? If you just try to shoot rays from this eye towards untransformed geometry, you will never hit your objects

Remember this? If you just try to shoot rays from this eye towards untransformed geometry, you will never hit your objects within the clipping plane Intersection occurs with t<1

Remember this? The solution is to apply the inverse transformation to the ray and then test for intersection. Brilliant!

Remember this? The solution is to apply the inverse transformation to the ray and then test for intersection. Brilliant! M^-1 * ray

Remember this? The solution is to apply the inverse transformation to the ray and then test for intersection. Brilliant! M^-1 * ray Intersection now occurs with t<=1

Step by step, day by day Calculate the matrix for shape M as M Calculate M^-1 Calculate R0, the starting point of the ray Calculate Rd, the direction of the ray Calculate R1, which is R0 + Rd Transform R0 by M^-1 Transform R1 by M^-1 Do perspective division!!! (divide x,y,z by w) Test for intersection with shape M

More steps by steps If there is an intersection, calculate t At each pixel, determine the closest intersection (i.e. lowest valid value of t) Now make the shading calculation based on the normal at that point

The abnormal normal Mr. T pities the fool that thinks normals transform the same way that points do

How normals work Normals do not transform in the same way that points do Calculate your normal Multiply it by M^t (transpose of the modelview) to get it back to the correct space Remember to throw out the translation values Calculate the lighting based on that

Final tips Again, MATLAB is your friend Use it to verify that your calculations are working Start with something small Do not try to raycast your entire image at first, as this will take a long time and will most likely be wrong Try to create a simple building with one floor tile at first and go from there There’s a lot to work on, so don’t get hung up on anything