Computer Graphics I. Assignment 3

Similar documents
CS5620 Intro to Computer Graphics

Illumination Models & Shading

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

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

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

Deferred Rendering Due: Wednesday November 15 at 10pm

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

Assignment 2 Ray Tracing

Comp 410/510 Computer Graphics. Spring Shading

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

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

Lighting and Shading

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

Shadows. COMP 575/770 Spring 2013

03 RENDERING PART TWO

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Illumination and Shading

Illumination & Shading

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

Photorealism: Ray Tracing

Shading I Computer Graphics I, Fall 2008

Lecture 15: Shading-I. CITS3003 Graphics & Animation

CPSC 314 LIGHTING AND SHADING

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

CS 4620 Midterm, March 21, 2017

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

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

Pipeline Operations. CS 4620 Lecture 10

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

Interpolation using scanline algorithm

CS 465 Program 5: Ray II

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

Introduction to Computer Graphics 7. Shading

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

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

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

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

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

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

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

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

TSBK03 Screen-Space Ambient Occlusion

Pipeline Operations. CS 4620 Lecture 14

Illumination in Computer Graphics

9. Illumination and Shading

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

Introduction to Ray-tracing Objectives

Ø Sampling Theory" Ø Fourier Analysis Ø Anti-aliasing Ø Supersampling Strategies" Ø The Hall illumination model. Ø Original ray tracing paper

From Graphics to Visualization

Dynamic Ambient Occlusion and Indirect Lighting. Michael Bunnell NVIDIA Corporation

CS 4620 Program 4: Ray II

Reflection and Shading

Computer Graphics. Illumination and Shading

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

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

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

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

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

Shading and Illumination

Shading. Shading = find color values at pixels of screen (when rendering a virtual 3D scene).

Supplement to Lecture 16

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

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

Point based global illumination is now a standard tool for film quality renderers. Since it started out as a real time technique it is only natural

Simple Lighting/Illumination Models

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Shading 1: basics Christian Miller CS Fall 2011

Introduction to Visualization and Computer Graphics

Illumination & Shading: Part 1

CPSC GLOBAL ILLUMINATION

1.6 Rough Surface Scattering Applications Computer Graphic Shading and Rendering

Illumination & Shading I

Raytracing CS148 AS3. Due :59pm PDT

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Ray Tracing COMP575/COMP770

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

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

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

CS 4620 Program 3: Pipeline

Virtual Reality for Human Computer Interaction

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

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

Local vs. Global Illumination & Radiosity

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

Graphics for VEs. Ruth Aylett

CS 325 Computer Graphics

Sung-Eui Yoon ( 윤성의 )

CS452/552; EE465/505. Intro to Lighting

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

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

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

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

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

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

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

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

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

Ray Tracing. Kjetil Babington

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

Ray Tracing. Brian Curless CSEP 557 Fall 2016

Transcription:

UNIVERSITÄT DES SAARLANDES Dr.-Ing. Hendrik P.A. Lensch Max Planck Institut Informatik Art Tevs (tevs@mpi-inf.mpg.de) Boris Ajdin (bajdin@mpi-inf.mpg.de) Matthias Hullin (hullin@mpi-inf.mpg.de) 12. November 2007 Computer Graphics I Assignment 3 Submission deadline for the exercises: Monday, 19th November 2007 3.1 Reflection Rays (5 Points) Given a ray R(t) = O+t D which hits a reflective surface at t = t hit. The surface has the geometry normal N at the hit point. Assume that both, the ray direction D and the surface normal N are normalized. a) Compute the ray that has been reflected (assuming a perfect mirror reflection) by the surface. You have to submit the solution for this exercise in written form. 3.2 Front/Back-side of a triangle (5 Points) A triangle has two sides, front-side and back-side, in a 3D space. The normal vector N points away from the front side. Given a ray R(t) = O + t D which hits a triangle and a face normal N of the hit point. a) Find a way of how to determine if the ray hits the face from the front or from the back. You have to submit the solution for this exercise in written form. 3.3 New classes and changed application logic (5 Points) Download the new microtrace-framework from http://www.mpi-inf.mpg.de/departments/d4/teaching/ws2007-2008/cg/microtrace03.zip Study the new framework-code of Shader.hxx, Scene.hxx, Light.hxx, MicroTrace.cxx. There is a new class Scene which handles the complete scene environment (i.e. objects and lights). a) Implement the Scene::Intersect(Ray& ray) method. The method perfroms in the same way as its counterpart in the Object class. However instead of intersecting primitives the nearest intersection with the scene objects has to be found. 3.4 The surface shader concept (10 + 10 Points) A surface-shader is a small program that is assigned to a primitive and is responsible for computing the color of each ray hitting this primitive. For example, a flat shader might just return a constant color for a primitive, whereas another shader might compute more complex effects such as lighting, shadows, or texturing. Each primitive has a pointer Shader *shader in the new framework. The Object class has a method Object::setShader(Shader*). Implement this method in such a way, that applying a shader to the object will apply it to every primitive handled in it. For example, our cow (see assignment 2) could be initialized with cow->setshader(new DebugShader(scene));. This should apply the shader DebugShader to every primitive in the cow model. As we will see later some shaders need access to the scene data (e.g for light or shadow calculations), this is why each shader gets a pointer to the scene objects.

In this exercise, you will add some missing parts of the given basic shader framework to your ray tracer and implement two simple shaders: a) Implement a simple debug shader, which uses the primitive s normal to colorify the ray. (see assignment 2). Proceed as follows: The shader class has a purely virtual function Vec3f Shader::Shade(Ray &ray), which has to be implemented in all derived shaders. Implement the DebugShader::Shade(Ray& ray) method. The method should just return the absolute value of the normal vector (x, y, z) as color values (r, g, b). b) Implement the Shade-method in the eye light shader, which uses the angle between the incoming ray and the surface normal at the hit point to achieve a better impression of the actual primitive s shape. The resulting color should be calculated according to: result = cos θ color where θ is the angle between the primitive surface normal and the ray direction. The shader needs to know some information about the primitive (i.e. the surface normal). Implement the shading function EyeLightShader::Shade(Ray &ray) using ray.hit->getnormal(ray) to retrieve the surface normal of the primitive. With the surface normal the above given formula can be applied. If the test scene specified in MicroTrace.cxx is rendered with these two shaders (i.e. DebugShader and EyeLightShader) the resulting images (result 3.4a.ppm and result 3.4b.ppm) should look like this: 3.5 Vertex Normals (15 Points) Rather than storing a single geometry normal for a triangle, it is often useful to store at each vertex a corresponding vertex normal. The advantage is that if we have a hit point on a triangle, the shading normal can be smoothly interpolated between the vertex normals. If neighboring triangles share the same vertex normals, a smooth appearance can be generated over non-smoothly tessellated geometry. Proceed as follows: a) Extend Scene::ParseOBJ to also support vertex normals. Take a look at the included.obj files. (5 Points) b) Your ray class is extended with two additional float values Ray::u and Ray::v. In Triangle::Intersect, store the computed barycentric coordinates into Ray::u and Ray::v. Note: From now on we will handle only triangles as primitives. Hence As long as your other classes (e.g. Sphere) don t need local surface coordinates, there is no need to compute them yet. c) In the framework is a new class SmoothTriangle which stores the vertex normals (na, nb and nc) additionally to the original vertex positions. In SmoothTriangle::GetNormal() use the u/v coordinates of the hit-point to interpolate between the vertex normals. (10 Points) Note: Interpolating normalized vectors will not return a normalized vector! Make sure to normalize your interpolated normal! 2

If everything is correct your images (i.e. result 3.5a.ppm and result 3.5b.ppm should look like this: Compare the difference between the regular (exercise 3.4) and the smooth triangles. 3.6 Mirror shader(10 Points) In this exercise you have to implement a mirror shader. Each ray which hits a surface with applied mirror shader has to be reflected according to the exercise 3.1. The reflected ray start the traversal of the scene from the point of reflection. a) Implement the missing parts of MirrorShader.hxx. (10 Points) b) Add new object plane.obj to your scene which already contains the cow model. Apply the mirror shader to the new object. If your shader is implemented correct you should achieve following results: Figure 1: Plane with applied shader: Left EyeLightShader, Right MirrorShader 3.7 Phong Shading and Point Light sources (30 Points) In the last exercise we implemented two simple surface shaders, which do not take light sources into account. A more advanced surface shading concept, the Phong shading model, utilizes light sources to increase the rendering realism and give objects a plastic like appearance. Before we can implement the Shade method in PhongShader.hxx we have to implement a simple light source. a) Implement a point light. Proceed as follows: (10 Points) Study the base class Light.hxx. Each light source which we will derive from it has to implement an Illuminate(Ray &ray, Vec3f &intensity) method. Implement the Illuminate-method of PointLight.hxx. The method should calculate the 1 light intensity based on the quadratic falloff (i.e. t, where t is the distance between light 2 source and surface point), as well as the direction vector from the surface point to the light source. The direction vector will be later used for shadow computations. 3

b) Implement the Phong illumination model (20 Points) The value L r returned by PhongShader::Shade() should be calculated according to: n 1 n 1 L r = k a c a L a + k d c d L l (I l N) + k s c s L l (I l R) ke c a : Ambient color c d : Diffuse color c s : Specular color (use c s = (1, 1, 1)) k a : Ambient coefficient k d : Diffuse coefficient k s : Specular coefficient k e : Exponent (shine parameter) l=0 L a : Ambient radiance (use L a = (1, 1, 1)) L l : Radiance arriving from light source l I l : Direction to light source l N: Shading normal R: Reflected incident ray direction (points away from the surface) n: Number of light sources Add to your existing scene a point light with following parameters: position=vec3f(0.1, 0.03, -0.2) and intensity=vec3f(0.05, 0.05, 0.05). Attach the phong shader to the cow model. The phong shader parameters has to be set up as following: c a = c d = (0.8, 0.7, 0.6), k a = 0, k d = 0.8, k s = 0.4, k e = 12.0. If your shader is implemented correctly you should achieve following results: l=0 Figure 2: Left: cow with EyeLightShader, Right: cow with PhongShader Notes: Sometimes an incident ray may hit the backside of a surface. Then, just turn the shading normal around to face forward. Only consider light sources that illuminate the primitive from its front-side. 4

3.8 Shadows (10 Points) To add more realism to the Phong model we want now to incorporate shadows into it. Proceed as follows: Modify PhongShader::Shade to check for occlusion. Incorporate the distance returned by Scene::Intersect() method, which you have implemented in exercise 3.3. (10 Points) Add a new object into the scene (i.e. wall.obj ) and apply phong shader on it. The parameters of the wall s phong shader are: c a = c d = (0.8, 0.7, 0.6), k a = 0, k d = 1.0, k s = 0.0, k e = 64.0. If everything is implemented correctly your images should look like in Figure 3. Figure 3: Left: without shadows, Right with shadows 3.9 Area Lights* (20 Points) As you have learned in the last exercise, shadows can add important visual information to an image. Until now we have only considered point lights. Point lights create hard shadows because a point light can not be partly occluded and is either blocked or not. To render more realistic shadows we need a more advanced light source. Area Lights are able to produce soft shadows, which are more natural. In this exercise we implement a QuadAreaLight (in QuadAreaLight.hxx) which is defined by a position p and spanning vectors e 1 and e 2. Calculate the normal and the area of the QuadAreaLight in the constructor (5 Points) In each illumination step do place a shadow ray randomly along the light surface area (use frand(), see stdafx.cxx). Compute the illumination similar to the point light but incorporate the area value into your calculations. (15 Points) Add a quad area light to the scene with following parameters: intensity = Vec3f(2.0, 2.0, 2.0) p = (0.1, 0.03, 0.2), e 1 = (0.15, 0.0, 0.0), e 2 = (0.0, 0.15, 0.0) and remove the point light. Render an image with 1000 shadow rays per pixel (drink a coffee, since this takes time ;-) ) If everything is implemented correctly your images should look like this (left 10 shadow rays, right 1000): 5