Digital Image Synthesis Yung-Yu Chuang 10/04/2007

Slides:



Advertisements
Similar presentations
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Exploration of bump, parallax, relief and displacement mapping
Bump Mapping CSE 781 Roger Crawfis.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Representing Geometry in Computer Graphics Rick Skarbez, Instructor COMP 575 September 18, 2007.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
Implicit Surfaces Tom Ouyang January 29, Outline Properties of Implicit Surfaces Polygonization Ways of generating implicit surfaces Applications.
Ray Tracing Outline For each pixel { Shoot ray r from eye to center of pixel with trace( r ) } function trace( r ) For each object { Find object with closest.
1 Representing Curves and Surfaces. 2 Introduction We need smooth curves and surfaces in many applications: –model real world objects –computer-aided.
1Notes. 2 Time integration for particles  Back to the ODE problem, either  Accuracy, stability, and ease-of- implementation are main issues  Obviously.
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.
Modeling and representation 1 – comparative review and polygon mesh models 2.1 Introduction 2.2 Polygonal representation of three-dimensional objects 2.3.
Acceleration Digital Image Synthesis Yung-Yu Chuang 10/4/2005 with slides by Mario Costa Sousa and Pat Hanrahan.
CS-321 Dr. Mark L. Hornick 1 3-D Object Modeling.
Computer graphics & visualization Ray-Tracing – A Quick review.
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.
Computer graphics & visualization REYES Render Everything Your Eyes Ever Saw.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Geometry and Transformations Digital Image Synthesis Yung-Yu Chuang 9/28/2006 with slides by Pat Hanrahan.
1 Ray Casting. CLASS 1 Ray Casting 2 3 Overview of Today Ray Casting Basics Camera and Ray Generation Ray-Plane Intersection.
2D/3D Shape Manipulation, 3D Printing Shape Representations Slides from Olga Sorkine February 20, 2013 CS 6501.
Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,
Image Synthesis Rabie A. Ramadan, PhD 1. 2 About my self Rabie A. Ramadan My website and publications
Materials Digital Image Synthesis Yung-Yu Chuang 11/19/2008 with slides by Robin Chen.
Shapes Digital Image Synthesis Yung-Yu Chuang with slides by Pat Hanrahan.
Minimum Distance between curved surfaces Li Yajuan Oct.25,2006.
Shapes Digital Image Synthesis Yung-Yu Chuang 10/05/2006 with slides by Pat Hanrahan.
Detector Description – Part III Ivana Hrivnacova, IPN Orsay Tatiana Nikitina, CERN Aknowledgement: Slides by: J.Apostolakis, G.Cosmo, A. Lechner.
Greg Humphreys CS445: Intro Graphics University of Virginia, Fall 2003 Subdivision Surfaces Greg Humphreys University of Virginia CS 445, Fall 2003.
RENDERING : Global Illumination
11/16/04© University of Wisconsin, CS559 Fall 2004 Last Time Texture Anti-Aliasing Texture boundaries Modeling introduction.
Shapes Digital Image Synthesis Yung-Yu Chuang 10/1/2008 with slides by Pat Hanrahan.
Solid Modeling Dr. Scott Schaefer.
Ray Tracing I. Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections and
MATHEMATICS B.A./B.Sc. (GENERAL) FIRST YEAR EXAMINATIONS,2012.
CSE 167 [Win 17], Lecture 15: Ray Tracing Ravi Ramamoorthi
Digital Image Synthesis Yung-Yu Chuang 10/8/2009
Photorealistic Rendering vs. Interactive 3D Graphics
MIT EECS 6.837, Cutler and Durand
Ray Tracing Forward Ray Tracing
Visible-Surface Detection Methods
Lecture 33: Shape Modeling Li Zhang Spring 2008
3D Graphics Rendering PPT By Ricardo Veguilla.
3D Object Representations
Digital Image Synthesis Yung-Yu Chuang 11/16/2006
3D Object Representation
Ray Tracing Geometry CSE 681.
Ray Tracing Geometry CSE 681.
© University of Wisconsin, CS559 Fall 2004
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Chapter IX Bump Mapping
Digital Image Synthesis Yung-Yu Chuang 10/4/2005
Object Intersection CSE 681.
Lecture 13 Clipping & Scan Conversion
Digital Image Synthesis Yung-Yu Chuang 9/28/2006
Geometry and Transformations
Geometry and Transformations
CS5500 Computer Graphics May 29, 2006
Ray Tracer Spring 2004 Help Session.
Geometry and Transformations
CS2013 Lecture 7 John Hurley Cal State LA.
3D Object Representation
Overview of Modeling 김성남.
GPAT – Chapter 7 Physics.
Presentation transcript:

Digital Image Synthesis Yung-Yu Chuang 10/04/2007 Shapes Digital Image Synthesis Yung-Yu Chuang 10/04/2007 with slides by Pat Hanrahan

Announcements One break or two breaks. Please do read the textbook and trace code. LootAt issue. No class on 10/18 because of attending CGW 2007. Assignment #1 will be handed out today. Due three weeks later.

Shapes One advantages of ray tracing is it can support various kinds of shapes as long as we can find ray-shape intersection. Careful abstraction of geometric shapes is a key component for a ray tracer. Ideal candidate for object-oriented design. Scan conversion may not have such a neat interface. All shape classes implement the same interface and the other parts of the ray tracer just use this interface without knowing the details about this shape.

Shapes Primitive=Shape+Material Shape: raw geometry properties of the primitive, implements interface such as surface area and bounding box. Source code in core/shape.* and shapes/*

Shapes pbrt provides the following shape plug-ins: quadrics: sphere, cone, cylinder, disk, hyperboloid (雙曲面), paraboloid(拋物面) (surface described by quadratic polynomials in x, y, z) triangle mesh height field NURBS Loop subdivision surface Some possible extensions: other subdivision schemes, fractals, CSG, point-sampled geometry

Shapes All shapes are defined in object coordinate space class Shape : public ReferenceCounted { public: <Shape Interface> all are virtual functions const Transform ObjectToWorld, WorldToObject; const bool reverseOrientation, transformSwapsHandedness; }

Shape interface: bounding BBox ObjectBound() const=0;pure virtual function BBox WorldBound() { left to individual shape default implementation; can be overridden return ObjectToWorld(ObjectBound()); }

Shape interface: intersecting bool CanIntersect() returns whether this shape can do intersection test; if not, the shape must provide void Refine(vector<Reference<Shape>>&refined) examples include complex surfaces (which need to be tessellated first) or placeholders (which store geometry information in the disk) bool Intersect(const Ray &ray, float *tHit, DifferentialGeometry *dg) bool IntersectP(const Ray &ray) not pure virtual functions so that non-intersectable shapes don’t need to implement them; instead, a default implementation which prints error is provided. in world space

Differential geometry DifferentialGeometry: a self-contained representation for a particular point on a surface so that all the other operations in pbrt can be executed without referring to the original shape. It contains Position Parameterization (u,v) Parametric derivatives (dp/du, dp/dv) Surface normal (derived from (dp/du)x(dp/dv)) Derivatives of normals Pointer to shape

Shape interface float Area() useful when using as a area light void GetShadingGeometry( const Transform &obj2world, const DifferentialGeometry &dg, DifferentialGeometry *dgShading) No back culling for that it doesn’t save much for ray tracing and it is not physically correct for object instancing

Surfaces Implicit: F(x,y,z)=0 you can check Explicit: (x(u,v),y(u,v),z(u,v)) you can enumerate also called parametric Quadrics

Sphere A sphere of radius r at the origin Implicit: x2+y2+z2-r2=0 Parametric: f(θ,ψ) x=rsinθcosψ y=rsinθsinψ z=rcosθ mapping f(u,v) over [0,1]2 ψ=uψmax θ=θmin+v(θmax-θmin) useful for texture mapping θ

Sphere

Sphere (construction) class Sphere: public Shape { …… private: float radius; float phiMax; float zmin, zmax; float thetaMin, thetaMax; } Sphere(const Transform &o2w, bool ro, float rad, float zmin, float zmax, float phiMax); Bounding box for sphere, only z clipping thetas are derived from z

Intersection (algebraic solution) Perform in object space, WorldToObject(r, &ray) Assume that ray is normalized for a while Step 1

Algebraic solution If (B2-4AC<0) then the ray misses the sphere Step 2 If (B2-4AC<0) then the ray misses the sphere Step 3 Calculate t0 and test if t0<0 (actually mint, maxt) Step 4 Calculate t1 and test if t1<0 check the real source code in sphere.cpp

Quadric (in pbrt.h) inline bool Quadratic(float A, float B, float C, float *t0, float *t1) { // Find quadratic discriminant float discrim = B * B - 4.f * A * C; if (discrim < 0.) return false; float rootDiscrim = sqrtf(discrim); // Compute quadratic _t_ values float q; if (B < 0) q = -.5f * (B - rootDiscrim); else q = -.5f * (B + rootDiscrim); *t0 = q / A; *t1 = C / q; if (*t0 > *t1) swap(*t0, *t1); return true; }

Why? Cancellation error: devastating loss of precision when small numbers are computed from large numbers by addition or subtraction. double x1 = 10.000000000000004; double x2 = 10.000000000000000; double y1 = 10.00000000000004; double y2 = 10.00000000000000; double z = (y1 - y2) / (x1 - x2); // 11.5 Catastrophic cancellation. Devastating loss of precision when small numbers are computed from large numbers by addition or subtraction. For example if x and y agree in all but the last few digits, then if we compute z = x - y, then z may only have a few digits of accuracy. If we subsequently use z in a calculation, then the result may only have a few digits of accuracy. As a first example, consider the following contrived code fragment double x1 = 10.000000000000004; double x2 = 10.000000000000000; double y1 = 10.00000000000004; double y2 = 10.00000000000000; double z = (y1 - y2) / (x1 - x2); System.out.println(z); It is easy to compute the exact answer by hand as (4/10,000,000,000,000) / (4/100,000,000,000,000) = 10. However, Java prints out result 11.5. Even though all calculations are done using 15 digits of precision, the result suddenly has only 1 digit of accuracy.

Range checking if (t0 > ray.maxt || t1 < ray.mint) return false; float thit = t0; if (t0 < ray.mint) { thit = t1; if (thit > ray.maxt) return false; } ... phit = ray(thit); phi = atan2f(phit.y, phit.x); if (phi < 0.) phi += 2.f*M_PI; // Test sphere intersection against clipping parameters if (phit.z < zmin || phit.z > zmax || phi > phiMax) { ... // see if we should check another hit point

Geometric solution 1. Origin inside?

Geometric solution 2. find the closest point, t=-O‧D if t<0 and O outside return false D is normalized t t

Geometric solution 3. find the distance to the origin, d2=O2-t2 if s2=r2-d2<0 return false; t s d r r O

Geometric solution 4. calculate intersection distance, if (origin outside) then t-s else t+s t t s O s r d r d O

Sphere Have to test sphere intersection against clipping parameters Fill in information for DifferentialGeometry Position Parameterization (u,v) Parametric derivatives Surface normal Derivatives of normals Pointer to shape

Partial sphere u=ψ/ψmax v=(θ-θmin)/ (θmax-θmin) Partial derivatives (pp103 of textbook) Area (pp107)

Cylinder

Cylinder

Cylinder (intersection)

Disk

Disk

Disk (intersection) h h-Oz t Dz D

Other quadrics paraboloid hyperboloid cone

Triangle mesh The most commonly used shape. In pbrt, it can be supplied by users or tessellated from other shapes. Some ray tracers only support triangle meshes.

Triangle mesh class TriangleMesh : public Shape { … int ntris, nverts; int *vertexIndex; Point *p; Normal *n; per vertex Vector *s; tangent float *uvs; parameters } vi[3*i] vi[3*i+1] vi[3*i+2] p x,y,z … Note that p is stored in world space to save transformations. n and s are in object space.

Triangle mesh Pbrt calls Refine() when it encounters a shape that is not intersectable. (usually, refine is done in acceleration structure creation) Void TriangleMesh::Refine(vector<Reference<Shape>> &refined) { for (int i = 0; i < ntris; ++i) refined.push_back(new Triangle(ObjectToWorld, reverseOrientation, (TriangleMesh *)this, i)); } Triangle only stores a pointer to mesh and an index.

Ray triangle intersection Intersect ray with plane Check if point is inside triangle In order to implement this algorithm we had to address these six issues.

Ray plane intersection Algebraic Method Substituting for P, we get: Solution: In order to implement this algorithm we had to address these six issues.

Ray triangle intersection I Algebraic Method For each side of triangle: In order to implement this algorithm we had to address these six issues. end

Ray triangle intersection II Parametric Method In order to implement this algorithm we had to address these six issues.

Ray triangle intersection III In order to implement this algorithm we had to address these six issues.

Fast minimum storage intersection a point on the ray a point inside the triangle

Fast minimum storage intersection D O V2 D V2 1 V1 V1 V0 1 V0

Fast minimum storage intersection

Fast minimum storage intersection Cramer’s rule

Fast minimum storage intersection

Triangle P2 (u2, v2) P (u,v) P0 (u0, v0) P1 (u1, v1)

Shading geometry if (!mesh->n && !mesh->s) { *dgShading = dg; return; } // compute Barycentric coordinate

Shading geometry Normal ns; Vector ss, ts; if (mesh->n) ns = Normalize(obj2world( b[0] * mesh->n[v[0]] + b[1] * mesh->n[v[1]] + b[2] * mesh->n[v[2]])); else ns = dg.nn; if (mesh->s) ss = Normalize(obj2world( b[0] * mesh->s[v[0]] + b[1] * mesh->s[v[1]] + b[2] * mesh->s[v[2]])); else ss = Normalize(dg.dpdu);