Interactive Real-Time Raycasting

Similar documents
Raytracing CS148 AS3. Due :59pm PDT

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

CS5620 Intro to Computer Graphics

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Shading I Computer Graphics I, Fall 2008

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

w Foley, Section16.1 Reading

CPSC 314 LIGHTING AND SHADING

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Illumination Models & Shading

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CS230 : Computer Graphics Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Illumination and Shading

Illumination. Illumination CMSC 435/634

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Computer Graphics Tick 1

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

Illumination and Shading

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

Comp 410/510 Computer Graphics. Spring Shading

Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

Illumination & Shading

Computer Graphics. Illumination and Shading

Introduction. Lighting model Light reflection model Local illumination model Reflectance model BRDF

Shading. Reading. Pinhole camera. Basic 3D graphics. Brian Curless CSE 557 Fall Required: Shirley, Chapter 10

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

Shading. Brian Curless CSE 557 Autumn 2017

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

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

Illumination in Computer Graphics

Visualisatie BMT. Rendering. Arjan Kok

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CPSC / Illumination and Shading

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Turn on the Lights: Reflectance

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

COMP environment mapping Mar. 12, r = 2n(n v) v

Illumination & Shading: Part 1

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

CS 4620 Program 3: Pipeline

Classic Rendering Pipeline

Virtual Reality for Human Computer Interaction

The exam begins at 2:40pm and ends at 4:00pm. You must turn your exam in when time is announced or risk not having it accepted.

Review for Ray-tracing Algorithm and Hardware

U.C. Berkeley, EECS, Computer Science TAKE HOME EXAM. Your Class Computer Account: DO NOT OPEN THIS INSIDE SODA HALL -- WAIT UNTIL YOU ARE ALONE!

Midterm Exam CS 184: Foundations of Computer Graphics page 1 of 11

Computer Graphics. Illumination and Shading

Topics and things to know about them:

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Introduction to Computer Graphics 7. Shading

Reflection and Shading

Lighting and Shading

Lights, Surfaces, and Cameras. Light sources emit photons Surfaces reflect & absorb photons Cameras measure photons

Lighting affects appearance

Sung-Eui Yoon ( 윤성의 )

Lighting. Figure 10.1

CS 130 Final. Fall 2015

Module 5: Video Modeling Lecture 28: Illumination model. The Lecture Contains: Diffuse and Specular Reflection. Objectives_template

Shading. Brian Curless CSE 457 Spring 2017

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

CS384G Midterm Examination Spring 2008

CS452/552; EE465/505. Intro to Lighting

Raytracing. COSC 4328/5327 Scott A. King

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

surface: reflectance transparency, opacity, translucency orientation illumination: location intensity wavelength point-source, diffuse source

Local vs. Global Illumination & Radiosity

Shading. Why we need shading. Scattering. Shading. Objectives

Assignment 2 Ray Tracing

Deferred Rendering Due: Wednesday November 15 at 10pm

Introduction to Visualization and Computer Graphics

Illumination & Shading I

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

Illumination. The slides combine material from Andy van Dam, Spike Hughes, Travis Webb and Lyn Fong

Homework #2. Shading, Projections, Texture Mapping, Ray Tracing, and Bezier Curves

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Midterm Exam! CS 184: Foundations of Computer Graphics! page 1 of 13!

Shading and Illumination

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

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

A Little Background. Motivation. Motivation

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Ray-Tracing. Misha Kazhdan

Ray Tracing COMP575/COMP770

-=Bui Tuong Phong's Lighting=- University of Utah, but with shaders. Anton Gerdelan Trinity College Dublin

Simple Lighting/Illumination Models

CS 130 Exam I. Fall 2015

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

CS-184: Computer Graphics. Today

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

Assignment 6: Ray Tracing

Announcements. Written Assignment 2 out (due March 8) Computer Graphics

Transcription:

Interactive Real-Time Raycasting CS184 AS4 Due 2009-02-26 11:00pm We start our exploration of Rendering - the process of converting a high-level object-based description into a graphical image for display. We have talked about drawing 2D objects using a process known as Rasterization. We will now explore the Raytracing approach to rendering. Through the next three projects (AS4 through AS6) you will build an interactive raytracer that will run in semi-realtime. Figure 1: Ray-traced image 0.1 Required Reading Please read section 10 through 10.4 and 10.6 of Shirley s Fundamentals of Computer Graphics for this assignment, and read the complete Chapter 9 and 10 for the raytracing assignments in general. 1

1 Shading - Phong Reflectance Model For this assignment you will use the Phong Reflectance Model to calculate the color of a pixel. The formula for the Phong Reflectance Model, where ρ is the (r, g, b) intensity of light sent towards the eye/camera, is: ρ = k a CA + Lights S = (k sm )C + (1 k sm )(1, 1, 1) k d CI max(î ˆn, 0) + k ssi max(ˆr ˆv, 0) ksp I = (r, g, b) is the intensity of the infalling light. A = (r, g, b) is the intensity of the ambient lightsource in the scene. C = (r, g, b) is the color of the object. S is the linearly interpolated specular highlight color color according to k sm Î is the incidence vector, supplying the angle of incoming light. ˆn is the surface normal vector. ˆv is the vector to the viewer. ˆr is the reflectance vector, supplying the angle of reflected light. k a, k d and k s are the ambient, diffuse and specular surface reflection properties of the material. Colors multiply component-wise, thus CI = {C r I r, C g I g, C b I b } Notice that all the vectors in this equation are unit length vectors. You need to normalize your vectors to ensure this is true. Let s consider the parts of this equation: 1.0.1 Ambient Lighting/Shading Light reflects around a room, illuminating objects uniformly from all sides. This ambient light mixes diffusely, component by component, with the inherent color of the object. 1.0.2 Diffuse Lighting/Shading We assume that surfaces are Lambertian, thus they obey Lambert s Cosine Law: = absorbed and re-emmitted light energy cos(θ incidence ), in other words c ˆn Î This states that the color of a point on a surface is independent of the viewer, and depends only on the angle between the surface normal and the incidence vector (the direction from which light falls on the point). We want the actual color to depend on both the color of the light source I = (r, g, b) and the material s color and diffuse reflectance, specified by k d C: ρ diffuse = k d CI max(ˆn Î, 0) (1) Where ρ diffuse is an (r,g,b) intensity value. Î is just the vector defining the light s direction. ˆn needs to be calculated for the surface itself. Luckily this is easy for spheres, since the normal vector simply points away from the center (see Section 2.4.1). 1.0.3 Specular Lighting/Shading The Phong illumination model states that there may be a bright, mirror-like reflection of the light source on the surface. This effect depends on where the viewer is. The effect is the strongest when the viewer vector and reflectance vector are parallel. ρ specular = k s SI max(ˆr ˆv, 0) ksp (2) 2

The color, S, of this highlight is calculated by linearly interpolating between C and (1, 1, 1) according to k sm, the metalness. A metalness of 1 means that the specular component takes the color of the object, and a metalness of 0 means that the specular component takes the color of the infalling light. k sp is the smoothness of the material - it affects how small and concentrated the specular highlight is. ˆv is calculated between the point on the surface and the viewer position. ˆr, the reflectance vector, is calculated using Î and ˆn: 2 Raycasting Raycasting models the rendering process as follows: ˆr = Î + 2(Î ˆn)ˆn (3) Figure 2: Raycasting To be able to do this, you need the following components: 2.1 Sampling Viewport Our viewport is a rectangle defined by its 4 coordinates in space, LL, LR, UL, UR. We use bilinear interpolation to find a specific point on this rectangle, by varying u and v from 0 to 1 in appropriately sized steps for each pixel. [ P (u, v) = (1 u) (1 v) LL + (v) UL ] [ + (u) (1 v) LR + (v) UR ] (4) 2.2 Ray construction Rays are completely defined by their starting position, e, and their direction, d, both of which are vectors. The direction vector can be represented as the difference between a start and an end vector, giving us the familiar linear interpolation formula, and is very useful for constructing rays from the camera to the image: r(t) = e + t d = e + t( p e) (5) 3

2.3 Intersection Tests We want to find the intersection between a sphere of radius r at position c and a ray from position e in direction d. The sphere can be represented as an Implicit Surface of the form f( p(t)) = 0. Finding the parameter t value at which an intersection occurs means solving that equation. From Shirley, page 206, we find the following formula for t, where d and e describes the ray and c and R described the sphere: ( ) [ ] 1 t = ( d d) ( e c) ± ( d ( e c)) 2 ( d d)(( e c) ( e c) R 2 ) d You can implement this directly using operators on our matrix library s objects, but you want to check for the value of the discriminant (the contents of the square root) before you complete the calculation. If it is negative, the square root will be imaginary, and no intersection occurred. 2.4 Shading Calculations See section 1 for a detailed discussion on calculating shading. 2.4.1 Normals to Spheres A sphere s normal, given its center and a point on its surface, is trivial to find. The normal is the vector from the center to the point on the surface, normalized: ˆn = Norm( p c) = ( p c)/r (7) (6) 4

3 AS4 Minimum Specifications Write a program called raycaster. It will not take in any input files, and the scene will be hard-coded in your int main function. The raytracer will accomplish at least the following: 1. On load, render the scene described further down with three visible spheres and three light sources, illuminating these spheres using the raycasting method. 2. On pressing s, save the current frame to disk as a BMP file with the prefix raycaster 3. Raycasting: Render a scene by casting, for each pixel on the viewport, a single ray from the eye through this pixel into the scene. Find which, if any, object intersects with this ray. Find the color of this ray by performing a shading calculation for the intersection point. 4. Shading: Calculate color according to the Phong reflection model. Take each light into account by summing the shading calculation over all lights, using the given direction vector to calculate the necessary angles. 5. Directional Lights: Model lights as emitting an c = (r, g, b) value where each component is in the range of (0.0, 1.0). Model lights as light rays (photons) moving in a direction d = (x, y, z), allowing you to calculate the angles needed for shading. 6. Primitives and Material Properties: Support spheres defined by a position P and a radius r. Give each sphere a color c = (r, g, b) where each component is in the range of (0.0, 1.0) Support the following material properties, each of which is a coefficient in the shading calculations: Ambient reflectance k a is always visible, regardless of lights in a scene. It multiplies directly with the color c to calculate the ambient color of an object. Diffuse reflectance k d is matte reflection directly related to light falling onto the object from a light source. It multiplies with the color c and is scaled by the angle of incoming light to calculate the diffuse color of an object. Specular term k s is the mirror-like reflection of light off an object to the eye. It multiplies with the color c and is scaled by the angle of incoming light to viewer location to calculate the specular highlight of an object. Metalness k sm controls the color of the specular highlights. ks m = 0 means the highlight is the color of the lightsource, ks m = 1 means the highlight is the color of the object. Specular Exponent (or Phong exponent) k sp characterizes the smoothness (i.e., the sharpness of the highlight spot) of a material, and forms an exponent in the calculation of the specular term. See the Shading section for more details on these terms. 7. Interactivity: Holding down the right mouse button and dragging along the x axis adjusts the metalness k sm of sphere 1. Holding down the right mouse button and dragging along the y axis adjusts the smoothness k sp of sphere 1. 5

4 AS4 Scene Description Your scene will consist of an eye location, a viewport location (defined by 4 corners), three spheres and three different light sources. Their properties are as follows: Screen Size: 512px by 512px Eye: located at e = (0.0, 0.0, 0.0) Viewport: located at: Lower Left: LL = ( 1.0, 1.0, 3.0) Upper Left: UL = ( 1.0, 1.0, 3.0) Lower Right: LR = (1.0, 1.0, 3.0) Upper Right: UR = (1.0, 1.0, 3.0) Sphere 1 (metal): Center p = ( 2.5, 1.5, 17.0), radius r = 2.0 Color c = {r = 0.4, g = 0.5, b = 0.9} Material Properties {ka = 0.1, kd = 0.5, ks = 0.5, ks p = 150, ks m = 1} Sphere 2 (shiny plastic): Center p = (0.0, 4.0, 25.0), radius r = 2.5 Color c = {r = 0.9, g = 0.4, b = 0.5} Material Properties {ka = 0.4, kd = 0.2, ks = 0.5, ks p = 20, ks m = 0} Sphere 3 (chalky): Center p = (1.5, 1.5, 10.0), radius r = 1.0 Color c = {r = 0.5, g = 0.9, b = 0.4} Material Properties {ka = 0.5, kd = 0.5, ks = 0.3, ks p = 4, ks m = 0.5} Light 1: Ambient light, color c = {r = 0.5, g = 0.2, b = 0.2} Light 2: Directional light throwing light in direction d = (0.5, 0.5, 0.5), color c = {r = 0.4, g = 0.8, b = 1.2} Light 3: Point light at position d = (0, 0, 14), color c = {r = 1.39, g = 0.2, b = 0.2} See the figure below for what we expect this to look like. 6

Figure 3: Expected output of given scene with black background removed to save ink. Yours should render with a black background! 5 Design Ideas From discussion section and lecture you should have a fair idea of how raycasting works. Since as4 is the first assignment on raytracing, this assignment does not ask for a full raytracer, while most of the links concern themselves with a full raytracer. Rest assured that what we do is a strict subset of a full raytracer, and that you will need this information for as5 and as6. Thus, the following documentation will help you for this project: Chapter 10 in Shirley s textbook. This chapter is really good and should be your main guide! Raytracer Implementation Journal for CS184 Fa07 http://inst.eecs.berkeley.edu/%7ecs184/sp09/ raytrace journal. Raytracer Design http://inst.eecs.berkeley.edu/ cs184/sp09/resources/raytracing.htm Intersection Tests http://www.realtimerendering.com/intersections.html Fall 2008 notes on shading http://njoubert.com/teaching/cs184 fa08/section/sec03.pdf 5.1 Overall Raytracer Design In the framework we supply the start and the end phases of the raycaster. We supply something that generates points on the viewport form which you can construct rays, and we supply the Image aggregator to which you write color values for pixels at the end of the raycasting cycle. It is up to you to write the parts in between. Let s consider a reasonable design for a raycaster, similar to what s in the Raytracer Design document: Thus, we suggest that your Raytracer consists of the following: 7

Figure 4: Suggested design Sampler: Generates points in world space by using Bilinear Interpolation across viewport. Define your viewport as 4 points in your scene (aka 4 points in world space), known as LL, LR, UL, UR. Calling sampler.getpoint() returns the next point to raytrace. Raytrace method: Rather than making a class for this, write a method inside main responsible for taking a ray and returning a color. This method will check for intersections of the ray with objects in the scene. This method will calculate shading for object which was intersected. Scene and Gemoetry: The Scene will store all the geometry in the world, and expose a method to do intersection tests on them. For now, store geometry (so-called primitives) in a vector on this object. Support the primitive = intersect(ray) method Geometry / Spheres: Spheres are characterized by a center and a radius. Store these as a vec4 and a float. (We ;; be using homogeneous coordinates.) Write a Primitive class that supports the intersect(ray) method. Make Circle a subclass. Render method: Since something needs to wire this process together, write a Render method that gets points from the sampler, traces these points, and saves the pixels to the Film class. This is also the main method that we will call to redraw the scene if we change something. IMPORTANT: We have supplied classes for Color, Ray, Sampled Point and Material in algebra3.h, please use these classes to avoid reinventing the wheel. They define many useful operators. 8