CS 6958 LECTURE 4 INTRO TO GRAPHICS GEOMETRY

Similar documents
CS 6958 LECTURE 5 TM ANALYSIS SHADING

Geometry in Ray Tracing. CS6965 Fall 2011

CS 6958 LECTURE 9 TRAX MEMORY MODEL

Understanding simhwrt Output

Trax Memory Layout. CS 6965 Fall 2011

Geometric Queries for Ray Tracing

INFOGR Computer Graphics

8.1 Geometric Queries for Ray Tracing

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

Introduction to Computer Graphics. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Lecture 8 Ray tracing Part 1: Basic concept Yong-Jin Liu.

CSE 167: Introduction to Computer Graphics Lecture #2: Coordinate Transformations

Homework #1. Displays, Image Processing, Affine Transformations, Hierarchical Modeling

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

Intro to Ray-Tracing & Ray-Surface Acceleration

CS 563 Advanced Topics in Computer Graphics. by Emmanuel Agu

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

INFOGR Computer Graphics. Jacco Bikker - April-July Lecture 3: Ray Tracing (Introduction) Welcome!

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

BASIC ELEMENTS. Geometry is the study of the relationships among objects in an n-dimensional space

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

TRaX programming examples

3D Rendering and Ray Casting

Ray Tracing I: Basics

Last week. Machiraju/Zhang/Möller

Project 1 Simple Ray Tracer

CS 6958 LECTURE 11 CACHES

Ray Tracer Due date: April 27, 2011

Ray Tracing Part 1. CSC418/2504 Introduction to Computer Graphics. TA: Muhammed Anwar & Kevin Gibson

Ray Tracing I. History

CS111: PROGRAMMING LANGUAGE II

Matrices. Matrices. A matrix is a 2D array of numbers, arranged in rows that go across and columns that go down: 4 columns. Mike Bailey.

3D Rendering and Ray Casting

Principles of Computer Game Design and Implementation. Lecture 6

CS 130 Exam I. Fall 2015

CS 4620 Midterm, March 21, 2017

Ray tracing idea. Ray Tracing. Ray tracing algorithm. Plane projection in drawing. CS 465 Lecture 3

CS 543: Computer Graphics Lecture 10 (Part II): Raytracing (Part II) Emmanuel Agu

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

the gamedesigninitiative at cornell university Lecture 7 C++ Overview

Ray Tracing. Outline. Ray Tracing: History

Matrices. Mike Bailey. matrices.pptx. Matrices

Lecture 11: Ray tracing (cont.)

CS 130 Exam I. Fall 2015

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

Ray Tracing. CS 4620 Lecture 5

Photon Mapping. Due: 3/24/05, 11:59 PM

ANSI C. Data Analysis in Geophysics Demián D. Gómez November 2013

Effects needed for Realism. Ray Tracing. Ray Tracing: History. Outline. Foundations of Computer Graphics (Spring 2012)

Transformations in Ray Tracing. MIT EECS 6.837, Durand and Cutler

Assignment 6: Ray Tracing

Scalar Field Visualization I

The feature set you are required to implement in your ray tracer is as follows (by order from easy to hard):

Computer Graphics. Lecture 02 Graphics Pipeline. Edirlei Soares de Lima.

SOLVING SYSTEMS OF EQUATIONS

Geometric Primitives. Chapter 5

Ray scene intersections

Viewing and Ray Tracing. CS 4620 Lecture 4

PITSCO Math Individualized Prescriptive Lessons (IPLs)

CS 563 Advanced Topics in Computer Graphics Lecture 2: Bare-Bones Raytracer. by Emmanuel Agu

CS348B Lecture 2 Pat Hanrahan, Spring Greeks: Do light rays proceed from the eye to the light, or from the light to the eye?

CS354 Computer Graphics Rotations and Quaternions

Barycentric Coordinates and Parameterization

Topics and things to know about them:

Viewing and Ray Tracing

COMP 175 COMPUTER GRAPHICS. Lecture 11: Recursive Ray Tracer. COMP 175: Computer Graphics April 9, Erik Anderson 11 Recursive Ray Tracer

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Basics of Computational Geometry

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Moore Catholic High School Math Department

MITOCW MIT6_172_F10_lec18_300k-mp4

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Computer Graphics and Image Processing Ray Tracing I

Ray Casting. Connelly Barnes CS 4810: Graphics

Supplement to Lecture 16

Triangle meshes I. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2017

CS770/870 Spring 2017 Ray Tracing Implementation

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

Interacting with a 3D World

Ray Casting. Outline. Similar to glulookat derivation. Foundations of Computer Graphics

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Perspective Mappings. Contents

Triangle meshes I. CS 4620 Lecture 2

Assignment 2 Ray Tracing

TEACHER CERTIFICATION STUDY GUIDE KNOWLEDGE OF MATHEMATICS THROUGH SOLVING...1

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

CS4411 Intro. to Operating Systems Final Fall points 12 pages

Ray Tracing COMP575/COMP770

Camera Placement for Ray Tracing

Year 8 Mathematics Curriculum Map

Solid Modeling. Ron Goldman Department of Computer Science Rice University

The Distributive Property and Expressions Understand how to use the Distributive Property to Clear Parenthesis

2-D Geometry for Programming Contests 1

CS Simple Raytracer for students new to Rendering

Computer Graphics. - Ray Tracing I - Marcus Magnor Philipp Slusallek. Computer Graphics WS05/06 Ray Tracing I

Monte Carlo Ray Tracing. Computer Graphics CMU /15-662

Math (Spring 2009): Lecture 5 Planes. Parametric equations of curves and lines

Transcription:

CS 6958 LECTURE 4 INTRO TO GRAPHICS GEOMETRY January 15, 2014

Administrative Email me if you are not on the mailing list dkopta@cs.utah.edu teach-cs6958@list.eng.utah.edu

Geometry for Graphics

Geometry for Graphics If it doesn t have any math, it probably isn t worth doing. If it has too much math, it definitely isn t worth doing -Steve Parker

Geometry for Ray Tracing Point Vector Triangle Ray Plane, Sphere, Disk, Cylinder, All of these can be made with tessellated triangles Assumed that all of these are 3D

Vectors In 3D, a vector is just 3 floats <x, y, z> Intuitive meaning: a direction and length 2D example <3, 2>

Points Also just 3 floats <x, y, z> Intuitive meaning: a point in space <3, 2>

Vectors Addition A + B = <A.x + B.x, A.y + B.y, A.z + B.z> <3, 2> + <1, 2>

Vectors Scalar multiplication 2A = <2*A.x, 2*A.y, 2*A.z> 2.0 * <3, 2>

Vector Properties If A, B, C are vectors Commutative A + B = B + A Associative addition (A + B) + C = A + (B + C) Additive Inverse A + (-A) = 0

Vector Properties A, B, C are vectors, r, s are scalars Associativity of scalar multiplication (rs)a = r(sa) Distributivity of scalar sums (r + s)a = ra + sa Distributivity of vector sums r (A + B) = ra + rb

Vectors vs. Points If P is a point, V is a vector What does P + P mean? Translation? What does translation mean for V? In code they re both just a set of 3 floats

Vectors/Points P1 = P0 + V P1 P0 V

Vectors/Points V = P1 P0 Distance between P0 and P1 = V V P0 P1

Points vs. Vectors Operators that do make sense: P = P+V P = P-V V = P-P V = V + V V = V - V V = s * V V = - V V = V * V

Other Operators A, B are vectors Dot product multiplies them, but results in a scalar A B = Ax * Bx + Ay * By + Az * Bz

Useful Properties cos(θ) = A B A B A θ B

Useful properties Length of a vector V = V = sqrt(vx^2 + Vy^2 + Vz^2) Or: V = sqrt(v V) V V = length squared

Unit Vector A vector with unit length (1.0) is normalized If V V = 1, V is normalized

Rays Origin O, direction V, distance t Normalize V so we can parameterize distance t = distance to object V = 1 Intersection point P: O + tv O + tv O + 2V O + 1V O P V

Normalizing a Vector unit(v) = Vx, Vy, Vz < > V V V V = sqrt(v V) Preserves direction of V

Normalized Vectors If A and B are normalized vectors cos(θ) = A B A B = A B We find ourselves regularly normalizing ray directions!

Cross Product A, B, C are vectors AxB C = A x B right hand rule B <AyBz - AzBy, AzBx - AxBz, AxBy - AyBx> A

Cross Product C = A x B AxB C is perpendicular to both A and B A x B = A B sinθ A x B = area of swept rectangle If A = B or A = -B, then A x B = 0 A B

Colors We will use Red, Green, Blue (RGB) Other color spaces exist A color is 3 floats (but don t use Vector!) Range is 0 1 (but allow them to go higher) Operators: Color * Color Color * scalar Color - Color Color + Color

Images An image is a helper class 2D array of pixels Pixel!= Color (must clamp to 0 1 first) Knows where the framebuffer is Has function to set pixel, given (color, i, j) Convert i, j coordinates to address in framebuffer

Framebuffer is upside down y=0 y=0 Real world Our ray tracer OpenGL Taught since 2nd grade Televisions Raster Images Other 1950 s technology 2D arrays

Framebuffer is upside down start_fb + ((xres*3) * yres) start_fb + ((xres*3) * yres) + (xres * 3) start_fb start_fb + (xres*3)

Geometric Queries Back to the original question: Ray tracing: determine if (and where) rays hit an object! O + t! V Where? May be interested in the point itself, or just the distance

Geometric Queries Ray-Plane Ray-Sphere Ray-Triangle Ray-Cylinder, Disk, Ring, Torus, Mobius Strip Ray-Box Ray-implicit function

Ray-sphere intersection Points on a sphere are equidistant from the center Our measure of distance: dot product Equation for sphere:! ( P C! )i P! C! ( ) r 2 = 0 Assume intersection point P exists P P-C r C

Ray-sphere intersection Now represent P as a function of the ray Assume intersection point P exists t is what we need t P O V

Ray-sphere intersection Using both equations: t P Substitute: O V P-C r C

Ray-sphere intersection Quadratic equation with: a = V V b = 2(O C) V c = (O C) (O C) r^2 Roots:

Ray-sphere intersection If the discriminant is negative, the ray misses the sphere Otherwise, there are two distinct intersection points (the two roots) CS6620 Spring 07

Ray-sphere intersection Which root do we care about? Be careful! Don t want rays behind the camera showing in our image CS6620 Spring 07

Assignment 1

Assignment 1 Implement: Vector Color Image Ray Sphere

Ray Skeleton class Ray { public: Vector org; Vector dir; Ray() { } Ray(const Vector& origin, const Vector& direction) : org(origin), dir(direction) { }

TRaX Programming https://code.google.com/p/simtrax/wiki/programming See simtrax/samples/src/ for examples Always include trax.hpp void trax_main() instead of int main()

Guidelines/Restrictions The TRaX compiler can be a bit fragile Doesn t quite support full C++ However, these restrictions are likely to result in faster code

No double data types Single-precision float only! Using double may cause compilation to fail Can be tricky to avoid float pi = 3.14 float pi = 3.14f float f = 5; float f = 5.f;

No dynamic memory new/malloc, free/delete We will see how to deal with this when we start using main memory No destructors! Compiler will fail Any variables you declare are on the perthread stacks Including arrays Remember tiny stack space

Global variables Avoid them Primitive types (float, int, ) should be OK class/struct types will cause compiler to fail

Inheritance/Templates Avoid them Polymorphism is slow

Pass By Reference Do this whenever possible Copying arguments is slow Especially for large data types Pass by const reference keeps the original data safe

Standard libraries They don t exist for TRaX No one has compiled them for TRaX Only include trax.hpp and your own source files trax.hpp gives you some standard library functionality printf Various math routines

trax.hpp Some of the useful functions (more as we need them) invsqrt(float f) sqrt(float f) min(float a, float b) max(float a, float b) GetXRes() GetYRes() GetFrameBuffer()

Implementation For Vector, Color Overload all operators that make sense Vector operator*(float s) const; Vector operator+(const Vector& v) const; Up to you if you want to distinguish Point/Vector Other useful Vector ops cross dot normalize length

Compiling The easiest thing to do: Put your new programs in a subdirectory of: simtrax/samples/src Copy an existing Makefile in to your directory Run make

Writing to the Framebuffer See mandelbrot sample int start_fb = GetFrameBuffer(); pointer to framebuffer Main memory pointers are just integers (untyped) No array indexing! [] storef(red, start_fb + ( i * xres + j ) * 3, 0 ); storef(green, start_fb + ( i * xres + j ) * 3, 1 ); storef(blue, start_fb + ( i * xres + j ) * 3, 2 ); 3 floats per pixel

Simtrax Configuration --num-icaches --num-icache-banks Bank 0 Instruction Cache Bank 1 Thread PC Stack RF RAM Thread PC Stack RF RAM Thread PC Stack RF RAM --num-thread-procs FUs Int Add FP Mul FP Inv --config-file

Analysis What is holding performance back? For now, this is mostly determined by Issue Statistics Module Utilization

Issue Statistics Issue Rate: Want this as high as possible icache conflicts Tracked separately from resource conflicts thread*cycles of resource conflicts FU conflicts, L1, L2, DRAM thread*cycles of data dependence Nothing you can do about this (for now) Includes RF conflicts

Default Areas (square mm) FPADD.003 FPMIN.00072 FPCMP.00072 INTADD.00066 FPMUL.0165 INTMUL.0117 FPINV.112 CONV.001814 BLT.00066 BITWISE.00066

Module Utilization FP AddSub: 41.41 FP Compare: 12.63 Does not show every module! Only the large ones You will likely need to increase the number of smaller units as well (Bitwise for ORI, BLT for branches) A utilization of 40% is pretty high, try to drop it down

Instruction Caches: Multiple Banks Address à bank mapping is strided Bank 0 Instruction Cache Bank 1 Thread a: PC = 0 Thread b: PC = 1 Bank 0 Instruction Cache Bank 1 Thread a: PC = 0 Thread b: PC = 2 (bank conflict!)

Instruction Caches: Multiple Caches Consumes much more area, but potentially reduces conflicts icache 1 Thread a: PC = 0 icache 2 Thread b: PC = 2

Instruction Caches Instruction caches are actually double pumped Each bank can service 2 requests every cycle