Computer Graphics -Ray Tracing- 1 st quarter, 2015 Nara Institute of Science and Technology May 21, 2015

Similar documents
Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

CS Simple Raytracer for students new to Rendering

Assignment 2 Ray Tracing

Ray Casting. To Do. Outline. Outline in Code. Foundations of Computer Graphics (Spring 2012) Heckbert s Business Card Ray Tracer

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

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

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

Computer Graphics Tick 1

CS 184: Assignment 4 Simple Raytracer

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

Assignment 6: Ray Tracing

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

Computer Graphics Tick 2

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

Ray Casting. Connelly Barnes CS 4810: Graphics

Ray-Tracing. Misha Kazhdan

Raytracing CS148 AS3. Due :59pm PDT

Project 1 Simple Ray Tracer

Intro to Ray-Tracing & Ray-Surface Acceleration

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

Illumination. Michael Kazhdan ( /657) HB Ch. 14.1, 14.2 FvDFH 16.1, 16.2

Lighting and Shading

Lecture 10: Ray tracing

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Programming projects. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer. Assignment 1: Basic ray tracer

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

CIS 580, Machine Perception, Spring 2015 Homework 1 Due: :59AM

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

DH2323 DGI13. Lab 2 Raytracing

3D Rendering and Ray Casting

Interactive Real-Time Raycasting

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

CS 184: Assignment 2 Scene Viewer

Global Illumination CS334. Daniel G. Aliaga Department of Computer Science Purdue University

EDAN30 Photorealistic Computer Graphics. Seminar 1, Whitted Ray Tracing (And then some!) Magnus Andersson, PhD student

Practical 2: Ray Tracing

Introduction to Ray-tracing Objectives

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

Last Time? Ray Casting. Administrivia: Lab & Office Hours. Notes on Assignments. Ray Casting. Overview of Today

Ray Tracing. Outline. Ray Tracing: History

Ray Tracing. Kjetil Babington

Global Illumination. COMP 575/770 Spring 2013

Shadows. COMP 575/770 Spring 2013

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Photorealism: Ray Tracing

Assignment #2. (Due date: 11/6/2012)

COMP371 COMPUTER GRAPHICS

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

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

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

CS Computer Graphics: Ray Tracing Detail, Part 3

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

Computer Graphics and Image Processing Ray Tracing I

Ray Tracing. CS116B Chris Pollett Apr 20, 2004.

Computer Graphics I. Assignment 3

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

TDA361/DIT220 Computer Graphics, January 15 th 2016

Deferred Rendering Due: Wednesday November 15 at 10pm

Computer Graphics and Image Processing Ray Tracing II. Additional material

Topic 12: Texture Mapping. Motivation Sources of texture Texture coordinates Bump mapping, mip-mapping & env mapping

Viewing and Ray Tracing. CS 4620 Lecture 4

Voxel-Based Global-Illumination

Ray Tracer Due date: April 27, 2011

Viewing and Ray Tracing

Lecture 11. More Ray Casting/Tracing

CS 6958 LECTURE 5 TM ANALYSIS SHADING

Topic 11: Texture Mapping 11/13/2017. Texture sources: Solid textures. Texture sources: Synthesized

Motivation: Monte Carlo Path Tracing. Sampling and Reconstruction of Visual Appearance. Monte Carlo Path Tracing. Monte Carlo Path Tracing

A simple OpenGL animation Due: Wednesday, January 27 at 4pm

Project 3 Path Tracing

Computer Graphics. Ray Tracing. Based on slides by Dianna Xu, Bryn Mawr College

Computer Graphics Global Illumination

Motivation. Monte Carlo Path Tracing. Monte Carlo Path Tracing. Monte Carlo Path Tracing. Monte Carlo Path Tracing

Topic 11: Texture Mapping 10/21/2015. Photographs. Solid textures. Procedural

Homework #2. Shading, Ray Tracing, and Texture Mapping

Ray tracing Tutorial. Lukas Herzberger

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

Final Project: Real-Time Global Illumination with Radiance Regression Functions

Raytracing. COSC 4328/5327 Scott A. King

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

Review for Ray-tracing Algorithm and Hardware

Computer Graphics Global Illumination

Parallelization. Memory coherency helps when distributing rays to various threads/processors

Movie: For The Birds. Announcements. Ray Tracing 1. Programming 2 Recap. Programming 3 Info Test data for part 1 (Lines) is available

COMPUTER GRAPHICS AND INTERACTION

CS 4620 Midterm, March 21, 2017

Ray Tracing. Foley & Van Dam, Chapters 15 and 16

To Shading and Beyond. CS 6965 Fall 2011

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Ray Tracing Foley & Van Dam, Chapters 15 and 16

Lecture 12: Advanced Rendering

CS Computer Graphics: Ray Tracing Detail, Part 3

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Ground Truth. Welcome!

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

Ray Tracing I: Basics

6. Illumination, Lighting

Ray Tracing COMP575/COMP770

Transcription:

Computer Graphics -Ray Tracing- 1 st quarter, 2015 Nara Institute of Science and Technology May 21, 2015

Today s topics Questions and Answers How to build a ray tracer (Homework 3.1 explanation)

Questions? https://goo.gl/9tfgsg

Homework 3.1??? 1. Take lecture 9 and lecture 10 @ edx 2. Download the course notes from edx website: L9: Ray Tracing 1 PDF Slides and L10: Ray Tracing 2 PDF Slides 3. Download a skeleton code from our lecture website 4. Find 3 blanks in main.cpp, then fill it (search todo comments) 5. Submit your implementation to the submission form.

Instruction For the homework 3.1 (beginner course), Fill 3 blank functions in main.cpp. 1. void RayThruPixel() 2. double Intersect() 3. Vector3d FindColor() NEVER mind the instruction of original homework3 on edx. This is our original assignments. You may implement these functions reference to edx lecture notes. homework 3.1 main.cpp 1. void RayThruPixel() 2. double Intersect() 3. Vector3d FindColor() edx homework3 edx

Kazutaka Sawa Portfolio Let s start building a ray tracer!

1. Take lecture 9 and lecture 10 @ edx, 2. Download the course notes from edx website Lecture9 Slide Lecture10 Slide

Ray tracing algorithm overview Light Source 1. Generate a ray from camera origin to a pixel. 2. If a ray hits an object, find color. Else, returns background color. Object Virtual screen FoV_Y (Field of View) Cam

3. Download a skeleton code from our lecture website 1. Download from here-> 2. Unzip it!

In case: Visual Studio 2010;

Goal When you finish your implementation, a cute snowman is rendered.

Almost everything are written in main.cpp. main.cpp 4 significant structs and classes: struct Ray: Light Ray struct Sphere: Sphere s size and location, also its material property. class Camera: Virtual camera propertis, such as losition, center etc Scene: Contains objects and lights. Currently, only single point light can be stored. 1 struct Ray Vector3d P0; /* Origin */ Vector3d P1; /* Direction */ }; struct Sphere Vector3d C; /* Center */ double Radius;/* Radius */ Vector3d Kd; Vector3d Ke; }; class Camera public: Vector3d Pos; /* Virtual Viewpoint */ Vector3d Center;/* Camera Center */ Vector3d Up; /* Up Vector */ int Width; /* Sensor Resolution */ int Height;/* Sensor Resolution */ double FoV_Y; /* Vertical Field of View */ double Aspect; double FoV_X; }; class Scene public: Sphere* spheres; int NumObjects; Vector3d PointLightPos; double Li; }; main.cpp

Ray struct Ray: Light Ray P0: origin P1: direction struct Ray Vector3d P0; /* Origin */ Vector3d P1; /* Direction */ Ray(const Vector3d origin, const Vector3d dirction) P0 = origin; P1 = dirction; } Ray(const Ray &ray) P0 = ray.p0; P1 = ray.p1; } }; Q: P1 is vector. main.cpp

Sphere struct Sphere: Sphere s size and location, also its material property. Radius C: center struct Sphere Vector3d C; /* Center */ double Radius; /* Radius */ Vector3d Kd; /* Diffuse */ Vector3d Ke; /* Emmision */ Sphere(double r, Vector3d center, Vector3d kd, Vector3d ke) : C(center), Radius(r), Kd(kd), Ke(ke)} }; main.cpp

Camera struct Sphere: Sphere s size and location, also its material property. Up Width Pos Center Height FoV_Y: Field of View Angle (y) class Camera public: Vector3d Pos; /* Virtual Viewpoint */ Vector3d Center;/* Camera Center */ Vector3d Up; /* Up Vector */ int Width; /* Sensor Resolution */ int Height;/* Sensor Resolution */ double FoV_Y; /* Vertical Field of View */ double double public: Aspect; FoV_X; Camera(const Vector3d pos, const Vector3d center, const Vector3d up, const int width, const int height, const double fov_y) :Pos(pos), Center(center), Up(up), Width(width), Height(height), FoV_Y(fov_y) this->aspect = (double)width/(double)height; this->fov_x = 2.0 * atan(this->aspect*tan(this->fov_y/2.0)); } }; main.cpp

Did you finish download a skeleton code?

int main(void) int main(void) /* Camera Settings */ /*Camera Position */ Vector3d pos = Vector3d(50.0, 52.0, 295.6); /*Camera Direction */ Vector3d dir = Vector3d::Normalize(Vector3d(0.0,0.0,-1.0)); int width = 128; /* Image width */ int height = 128; /* Image height */ double fov = 60.0 / 180.0 * M_PI; /* field of view */ Camera cam(pos, pos + dir, Vector3d(0, 1, 0), width, height, fov); /* Scene Settings */ Scene scene; /* Current scene contains 3 spheres. */ scene.spheres = spheres; scene.numobjects = 3; /* and contains one point light source. */ scene.pointlightpos = Vector3d(100, 100, 100); scene.li = 1.0; /* Do the ray tracing */ Image* img = RayTrace(cam, scene, cam.width, cam.height); } /* Save image */ img->savebmp("image.bmp"); delete img; return 0;

1. Generate a ray from camera origin to a pixel. 2. If a ray hits an object, find color. Else, returns background color. /* See also slides_raytrace2.pdf pp1. */ Image* RayTrace(const Camera& cam, const Scene& scene, const int width, const int height) Image* image = new Image(width, height); int count = 0; for (int i = 0 ; i < height ; i++) for (int j = 0; j < width ; j++) Ray ray = RayThruPixel(cam, j, i); 1. Gen a ray from camera fprintf(stderr, " rrender: %5.2f%%", (100.0*(count++))/(width*height-1)); } IntersectionInfo hit = Intersect(ray, scene); image->data[width*i+j] = FindColor(scene, hit); } } return image; 2. Find color Cam

Homework 3.1 Steps and Hints Step 1: We would like to find a snowman s silhouette. Implement RayThruPixel and Intersect, first. Step 2: Then fill a blank space in Find Color /* See also slides_raytrace2.pdf pp1. */ Image* RayTrace(const Camera& cam, const Scene& scene, const int width, const int height) Image* image = new Image(width, height); int count = 0; for (int i = 0 ; i < height ; i++) for (int j = 0; j < width ; j++) Ray ray = RayThruPixel(cam, j, i); fprintf(stderr, " rrender: %5.2f%%", (100.0*(count++))/(width*height-1)); } IntersectionInfo hit = Intersect(ray, scene); image->data[width*i+j] = FindColor(scene, hit); } } return image;

Step1 (1) RayThruPixel RayThruPixel generates a ray from camera position to a specific pixel on a virtual screen. /* See also slides_raytrace2.pdf pp2. */ /* Note: there're several typo in the slide. */ Ray RayThruPixel(const Camera& camera, const int i, const int j) /* TODO: Implement Camera Ray Generation*/ Vector3d origin = camera.pos; Vector3d direction = Vector3d(0, 0, -1); pixel } return Ray(camera.Pos, direction); Ray Virtual Screen Cam

origin direction

Lesson1. Implement RayThruPixel Function

Step1 (2) Intersection Intersect returns a distance between the ray origin and the hit point on the sphere. If no intersection, returns -1. double Intersect(const Ray& ray, const Sphere& sphere) /*TODO: Implement ray-sphere intersection. */ /* return positive distance from ray origin to intersection */ /* return -1, if no sphere intersects */ /* solve the eq. : at^2 + bt + c = 0 */ /* Complex roots: no intersection */ /* 2 roots found */ distance /* 2 real positive roots: pick smaller root */ /* One positive, one negative root: ray origin inside sphere (pick + root) */ Ray origin } /* Both negative, no intersection */ return -1;

Object/Object Intersections http://www.realtimerendering.com/intersecti ons.html

Do you remember Quadric Formula? 2 ax 2 + bx + c = 0 x = b ± b2 4ac 2a

Lesson2. Implement Intersect Function

Errata There s a typo in my skeleton code (sorry!), Ray ray = RayThruPixel(cam, j, i); Ray ray = RayThruPixel(cam, i, j);

Step 2: Fill a blank space in Find Color To implement Vector3d FindColor(), you may refer the slide Please ignore both ambient term and specular term. My ray tracer does not support both effects. There s a single point light source, only. You don t have to sum up all lights.

Shading Model I = K e + VL i K d max(l i n, 0) I: Radiance (~ pixel color) Ke: Emission V: Visibility term. Li: Light Intensity Kd: Diffuse reflectance li: Light vector n: normal vector 1. First, you may try without visibility term. (V is just set to 1.0) 2. Next, generate the second ray (called shadow ray) from hitpoint to light source, then trace a ray as : IntersectionInfo hit = Intersect(ray, scene); if hit.hitobject == null, there s no intersection. V = 1.0. Else, V = 0.0. 3. Hint: The origin of the shadow ray must push up slightly, along the normal direction to avoid intersecting by itself.

Step 2: Fill a blank space in Find Color /* See also slides_raytrace2.pdf pp2. */ /* Note: there're several typo in the slide. */ Ray RayThruPixel(const Camera& camera, const int i, const int j) /* TODO: Implement Camera Ray Generation*/ Vector3d origin = camera.pos; Vector3d direction = Vector3d(0, 0, -1); } return Ray(camera.Pos, direction);

Lesson3. Implement FindColor Function

Lesson 4. Create another snowman with another color. Lesson 5. Create another light source Lesson 6. Create a large mirror ball