- May 15, 2020

多伦多大学CSC D18Assignment1 课业解析 题意：打造一个2D的渲染引擎 解析：任务分为两个part和bonus部分。

Part1：A）第一部分是参数形式的几何表达式：1）考查光线l击中物体的p点（发现为n）的情况。a）光线击中一个椭圆时，参数a，b，c的值。b）画出椭圆、光线和法线的图形。c）因为圆是一种特殊的椭圆，写出圆形的方程。d）通过给定入射光线和折射率，计算入射角和折射角的关系。B）推导一个三位图形的切平面

Part2：根据给定的代码框架，实现光线传播算法。需要实现的场景中要包括：一个光源，一组圆形对象。

Bonus Part：1）增加场景中的物体，渲染除更酷的图像。2）实现光线的色散。3）实现彩色物体与光线的交互。 涉及知识点：光线路径算法，参数函数更多可加微信讨论微信号：IT_51zuoyejunpdfF. Estrada, Aug. 2019Assignment due date: Sep. 27th 12:00 (NOON)Hand-in to be submitted at the D18 drop-box (4th ﬂoor IC),code to be submitted on the mathlab server by the above due dateThis assignment can be completed individually, or by a team of 2 studentsStudent Names (Last, First)Student #1:Student #2:Student numbersStudent #1:Student #2:Student UtorIDsStudent #1:Student #2:We hereby afrm that all the solutions we provide, both in writing and in code,for this assignment are our own. We have properly cited and noted anyreference material we used to arrive at this solution, and have not sharedour work with anyone else._______________________________ _____________________________Student 1 signature Student 2 signature(note: 3 marks penalty if any of the above information is missing)CSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light Transport1This assignment is intended to help you master the basic geometric principles we will use forthe rest of the term to build our advanced rendering engine. To that end, you will practice2D geometry, develop an intuition of how 2D parametric lines can be used to represent lightrays, understand how we can represent simple objects and how these interact with ourlight rays, and use simple transformations to build a simple, but accurate renderer for lighttransport in 2D.After completing this assigment, you will have gained the ability to simulate and visualize lightand its interactions with scene components!Learning Objectives – after completing this assignment you should be able to:Manage points and vectors using simple operations such as additions, dot, and cross products.Represent light rays using 2D parametric equations. Represent objects using 2D implicit andparametric forms.Apply afne transformations to points and vectors, and use them to simulate the propagationof light through a simple scene.Determine points of intersection between light rays and simple scene objects (this is the basisof ray tracing, which we will be fully developing soon).Simulate the basic behaviour of light as it interacts with object surfaces: Reﬂection, scattering,and refraction.Explain how simple light sources behave, and the diﬀerence between primary and secondaryillumination.Skills Developed:Thinking in terms of geometry and vectors.Manipulating simple geometric entities algebraically: rays, circles, boxes.Using 2D transformations to implement code that bounces, reﬂects, and refracts light raysaccording to fundamental principles of optics.Understanding and extending code that deals with images, light rays, and objects.Reference material:The Lecture notes up to this point, found on the course website.This handout (be sure to read everything carefully).The comments in the starter code.CSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 20192Part 1 – Written work. Be sure to provide clean, legible derivations and do not omit any steps yourTA may need to understand your work. Use diagrams wherever appropriate.A) 2D – Parametric forms and the geometry of light transport1) A light ray hits an object at a point with surface normala) [3 marks] – If the object is a 2D ellipse,(centered at [cx, cy])Develop an equation in terms of that yields thevalue of at the intersection point between the ray and the ellipse.You should arrange things so your solution is in the form of a 2nd degreeequation, make sure to show what the value of a b, and c are.Test your derivation by fnding the intersection between the ellipseand the ray given byb) [3 marks] – Provide the expressions that yield the components of the normal vectorat the intersection. Test your derivation by computing the normalfor the ellipse and ray in a), and draw a graph with the ellipse, ray,Intersection, and normal vector. If the graph looks wrong, checkyour work.c) [3 marks] – A circle is a special case of an ellipse. Show what the equations in a)and b) reduce to if the ellipse is such that a = b, cx=0, cy=0. Be sureto explicitly represent the radius of the circle!d) The diagram below shows the geometry of refraction. A rayarriving at a surface, is bent from directionWith the angles between the incident and refracted rays beinggiven by Snell’s law:[2 marks] Show how to determine and the angle of refractiongiven , (are the indexes of refraction)[2 marks] Show and explain with a diagram how to obtain vectorusing and simple 2D rotations.Test your procedure by computing the refraction directiongiven( Attach any work for this part immediately after this page)CSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 20193B) Parametric surfaces, surface geometry, and transformsHere, you will analyze the surface shape of a parametric 3D surface you mayhave heard of before: The Mobius strip. The goal is to identify tangent planes andnormal directions at arbitrary points on the surface – this would be required to renderthe strip in any 3D software.The surface of a Mobius strip with width w is given by:(http://mathworld.wolfram.com/MoebiusStrip.html)Where R is a constant, and represents the distance from the origin to the centerline of the Mobius strip, s is a parameter in [-w, w], and t is a parameter in [0, 2*Pi].Plotting points for a range of values of s and t yields the familiar shape of the Mobiusstrip:a) [2 marks] Derive the equations for the tangent plane at any point (s,t) on thesurface. This is a parametric surface so we expect the tangent planeas a parametric plane defned by two vectors spanning the plane.b) [2 marks] Determine the implicit equation for the tangent plane. This willrequite you to fgure out the normal to the plane.c) [3 marks] The Mobius strip above is centered at the origin, and its axis is thez axis (shown as a red line above, the strip wraps around it). Supposewe need to render a Mobius strip whose centerpoint is atand whose axis is aligned with .Determine the sequence of transformations that takes pointson the Mobius strip above and produces the desiredtransfomed strip. For rotations, show the rotation matrix andshow how the angle of rotation is computed. The transformsequence must be shown in the correct order.CSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 20194Part 2 – Understanding how light works, 2D light transportYour task for this assignment is to implement the core components of a light-propagationAlgorithm. The task of the algorithm is fairly simple:Given a scene consisting ofa) 1 light source (which has a known position, colour, and type)b) A set of objects (which in this case are circles, with known position and material type)The program will:1) Emit a light ray from the light source2) Propagate the ray through the scene until it hits an object (or one of the 4 walls thatmake up the image boundary)3) It then will bounce the ray in a physically consistent way, depending on the materialthe object the ray hit is made ofThe starter code provides most of the nuts and bolts you need to implement the interestingbits, so you will focus on the geometric issues involved with the steps described above, and writea little (but not a lot!) of code. Then you can sit back and watch your program trace light arounda scene you created!Pattern of light resulting from a point light source(at the center of the image) and a set of refractingspheresCSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 20195Part 2 – Understanding how light works, 2D light transport (cont.)Step 1) Download and uncompress the starter code into a suitable directory. Take time now tocompile and run it – learn what the command line arguments do, and how to use theprogram. Of course, at this point it won’t be able to trace light, but it will show you abox of the size you specifed, and the outlines of the objects defned for the scene.Step 2) Read all the header fles included with the starter code – I am providing you with alot of functionality, so you should know what is already there for you to use, and notwaste time implementing functions I’m providing. You will also get a picture of how thecode is structured, and what parts you need to implement.Step 3) Read CAREFULLY the comments in rays2D.c – this is the fle you will be working on,and it has a couple of functions you must implement. The code has comments thatwill help you understand what you need to do.Once you’re done reading these comments, take a short break, then comeback and read them again to make sure you didn’t miss anything.Step 4) Implement your solution. There are of course many ways to go about doing this, butI would suggest starting with casting rays from simple ‘laser’ light sources, andintersections between rays and walls.That gives you a basic framework on which to build the rest. The starter code willtell you what needs to be implemented. Test everything thoroughly, and formore than one case – your code will be auto-tested, so make sure it does theright thing on diﬀerent scenes.For testing:- 1 or 2 samples, and recursion depth of 1 or 2 so you can check the basicgeometry is correct.- Once you have the fundamental components working, increase sampling andrecursion depth to check the process works to check the scene is renderedas expected.Of course, you should have a good idea what the sceneShould look like given the light sourceAnd the objects in itCSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 20196Part 2 – Understanding how light works, 2D light transport (cont.)Notes: You are expected to use 2D rotations to generate the vector directions you need. Thismeans your code needs to compute the relevant angles, determine suitable centers ofrotation (and points to rotate), and then do the rotation to obtain whatever vectordirections you need. Remember:Step 5) Pack your code for submission:- Complete ‘autotester_id.txt’ so the auto-tester knows who you are.Compress your code into a single compressed .tgz fle namedlight2D_studentNo1_studentNo2.tgz (e.g. light2D_11223344_55667788.tgz)The tar command syntax is:>tar -cvzf name_of_your_compressed_tar_file.tgz *.c *.h autotester_id.txtThen submit the compressed fle>submit -c cscd18f19 -a A1 -f name_of_your_compressed_tar_file.tgzDouble check that your compressed fle uncompresses properly, and that it containsall the code as well as the ‘autotester_id.txt’ fle.For reflection, the sign of the angle dependson whether the normal is to the left or tothe right of the incoming rayFor refraction, be careful to account for thedirections of the different vectors which dependon whether the ray is arriving at, or leavingan objectMarking SchemeWritten problems 20 marksWorking code 30 marks (auto-tested)Crunchy bonus Up to you!CSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 20197Part 2 – Understanding how light works, 2D light transport (cont.)Get Crunchy!Of course, once you have a working 2D light transport engine, you want to use it to rendervery cool images. For bonus marks, you can extend your renderer to:[up to 10 marks] – Render a very cool scene (it should not be a clone of the one in this handout)Spend some time placing objects with suitable materials around, and renderthe scene at a reasonably good resolution, for lots of samples.[10 marks] – Implement dispersion. White light is a mixture of light across all visible wavelengths.Refracting objects bend light by diﬀerent amounts depending on the wavelength,and we expect them to spread out the diﬀerent colour components in white light(creating rainbows).Modify your code to handle this by cleverly using sampling, and by manipulating theindex of refraction of the material depending on light wavelength.Dispersion of light by refracting materials[5 marks] – Implement spectral power distributionsfor lightsources. Implement proper lightsources whose colour comes from a specifcmixture of wavelengths at diﬀerent amounts,and have your light source emit rays thatfollow this specifc mixture’s distribution.[5 marks] – Implement coloured objects. Until now, all objects are ‘white’ in that they do not inany way change the colour of the light bounced by, or transmitted through them.modify your code so that it accounts for coloured objects.Scene rendered with a white lightsource and colourRefracting spheres.Drop by and talk with me if you want to workOn any of these features but need a hint ortwo, or if you have other crunchy ideas toTry.Have Fun!Submitting crunchy stuﬀ: Include a renderedscene with your compressed submitted fle, as wellas a ‘crunchy.txt’ describing what you did!CSC D18 – Fall 2019Assignment 1 – Basic Geometry and 2D Light TransportF. Estrada, Aug. 2019