程序代写 COMP4610/6461 Lectures Labs Assignments Resources News

COMP4610/6461 Lectures Labs Assignments Resources News
Home / Labs / Lab 5
The fifth labs.
In this lab, you will extend a simple ray tracing program. This should help you understand what is involved in ray tracing. Also, this lab aims to reinforce your understanding of illumination models.

Copyright By PowCoder代写 加微信 powcoder

The program you are given only does ray casting onto spheres, and it is a very simple and short program. A lot of the code is dedicated to setting up the juggler and animation. Have a careful read through the code to understand how it is working. In particular, look at and understand the P3D class (as you will need to do some basic calculations with the points using this 3D point class) and Scene class.
The starting code is available here. When run, the frames are ray cast into a sequence of images. Once this is done, the sequence is animated.
Your solution to each task should build on the others, e.g. the features implemented in task-1 should also be in your task-3 solution. Solutions to each task will require editing multiple files. For this reason, you will need to supply a single program that is capable of generating the output for each of the three tasks. We have set up the project such that the RayTracer object is supplied with a command line argument, which is an integer called mode. When supplied with a mode of ‘1’, your program should output task 1, and when supplied with ‘2’ it should output task 2 etc.
Task 1 – Lighting
Modify the raytrace method in Scene.java (and others if needed) such that it implements the (Blinn) Phong illumination model, including ambient, diffuse and specular reflection from a single light source (which you will need to create). You should adjust lighting parameters such that both the diffuse and specular effects are viewable.
I placed my light source at:
P3D lightpos = new P3D(25.0,30.0,-40.0);
(you are welcome to place it at a different place, it is just that this looks okay given the
juggler/viewer locations)
Note, you do not need to trace rays to the light sources in this part of the lab. Hence you should not see shadows.
You may use either the Phong or Blinn-Phong specular reflection model. The background should be black.
Task 2 – Reflections and Shadows
Add two large mirror spheres to the scene. Let these mirrors act as perfect reflectors. Enable rays to reflect off these mirrors a number of times (I used a max bounce of 10).
In my scene I placed them within “makeScene” using the code:
res.add(m = new Sphere(new P3D(-14.35, 7.35, 2.0), 11.0, Color.black));
m.material.reflection = 1.0;
res.add(m = new Sphere(new P3D(14.35, 7.35, 2.0), 11.0, Color.black));
m.material.reflection = 1.0;
The spheres should include both reflections and specular highlights (but not diffuse or ambient lighting).
[Oct-14] Minor correction: In our example image, the mirrored spheres are rendered using only reflections and not specular highlights. Either solution (reflections+specular or just reflections) is acceptable for this task.
Create an infinite plane parallel with the x-z plain (this can simplify the maths a little), this should pass through the point (0.0, −5.85, 0.0).
You must also trace the rays to the light source, this should effect your illumination model and create shadows (points in shadow receive ambient light, but not diffuse or specular).
Add a blue sky (this is the colour to be used when a ray does not hit anything). Your solution should look similar the one below.
Task 3 – Texturing
Add a rectangular quad with the Computer Graphics logo on it (provided under textures). The quad is parallel with the x-y plain (this can simplify the maths a little). The quad should be 4- units wide by 4-units high, and centered at (0, 2, −2).
Add a checkerboard pattern to the floor where checkers are 1 unit square, make the squares black and white.
Once everything is working, your solution should look like this:
Bonus Task
Add a global illumination lighting model.
This is easier than you might think. The image below was generated using a simple GI lighting model. To create this effect, I replaced the Phong lighting model with two raytraces. One sampled randomly from the surface hemisphere, and one reflected off the surface with a small perturbation. Each of these rays recursively calculates its own lighting. I then dot the diffuse light with the surface normal, add it to the specular light, and add any emissive material colour. To stop infinite recursion, I limit the bounces to 10. In this image, the whole scene is lit by the two emissive globes.
This approach is often referred to as Monte-Carlo sampling and produces very noisy results. For this reason, I sampled each pixel 8,192 times. I also trace rays from a random point within the pixel’s area which effectively produces super sampled images.
The image below took approximately 3-hours to render on a single CPU core.
Note: I probably should have either randomly traced a diffuse ray or a specular ray but not both. Why is this? Also, which ray should be traced more often, the specular or the diffuse? A better solution would be to drop the diffuse/specular distinction and instead sample from a BRDF.
This solution also implements a few other nice features
I use a single sample to generate an initial image. This was useful for setting up the scene, as the first trace is almost instant. I then produce a second image using sqrt(n) samples. And finally, a third image using all samples.
Soft reflections are implemented by perturbing the reflected ray’s normal a little. Soft shadows we ‘get for free’. This is because there are no point lights, only emissive surfaces. If a surface patch sees only half the light’s area, it gets only half the light, hence the soft shadows.
All lighting is performed in linear space, then transformed into gamma space at the end. This was important for making the lighting look right.
To sample from a hemisphere from a surface with normal N, I used the following algorithm:
1. Generate a random vector V in the unit cube. 2. IfV.length>1,goto1.
3. If V ⋅ N < 0, then V ← −V 4. NormalizeandoutputV Acknowledgement of Country The Australian National University acknowledges, celebrates and pays our respects to the Ngunnawal and Ngambri people of the Canberra region and to all First Nations Australians on whose traditional lands we meet and work, and whose cultures are among the oldest continuing cultures in human history. Contact ANU Copyright Disclaimer Privacy Freedom of Information The Australian National University, Canberra CRICOS Provider : 00120C ABN : 52 234 063 906 Updated: 18 Oct 2022 | Responsible Officer: Head of School | Page Contact: 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com