CSG and Raytracing CPSC 407.

Slides:



Advertisements
Similar presentations
Constructive Solid Geometry
Advertisements

GR2 Advanced Computer Graphics AGR
Constructive Solid Geometry Mel Slater
Christian Lauterbach COMP 770, 2/16/2009. Overview  Acceleration structures  Spatial hierarchies  Object hierarchies  Interactive Ray Tracing techniques.
Advanced Light and Shadow Culling Methods Eric Lengyel.
Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CSE 381 – Advanced Game Programming Scene Management
Week 14 - Monday.  What did we talk about last time?  Bounding volume/bounding volume intersections.
9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk.
CS447/ Realistic Rendering -- Solids Modeling -- Introduction to 2D and 3D Computer Graphics.
Christian Lauterbach COMP 770, 2/11/2009
Chapter 11: Advanced Rendering Part 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
1 Dr. Scott Schaefer Hidden Surfaces. 2/62 Hidden Surfaces.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Ray Tracing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of.
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
Bounding Volume Hierarchy “Efficient Distance Computation Between Non-Convex Objects” Sean Quinlan Stanford, 1994 Presented by Mathieu Brédif.
2003 by Jim X. Chen: Introduction to Modeling Jim X. Chen George Mason University.
Implicit Surfaces Tom Ouyang January 29, Outline Properties of Implicit Surfaces Polygonization Ways of generating implicit surfaces Applications.
1 CSCE 441: Computer Graphics Hidden Surface Removal (Cont.) Jinxiang Chai.
Ray Tracing 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
Ray Space Factorization for From-Region Visibility Authors: Tommer Leyvand, Olga Sorkine, Daniel Cohen-Or Presenter: Alexandre Mattos.
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.
Hidden Surface Removal
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.
Week 13 - Wednesday CS361.
BSP Trees, Quadtrees & Octrees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January 28, 2004.
Computer Graphics Mirror and Shadows
Computer Graphics 2 Lecture x: Acceleration Techniques for Ray-Tracing Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Spatial Data Structures Jason Goffeney, 4/26/2006 from Real Time Rendering.
COMP 175: Computer Graphics March 24, 2015
10/09/2001CS 638, Fall 2001 Today Spatial Data Structures –Why care? –Octrees/Quadtrees –Kd-trees.
CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann.
Graphics Graphics Korea University cgvr.korea.ac.kr Solid Modeling 고려대학교 컴퓨터 그래픽스 연구실.
2D/3D Shape Manipulation, 3D Printing Shape Representations Slides from Olga Sorkine February 20, 2013 CS 6501.
Ray Tracing Chapter CAP4730: Computational Structures in Computer Graphics.
Implementing Scene Graphs, CSG Trees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, January 26, 2004.
University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell Ray Tracing.
3D Object Representations
1 Visiblity: Culling and Clipping Computer Graphics COMP 770 (236) Spring 2009 January 21 & 26: 2009.
Ray Tracing. 2 Introduction OpenGL is based on a pipeline model in which primitives are rendered one at time ­No shadows (except by tricks or multiple.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
CS 480/680 Computer Graphics Compositing and Blending Dr. Frederick C Harris, Jr.
Constructive Solid Geometry Ray Tracing CSG Models
Geometrically Bounded Wireframe AIC (Part 510) Grouping of curves relevant for 3-dimensional wireframe modeling without topological constructs Elementary.
In the name of God Computer Graphics. Introduction Modeling techniques modeling techniques managements Some renderings.
Volume and Solid Modeling
Maths & Technologies for Games Spatial Partitioning 2
3D Object Representations 2011, Fall. Introduction What is CG?  Imaging : Representing 2D images  Modeling : Representing 3D objects  Rendering : Constructing.
CSCE 441: Computer Graphics Ray Tracing
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
IT / API 1 CERN 1-Feb-16 GBLIB: classes to deal with geometrical data Evgueni Tcherniaev IT / API CLHEP workshop, January.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
Ray Tracing Optimizations
RENDERING : Global Illumination
Global Illumination (3) Path Tracing. Overview Light Transport Notation Path Tracing Photon Mapping.
David Luebke3/12/2016 Advanced Computer Graphics Lecture 3: More Ray Tracing David Luebke
Solid Modeling Dr. Scott Schaefer.
3D Object Representations 2009, Fall. Introduction What is CG?  Imaging : Representing 2D images  Modeling : Representing 3D objects  Rendering : Constructing.
CS552: Computer Graphics Lecture 28: Solid Modeling.
Constructive Solid Geometry CSG (Geometri Padat Konstruktif)
Distance Computation “Efficient Distance Computation Between Non-Convex Objects” Sean Quinlan Stanford, 1994 Presentation by Julie Letchner.
3D Object Representations
Mike Merchant Nicholas Hilbert
CSCE 441: Computer Graphics Hidden Surface Removal
Efficient Distance Computation between Non-Convex Objects
Presentation transcript:

CSG and Raytracing CPSC 407

What is CSG? Computational Solid Geometry Volume Representation Very powerful modeling paradigm Difficult to render CSG models

Volumes, Not Surfaces CSG modeling tools allow a user to apply Boolean operations to volumes Union, Intersection, Difference Only works with volumes Closed surfaces can be interpreted as volumes… In 3D, a volume is bounded by a surface In 2D, the boundary is a curve

Volumes are Half-Spaces We can think of volumes as half-spaces Each primitive divides space into a set of points inside the volume, and a set of points outside The sets of points are infinitely dense Now our Boolean operations are set operations on these sets of points

Simple 3D Half-Spaces Sphere Cylinder Cone Torus Box Plane Plane is tricky - it splits space into two infinite half-spaces Note that the cylinder and cone are capped. This is not necessary In fact, you can use an infinite cylinder and two planes to make a capped cylinder Infinite cylinders are easier to implement You can also get a box from 6 planes…

Boolean CSG Operations Union Addition, A Ú B Intersection A Ù B Difference Subtraction, A – B, A Ù not B Difference is not commutative

A more complicated example Difference of: Intersection of Sphere and Cube Union of 3 Cylinders - =

Raytracing CSG Objects Need a data structure to describe primitives and operations Binary CSG Binary tree Leaf nodes are primitives Interior nodes are Boolean operations

Binary Tree Example

Ray Intervals Define a ray as a set of points (r+td) r is eye point d is the direction of the ray t is the scalar distance along the ray For now, assume that a primitive is convex A ray (r+td) intersects a convex primitive at most 2 times Let’s say the ray enters the primitive at distance t1 and leaves at distance t2 Now we can define an interval [t1, t2] along the ray that is inside the primitive Note: for planes, the interval is either [a,inf] or [inf,b]

CSG Operations on Intervals Assume we have intervals A = [a1,b1] and B = [a2,b2], and we want to combine them with a CSG operation There are 5 cases to check for each operation: No Overlap: Partial Overlap: Full Overlap:

CSG Union on 2 Intervals Remember, Union is A or B In the no-overlap case, we return the two intervals The rest of the cases produce one interval, [min(a1,a2), max(b1,b2)]

CSG Intersection on 2 Intervals Remember, Intersection is A and B In the no-overlap case, we return no intervals The rest of the cases produce one interval, [max(a1,a2), min(b1,b2)]

CSG Difference on 2 Intervals Remember, Difference is A and not B The order is important! Here we have 5 cases: Return { [a1,b1] } Return { [0,0] } Return { [a1,a2], [b2,b1] } Return { [a1,a2] } Return { [b2,b1] }

Lists of intervals Complex volumes are not convex A ray may intersect the volume more than once Instead of a single interval, we get a set of them We want to combine interval sets S1 and S2 with a Boolean CSG operation Brute force algorithm: For each interval Ai in S1, apply the appropriate 2-interval operation with each interval Bj from S2 Return the list of new intervals This algorithm is O(N2). O(NlogN) algorithms do exist I’m not certain the list of new intervals will be unique. You may have to check if any overlap, and combine them.

Binary CSG Tree Traversal Depth-first traversal of the tree At each primitive node, pass back the list of intervals along the ray that intersect the primitive At each Boolean node, combine the two child lists and pass back the new set of intervals The intersection point is at (r+td), where t is the lower value of the first interval in the list returned from the root node of the tree

Materials and Normals for CSG Need to determine normal at intersection point Need tertiary information with intervals Either object pointers or normals themselves Note that normals are reversed for subtracted objects Correct material properties at intersection point are debatable… Some people take material properties at intersection point Others prefer to define material properties for the entire CSG object as a whole

Additional CSG Bits It is possible to partially implement CSG without doing a full CSG tree This is how I did difference objects in my raytracer Blob’s notes have a different CSG algorithm His algorithm looks like it might be more efficient, but it requires a point inside/outside test Very difficult for arbitrary triangle meshes

General Raytracing Bits

Common bugs Wrong direction for eye rays Make sure they are going into the scene Taking the wrong intersection point Ray intersects with a sphere twice, make sure you use the closer intersection! Incorrect direction for reflected rays Sending the reflected ray into the object Total Internal Reflection in refraction Get a sqrt(< 0) in the formula for refracted ray direction In this case, ray reflects instead of refracting

Numerical Error Self-Intersection due to Numerical Error Produces ‘surface dirt’ – black speckles on otherwise smooth objects Throw away intersections close to intersection point Bad if you have very thin objects Throw away any other intersections with current object Assumes objects are convex!!! (not so for CSG, torus) Avoid by moving a small distance along the normal at the intersection point before casting secondary rays Bad for thin objects again, but probably the simplest method

Transforming Normals I’m assuming you are implementing object transformations as described in Blob’s Notes He explains how to transform the intersection point from object space to world space He doesn’t explain how to transform normals Tutorial on my website: http://www.unknownroad.com/rtfm/graphics/rt_normals.html

Shadow Cache Assumption: the last object that was hit by a shadow feeler is likely to be the one hit the next time So test it first For shadow feelers, it doesn’t matter if it’s the closest object (not so for reflection!) Shadow feelers are usually a large part of the cost of rendering a scene, so this is a big speedup that is relatively simple to implement

WWW Material http://fuzzyphoton.tripod.com/index.htm http://www.scs.leeds.ac.uk/cuddles/hyperbks/Raytracer/contents.htm http://www.scs.leeds.ac.uk/cuddles/hyperbks/Rendering/introduction.html http://www.cs.wisc.edu/~schenney/courses/cs559-s2001/lectures/lecture-26-online.ppt