Computer Graphics Ray tracing

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

Lecture 8 Transparency, Mirroring
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Light Issues in Computer Graphics Presented by Saleema Amershi.
Chapter 11: Advanced Rendering Part 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
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.
CS 376 Introduction to Computer Graphics 04 / 09 / 2007 Instructor: Michael Eckmann.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
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.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
Ray Tracing 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
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.
Presentation by Dr. David Cline Oklahoma State University
Reflections Specular reflection is the perfect reflection of light from a surface. The law a reflection states that the direction of the incoming ray and.
CS 376 Introduction to Computer Graphics 04 / 11 / 2007 Instructor: Michael Eckmann.
1 Ray-Tracing ©Anthony Steed Overview n Recursive Ray Tracing n Shadow Feelers n Snell’s Law for Refraction n When to stop!
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
Ray Tracer Spring 2008 Help Session. Outline Project Web Resources What do you have to do for this project? Ray Class Isect Class Requirements Tricks.
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 CSIS 5838: Graphics and Animation for Gaming.
CS380: Computer Graphics Distributed Ray Tracing TA Course URL:
Ray-tracing.
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.
Project 3 Help Session: Ray Tracing. Getting Started Download the starter pack. 1.sample_ray.exe 2.ray-skel directory 3.scenes directory Look at the Road.
More on Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, April 14, 2004.
RENDERING : Global Illumination
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Ray Tracing I. Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections and
CS552: Computer Graphics Lecture 36: Ray Tracing.
Review Ray Tracing III Review. Pseudo codes RayCast-1  Plain ray caster (direct illumination) RayCast-2  RayCast-1 + shadow rays RayTrace-1  Recursive.
Introduction to Ray Tracing Dr. B. Raghu Professor /CSE Sri Ramanujar Engineering College.
Advanced Computer Graphics
Geometric Optics AP Physics Chapter 23.
Mirrors and Lenses.
CSE 167 [Win 17], Lecture 15: Ray Tracing Ravi Ramamoorthi
Reflection of Light Waves
Photorealistic Rendering vs. Interactive 3D Graphics
IV. Optics Nature of light. Spectrum of electromagnetic waves.
Ray Tracer Spring 2007 Help Session.
Introduction to Computer Graphics with WebGL
Chapter 32Light: Reflection and Refraction
Ray Tracing Ed Angel Professor Emeritus of Computer Science
CS G140 Graduate Computer Graphics
Ray Tracing Dr. Scott Schaefer.
IV. Optics Nature of light. Spectrum of electromagnetic waves.
3D Graphics Rendering PPT By Ricardo Veguilla.
Introduction to Computer Graphics with WebGL
Lecture 11: Recursive Ray Tracer
Ray Tracing.
Rendering Wet Looking Objects
The law of reflection: The law of refraction: Image formation
Lesson 17 Key Concepts and Notes
CS5500 Computer Graphics May 29, 2006
14th Lecture – Final Lecture
Ray Tracer Spring 2004 Help Session.
GR2 Advanced Computer Graphics AGR
Ray Tracer Spring 2008 Help Session.
Light Reflection – the “bouncing” of light off of a surface. The light does not pass through the surface (called a medium), Refraction – is the “bending.
Reflection and Refraction
Simple Texture Mapping
Computer Graphics Ray tracing
Computer Graphics Ray tracing
Ray Tracer Autumn 2005 Help Session.
Ray Tracer Spring 2006 Help Session.
Presentation transcript:

Computer Graphics Ray tracing Step 2 2016

Outline multiple sphere (at lease 3 big and 6 small sphere) recursive intersection with refraction and transmission material attribute (Kd, n_t in Snell’s Law, w_r, ….) bonus

More sphere vec3 color(const ray& r) { float t = hit_sphere(…); if (t > 0.0) { vec3 N = unit_vector(r.point_at_parameter(t) – center); return 0.5*vec3(N.x()+1, N.y()+1, N.z()+1); } float t2 = hit_sphere(…); if (t2 > 0.0) { return skybox(); //When no intersection Problem??

struct hit_record { float t; vec3 p; vec3 normal; and more … }; class hitable { public: virtual bool hit(const ray& r, float tmin, float tmax, hit_record& rec) const = 0;

class sphere: public hitable { public: sphere() {} sphere(vec3 c, float r) : center(c), radius(r) {}; virtual bool hit(const ray& r, float tmin, float tmax, hit_record& rec) const; vec3 center; float radius; }; bool sphere::hit(const ray& r, float tmin, float tmax, hit_record& rec) const { … } Why tmin? tmax?

Nearest intersection point Init Add all hitable object into a list intersect() in page 11 hit_record ht[n] for(all hitable object o) { o.hit(…, ht[i]); } Find ht[smallest_index]) with smallest t; Shading(lightposition, lightintensity, ht[smallest_index]);

Why tmin/tmax in hit()?

Result with multi-sphere //camera vec3 lower_left_corner(-2, -1, -1); vec3 origin(0, 0, 1); vec3 horizontal(4, 0, 0); vec3 vertical(0, 2, 0); //light vec3 LightPosition(-10, 10, 0); vec3 LightIntensity(1.0, 1.0, 1.0); vector<sphere> hitable_list; … //objects in the world hitable_list.push_back(sphere(vec3(0, -100.5, -2), 100)); hitable_list.push_back(sphere(vec3(0, 0, -2), 0.5)); hitable_list.push_back(sphere(vec3(1, 0, -1.75), 0.5)); hitable_list.push_back(sphere(vec3(-1, 0, -2.25), 0.5)); srand(1234); for (int i = 0; i < 48; i++) { float xr = ((float)rand() / (float)(RAND_MAX)) * 6.0f - 3.0f; float zr = ((float)rand() / (float)(RAND_MAX)) * 3.0f - 1.5f; hitable_list.push_back(sphere(vec3(xr, -0.45, zr-2), 0.05)); }

recursive intersection with refraction and transmission

Recursive Ray Tracer(1/3) color trace(point p, vector d, int step) { color local, reflected, transmitted; point q; normal n; if(step > max) return vec3(0, 0, 0);//black or background p d

Recursive Ray Tracer (2/3) N p q = intersect(p, d, status); //if(status==light_source) //return(light_source_color); if(status==no_intersection) return(background_color); n = normal(q); //or get from hit_record r = reflect(q, n); t = transmit(q, n); r d q t Case status==light_source * Add light_source as small sphere in intersection()

Recursive Ray Tracer (3/3) local = shading(…); reflected = trace(q, r, step+1); transmitted = trace(q, t, step+1); return(w_l*local + w_r*reflected + w_t*transmitted); } N Local: contribution from shading in q p r d assume Mirror: w_l=1.0f, w_r=1.0f, w_t =0.0f Glass: w_l=07.f, w_r=0.3f, w_t =1.0f Plastic: w_l=0.9, w_r=0.6f, w_t =0.0f q t

Computing a Reflected Ray   N S S Rin Rout Ɵ Ɵ http://www.opengl.org/sdk/docs/manglsl/xhtml/reflect.xml

hitable_list.push_back(sphere(vec3(1, 0, -1.75), 0.5, 1.0f)); class sphere: public hitable { public: sphere() {} sphere(vec3 c, float r, float w_ri=0.0f, float w_ti=0.0f) : center(c), radius(r), w_r(w_ri), w_t(w_ti) {}; virtual bool hit(const ray& r, float tmin, float tmax, hit_record& rec) const; vec3center; floatradius; floatw_r; floatw_t; }; return (1.0f-rec_nearest.w_r)*local_color + rec_nearest.w_r*reflected_color;

Transformed ray d θ N θ r t Air: 1 Glass: 1.46   d θ N   θ r t Air: 1 Glass: 1.46 https://www.opengl.org/sdk/docs/man4/html/refract.xhtml Find the refractive vector and index https://en.wikipedia.org/wiki/Snell%27s_law https://en.wikipedia.org/wiki/List_of_refractive_indices

hitable_list.push_back(sphere(vec3(0, 0, -2), 0.5, 0.0f, 0.9f)); vec3 colorlist[8] = { vec3(0.8, 0.3, 0.3), vec3(0.3, 0.8, 0.3), vec3(0.3, 0.3, 0.8), vec3(0.8, 0.8, 0.3), vec3(0.3, 0.8, 0.8), vec3(0.8, 0.3, 0.8), vec3(0.8, 0.8, 0.8), vec3(0.3, 0.3, 0.3) }; //objects in the world hitable_list.push_back(sphere(vec3(0, -100.5, -2), 100)); //ground hitable_list.push_back(sphere(vec3(0, 0, -2), 0.5, vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.9f)); hitable_list.push_back(sphere(vec3(1, 0, -1.75), 0.5, vec3(1.0f, 1.0f, 1.0f), 0.9f)); hitable_list.push_back(sphere(vec3(-1, 0, -2.25), 0.5, vec3(1.0f, 0.7f, 0.3f))); srand(1234); for (int i = 0; i < 48; i++) { float xr = ((float)rand() / (float)(RAND_MAX)) * 6.0f - 3.0f; float zr = ((float)rand() / (float)(RAND_MAX)) * 3.0f - 1.5f; int cindex = rand() % 8; float rand_reflec = ((float)rand() / (float)(RAND_MAX)); float rand_refrac = ((float)rand() / (float)(RAND_MAX)); hitable_list.push_back( sphere(vec3(xr, -0.4, zr-2), 0.1, colorlist[cindex], rand_reflec, 0.0f) ); } return (1.0f - w_t) * ((1.0f-.w_r) * local_color + rw_r*reflected_color) + w_t*transmitted_color;

shading color shading(vec3 lightsource, vec3 lightintensity, hit_record ht, vec3 Kd) { trace ShadowRay vec3 color = ? * max(0, N dot L)* I * Kd; Return color; }

Bonus More image format (bmp, png, …) Easy for debug Attenuation

Anti-alias More transparent sphere Maxstep =5

Reference Chapter 4 in Fundamentals of Computer Graphics, 4/e.