Computer Graphics Tick 2

Similar documents
Computer Graphics Tick 1

Shadows. COMP 575/770 Spring 2013

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

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

Photorealism: Ray Tracing

Lecture 18: Primer on Ray Tracing Techniques

Ray Tracing. Kjetil Babington

Lecture 17: Recursive Ray Tracing. Where is the way where light dwelleth? Job 38:19

Assignment 2 Ray Tracing

Ray tracing Tutorial. Lukas Herzberger

Ray Tracing COMP575/COMP770

Global Illumination. COMP 575/770 Spring 2013

Project 1 Simple Ray Tracer

Introduction to Ray-tracing Objectives

Ray-Tracing. Misha Kazhdan

SAMPLING AND NOISE. Increasing the number of samples per pixel gives an anti-aliased image which better represents the actual scene.

Assignment 6: Ray Tracing

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

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

Lighting and Shading

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

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

MITOCW MIT6_172_F10_lec18_300k-mp4

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

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

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

Computer Graphics I. Assignment 3

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

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

Global Rendering. Ingela Nyström 1. Effects needed for realism. The Rendering Equation. Local vs global rendering. Light-material interaction

Lecture 10: Ray tracing

Raytracing CS148 AS3. Due :59pm PDT

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

CS Simple Raytracer for students new to Rendering

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

CS 6958 LECTURE 5 TM ANALYSIS SHADING

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

COMP371 COMPUTER GRAPHICS

Topics and things to know about them:

Agenda. Ray(tracing(algorithm( Code(structure( Ray(intersec;ons Sphere Triangle Hints Transforma;ons Debugging How(to(start

Ray Tracing. CS116B Chris Pollett Apr 20, 2004.

Render methods, Compositing, Post-process and NPR in NX Render

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

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

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

Computer Graphics. Shadows

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

CS 184: Assignment 4 Simple Raytracer

To Shading and Beyond. CS 6965 Fall 2011

CS 465 Program 5: Ray II

Ray Tracer Due date: April 27, 2011

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

Lecture 11: Ray tracing (cont.)

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

COMPUTER GRAPHICS AND INTERACTION

CS 325 Computer Graphics

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

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

Computer Graphics. Lecture 10. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura 12/03/15

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

Consider a partially transparent object that is illuminated with two lights, one visible from each side of the object. Start with a ray from the eye

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Ray Tracing Detail, Part 3

Chapter 11. Caustics and Global Illumination

COS 116 The Computational Universe Laboratory 10: Computer Graphics

lecture 19 Shadows - ray tracing - shadow mapping - ambient occlusion Interreflections

CEng 477 Introduction to Computer Graphics Fall 2007

Photorealistic 3D Rendering for VW in Mobile Devices

Advanced Shading I: Shadow Rasterization Techniques

RAYTRACING. Christopher Peters INTRODUCTION TO COMPUTER GRAPHICS AND INTERACTION. HPCViz, KTH Royal Institute of Technology, Sweden

Viewing and Ray Tracing. CS 4620 Lecture 4

A Little Background. Motivation. Motivation

Deferred Rendering Due: Wednesday November 15 at 10pm

CS Computer Graphics: Ray Tracing Detail, Part 3

03 RENDERING PART TWO

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

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examinations (Semester 2) COMP4610/COMP6461 (Computer Graphics) Final Exam

Viewing and Ray Tracing

Ray Cast Geometry. RayCast Node for Motion, Displacements and Instancing. New to The Ray Cast Geometry node has received an upgrade for 2018.

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

Practical 2: Ray Tracing

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

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

TDA361/DIT220 Computer Graphics, January 15 th 2016

4) Finish the spline here. To complete the spline, double click the last point or select the spline tool again.

CS 428: Fall Introduction to. Raytracing. Andrew Nealen, Rutgers, /18/2009 1

Overview: Ray Tracing & The Perspective Projection Pipeline

CS 4620 Program 4: Ray II

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Ray Tracing. CS 4620 Lecture 5

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

CS5620 Intro to Computer Graphics

Interactive Real-Time Raycasting

CS 488. More Shading and Illumination. Luc RENAMBOT

Recall: Basic Ray Tracer

Volume Illumination. Visualisation Lecture 11. Taku Komura. Institute for Perception, Action & Behaviour School of Informatics

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

Today. Anti-aliasing Surface Parametrization Soft Shadows Global Illumination. Exercise 2. Path Tracing Radiosity

Transcription:

Computer Graphics Tick 2 Advanced Ray Tracing Effects Figure 1: The image you will create in this exercise. 1 Introduction In this exercise you will extend the ray tracer to handle a new shape and additional effects. The new shape you will render is a plane with which you can represent the ground. The additional effects you will implement are multiple light sources, hard shadows, and reflective surfaces. 1

2 Getting started Download archive tick2.zip from Moodle area Tick 2. After extracting you will see the following files: tick2 gfx/tick2 Camera.java Plane.java PointLight.java Ray.java RaycastHit.java Renderer.java Scene.java SceneLoader.java SceneObject.java Sphere.java Tick2.java Vector3.java tick2.xml The files you will modify and submit for this exercise have been highlighted. You will modify Plane.java to implement ray-plane intersection, and you will modify Renderer.java to shade with multiple lights, shadows, and reflections. Tick2.java contains the main method. Along with the --input and --output arguments from the last tick, it can also take a --bounces argument that specifies the number of times rays can bounce when calculating reflections. 3 Intersecting with planes We often want to render planes in graphics as they can simulate the ground or walls in a scene. The Tick 2 scene file tick2.xml now can contain plane elements specified like so: <plane x="0.0" y="0" z="2" nx="1" ny="0" nz="0" colour="#222222"/> Where the plane is specified by a point (x, y, z) and normal vector (n x, n y, n z ). 2

Your task is to implement Plane.intersectionWith() so we can render planes as well as spheres. Ray-plane intersection formula Given: A ray defined as P (s) = O + sd. A plane defined as (P Q) N = 0, where N is the normal to the plane, Q is a point on the plane and is a dot product. We can find where the ray intersects the plane by plugging the ray equation into the plane equation, and solving for resulting ray parameter s. (O + sd Q) N = 0 s = (Q O) N D N If s < 0, the plane is behind the ray origin so there is no intersection. Ray-plane intersection code The current ray-intersection code in Plane.java looks like this: public RaycastHit intersectionwith(ray ray) { Vector3 O = ray.getorigin(); Vector3 D = ray.getdirection(); Vector3 Q = this.point; Vector3 N = this.normal; TODO: Calculate ray parameter s at intersection TODO: If s < 0, return empty RaycastHit, otherwise return RaycastHit describing point of intersection return new RaycastHit(); Your task is to modify this code to calculate ray parameter s. If s is not negative, return a RaycastHit corresponding to the point of intersection: return new RaycastHit(this, s, ray.evaluate(s), N); Your renderer should now be able to render planes. 3

Ambient light only One point light Two point lights Figure 2: The effect of multiple lights: here is the Tick 2 scene shaded with zero, one, and two point light sources (from left to right). 4 Multiple light sources In the previous exercise, scenes contained only a single point light. In graphics, we want to simulate multiple light sources. Figure 2 shows the Tick 2 scene shaded with varying numbers of lights (without shadows for now). To handle multiple lights we modify the equation for calculating pixel s colour to sum over a set of n lights: n n P = C diff I a + C diff k d I i max(0, N L i ) + C spec k s I i max(0, R i V ) n {{{{{{ i=0 i=0 Ambient Diffuse Specular I i, L i, and R i are the intensity, light vector, and reflection vector for the i th light source. Like before, we have a single ambient light term. However, we now sum over lights in a scene, adding the contribution of each light source to the pixel P. We do this because light is additive. 4

Implementing multiple light sources You will modify Renderer.illuminate() to add a diffuse and specular component for each light source. private Vector3 illuminate(scene scene, SceneObject object, Vector3 P, Vector3 N) { Vector3 colourtoreturn = new Vector3(0);... // Add ambient light term to start with colourtoreturn = colourtoreturn.add(i_a.scale(c_diff)); // Loop over each point light source List<PointLight> pointlights = scene.getpointlights(); for (int i = 0; i < pointlights.size(); i++) { PointLight light = pointlights.get(i); double distancetolight = light.getposition().subtract(p). magnitude(); Vector3 I = light.getilluminationat(distancetolight); TODO: Calculate L, V, R, NdotL, and RdotV TODO: Calculate diffuse and specular terms TODO: Add diffuse and specular terms to colourtoreturn return colourtoreturn; The loop over the light sources in the scene has already been implemented for you. Your task is to compute diffuse and specular illumination terms for each light in the same way you did for Tick 1, and accumulate them in the colourtoreturn variable. 5 Shadows Shadows are an important visual cue so we can tell where objects are in relation to each other. Implementing shadows in a ray tracer is simple: when calculating the illumination of a point by a certain light source, we must first check if that 5

(a) Shadows cast by light 1 (b) Shadows cast by light 2 (c) The scene with shadows Figure 3: The black pixels in (3a) and (3b) correspond to pixels in shadow for the corresponding light source. (3c) shows how shadows provide an important visual cue: we can now see the spheres and plane are touching. point can see the light source. If it cannot, then we do not accumulate that light s diffuse and specular contributions for that point. 5.1 Implementing shadows You will modify Renderer.illuminate() once more to consider shadows before adding the diffuse and specular component for each light source. private Vector3 illuminate(scene scene, SceneObject object, Vector3 P, Vector3 N) {... for (int i = 0; i < pointlights.size(); i++) { FROM BEFORE: Calculate diffuse and specular terms // Check if point P is in shadow from that light or not Ray shadowray = new Ray(P.add(L.scale(EPSILON)), L); boolean inshadow = false; TODO: Cast the shadowray with findclosestintersection to determine if P is in shadow or not, and set inshadow TODO: if not inshadow, add diffuse and specular to colourtoreturn return colourtoreturn; 6

No reflection One reflection bounce Two reflection bounces Figure 4: We can render reflections by bouncing our traced rays off objects in the scene. To ensure our renderer terminates, we must limit the number of times a ray can bounce. Here is the scene with 0, 1, and 2 bounces. The idea is to only add the contribution for the ith light source to colourtoreturn if the path from P to that light source is clear. This is determined by casting a shadow ray from P towards the light source. If the shadow ray hits any object before reaching the light, then point P is in shadow. Otherwise, point P is directly illuminated by the light. Note the shadow ray has already been created for you. Its starting position has been slightly adjusted by a small bias factor EPSILON. This prevents the shadow ray immediately intersecting the same object it started from. For each point light source, implement the following: 1. Cast the shadow ray using scene.findclosestintersection(shadowray) to get a RaycastHit object. 2. If the RaycastHit s distance is less than the distance to the point light, set inshadow to true. 3. If inshadow is false, add the diffuse and specular terms for that light source to colourtoreturn, otherwise do nothing. Your renderer should now render shadows cast by the spheres onto the plane and each other. The output should look like Figure 3c. 7

6 Reflection Aside from shadows, another effect that is easy to implement in ray tracing is reflection. Figure 4 shows the result of adding reflections to our scene. Your final task is to implement reflection using recursion in Renderer.trace(). Currently, the trace() method returns the direct illumination at a point P. To render reflection, we additionally calculate the reflected illumination by bouncing the traced ray off the surface. Implementing reflection You can see the Renderer.trace() method now includes a parameter bouncesleft. bouncesleft corresponds to the number of times the ray will bounce before returning the direct illumination. protected Vector3 trace(scene scene, Ray ray, int bouncesleft) {... // Calculate direct illumination at that point Vector3 directillum = this.illuminate(scene, object, P, N); double reflectivity = object.getreflectivity() // If no bounces or reflection, return direct illumination if (bouncesleft == 0 reflectivity == 0) { return directillum; else { TODO: Calculate the direction R of the bounced ray TODO: Spawn a reflectedray with bias TODO: Calculate reflectedillum by tracing reflectedray // Scale direct and reflective illum. to conserve light directillum = directillum.scale(1.0 - reflectivity); reflectedillum = reflectedillum.scale(reflectivity); return directillum.add(reflectedillum); The direct illumination at P (directillum) is calculated using Renderer.illuminate(). 8

For reflection you must implement the following: 1. Calculate the direction of the bounced ray R by reflecting the original ray s direction D in N. Remember, Vector3.reflectIn() computes a mirrorlike reflection, so you should negate D before reflecting it. Make sure R and N are unit vectors. 2. Spawn a new ray reflectedray with origin (P + ɛr) and direction R. Make sure to adjust the origin by bias ɛ to prevent immediate self-intersection. 3. Calculate the reflected illumination colour using trace(scene, reflectedray, bouncesleft-1). We decrement bouncesleft to make sure rays don t bounce around the scene forever. Your renderer should now produce the same image as Figure 1. Next time you ll explore rasterization: an alternative approach for rendering images that is faster than ray tracing, but less realistic. 7 Submission The instruction for this submission is identical as for Tick 1. Once you re happy with your tick s output, go to Moodle Tick 2 Tick 2 Submission, switch to Submission tab, drag and drop two files: Plane.java and Renderer.java and click Submit. There is no need to put anything in the Comments field. Then, you can switch to the tab Submission view and hit Evaluate. If your code generates correct results, you should see the message Congratulations! Your code passed the tester.. Note that this is a provisional mark and you may still need to have and interview to get credit for your tick. If your code does not compile or fails to produce correct results, you will see an error message or a report from running the tests. Your code will be tested on the sample scene bundled in the zip file (tick2.xml) and one addition test scene that is kept hidden. The tester will award a full mark only when correct images are produced for both scenes. Note that you can use Edit tab to make small changes to your code and run evaluation again. But do not use this option for debugging or completing a larger portion of work. Note that you cannot see images generated by your program when you click Evaluate link. There is a small chance that your program generates correct results but the tester reports it fails the tests. If you have checked your code thoroughly and suspect that this could be the problem with the tester, please let us know on Help forum for Graphics 1a in Moodle or by e-mail rkm38@cam.ac.uk. Please do not post your code on the open forum. If your code works correctly, you will be awarded a full mark in the ticking session. 9