Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUBMISSION: Ratchpak (Dome) Pongmongkol #15

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 26 additions & 177 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,189 +1,38 @@
# [CIS565 2015F] YOUR TITLE HERE

**GLSL Ray Marching**
# GLSL Ray Marching

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 5**

* (TODO) YOUR NAME HERE
* Tested on: (TODO) **Google Chrome 222.2** on
Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Ratchpak (Dome) Pongmongkol
* Tested on: **Google Chrome 46.0.2490.71 (64-bit)** on
OSX El Capitan, 2.4 GHz Intel Core i7, 16 GB 1600 MHz DDR3, NVIDIA GeForce GT 650M 1024 MB (rMBP 15" 2013)

### Live on Shadertoy (TODO)
### Live on Shadertoy

[![](img/thumb.png)](https://www.shadertoy.com/view/TODO)
<a href="https://www.shadertoy.com/view/MtSXRt"><img src=img/src.png width=50%/></a>

### Acknowledgements

This Shadertoy uses material from the following resources:

* TODO

### (TODO: Your README)


Instructions (delete me)
========================

This is due at midnight on the evening of Monday, October 19.

**Summary:** In this project, you'll see yet another way in which GPU
parallelism and compute-efficiency can be used to render scenes.
You'll write a program in the popular online shader editor
[Shadertoy](http://www.shadertoy.com/).
Your goal will be to implement and show off different features in a cool and
interesting demo. See Shadertoy for inspiration - and get creative!

Ray marching is an iterative ray casting method in which objects are
represented as implicit surfaces defined by signed distance functions (SDFs). This
method is widely used in the Shadertoy community to render complex scenes which
are defined in the fragment shader code executed for each pixel.

**Important Notes:**
* Even though you will be coding in Shadertoy, it is important as always to
save versions of your code so that you do not lose progress! Commit often!
* A significant portion of this project will be in write-up and performance
analysis - don't save it for later.

**Provided Code:**
The provided code in `raymarch.glsl` is straight from iq's Raymarching
Primitives; see {iq-prim}. It just sets up a simple starter camera.
* http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf
* http://www2.compute.dtu.dk/pubdb/views/edoc_download.php/6392/pdf/imm6392.pdf
* https://github.com/dsheets/gloc/blob/master/stdlib/matrix.glsl

### Features

All features must be visible in your final demo for full credit.

**Required Features:**

* Two ray marching methods (comparative analysis required)
* Naive ray marching (fixed step size) {McGuire 4}
* Sphere tracing (step size varies based on signed distance field) {McGuire 6}
* 3 different distance estimators {McGuire 7} {iq-prim}
* With normal computation {McGuire 8}
* One simple lighting computation (e.g. Lambert or Blinn-Phong).
* Union operator {McGuire 11.1}
* Necessary for rendering multiple objects
* Transformation operator {McGuire 11.5}
* Debug views (preferably easily toggleable, e.g. with `#define`/`#if`)
* Distance to surface for each pixel
* Number of ray march iterations used for each pixel

**Extra Features:**

You must do at least 10 points worth of extra features.

* (0.25pt each, up to 1pt) Other basic distance estimators/operations {McGuire 7/11}
* Advanced distance estimators
* (3pts) Height-mapped terrain rendering {iq-terr}
* (3pts) Fractal rendering (e.g. Menger sponge or Mandelbulb {McGuire 13.1})
* **Note** that these require naive ray marching, if there is no definable
SDF. They may be optimized using bounding spheres (see below).
* Lighting effects
* (3pts) Soft shadowing using secondary rays {iq-prim} {iq-rwwtt p55}
* (3pts) Ambient occlusion (see 565 slides for another reference) {iq-prim}
* Optimizations (comparative analysis required!)
* (3pts) Over-relaxation method of sphere tracing {McGuire 12.1}
* (2pts) Analytical bounding spheres on objects in the scene {McGuire 12.2/12.3}
* (1pts) Analytical infinite planes {McGuire 12.3}

This extra feature list is not comprehensive. If you have a particular idea
that you would like to implement, please **contact us first** (preferably on
the mailing list).

## Write-up

For each feature (required or extra), include a screenshot which clearly
shows that feature in action. Briefly describe the feature and mention which
reference(s) you used.

### Analysis

* Provide an analysis comparing naive ray marching with sphere tracing
* In addition to FPS, implement a debug view which shows the "most expensive"
fragments by number of iterations required for each pixel. Compare these.
* Compare time spent ray marching vs. time spent shading/lighting
* This can be done by taking measurements with different parts of your code
enabled (e.g. raymarching, raymarching+shadow, raymarching+shadow+AO).
* Plot this analysis using pie charts or a 100% stacked bar chart.
* For each feature (required or extra), estimate whether branch divergence
plays a role in its performance characteristics, and, if so, point out the
branch in question.
(Like in CUDA, if threads diverge within a warp, performance takes a hit.)
* For each optimization feature, compare performance with and without the
optimization. Describe and demo the types of scenes which benefit from the
optimization.

**Tips:**

* To avoid computing frame times given FPS, you can use the
[stats.js bookmarklet](https://github.com/mrdoob/stats.js/#bookmarklet)
to measure frame times in ms.

### Resources

You **must** acknowledge any resources you use, including, but not limited to,
the links below. **Do not copy non-trivial code verbatim.** Instead, use the
references to understand the methods.

For any code/material in the 565
[slides](http://cis565-fall-2015.github.io/lectures/12-Ray-Marching.pptx),
please reference the source found at the bottom of the slide.

* {McGuire}
Morgan McGuire, Williams College.
*Numerical Methods for Ray Tracing Implicitly Defined Surfaces* (2014).
[PDF](http://graphics.cs.williams.edu/courses/cs371/f14/reading/implicit.pdf)
* You may credit and use code from this reference.
* {iq-prim}
Iñigo Quílez.
*Raymarching Primitives* (2013).
[Shadertoy](https://www.shadertoy.com/view/Xds3zN)
* {iq-terr}
Iñigo Quílez.
*Terrain Raymarching* (2007).
[Article](http://www.iquilezles.org/www/articles/terrainmarching/terrainmarching.htm)
* You may credit and use code from this reference.
* {iq-rwwtt}
Iñigo Quílez.
*Rendering Worlds with Two Triangles with raytracing on the GPU* (2008).
[Slides](http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf)
* {Ashima}
Ashima Arts, Ian McEwan, Stefan Gustavson.
*webgl-noise*.
[GitHub](https://github.com/ashima/webgl-noise)
* You may use this code under the MIT-expat license.


## Submit

### Post on Shadertoy

Post your shader on Shadertoy (preferably *public*; *draft* will not work).
For your title, come up with your own demo title and use the format
`[CIS565 2015F] YOUR TITLE HERE` (also add this to the top of your README).

In the Shadertoy description, include the following:

* A link to your GitHub repository with the Shadertoy code.
* **IMPORTANT:** A copy of the *Acknowledgements* section from above.
* Remember, this is public - strangers will want to know where you got your
material.

Add a screenshot of your result to `img/thumb.png`
(right click rendering -> Save Image As), and put the link to your
Shadertoy at the top of your README.

### Pull Request

**Even though your code is on Shadertoy, make sure it is also on GitHub!**

1. Open a GitHub pull request so that we can see that you have finished.
The title should be "Submission: YOUR NAME".
* **ADDITIONALLY:**
In the body of the pull request, include a link to your repository.
2. Send an email to the TA (gmail: kainino1+cis565@) with:
* **Subject**: in the form of `[CIS565] Project N: PENNKEY`.
* Direct link to your pull request on GitHub.
* Estimate the amount of time you spent on the project.
* If there were any outstanding problems, or if you did any extra
work, *briefly* explain.
* Feedback on the project itself, if any.
- Soft Shadow
- Ambient Occlusion
- Naive ray marching (fixed step size) & Sphere tracing (step size varies based on signed distance field)
- Over-relaxation method of sphere tracing
- 7 distance estimators.
- Blinn phong lighting
- Union Operator
- Transformation Operator
- Debug Views

## Performance Analysis
###Fixed step size Vs Sphere tracing
<img src=img/Fixed.png width=50%/><img src=img/Adaptive.png width=50%/>
These images are displayed in debug mode to display the number of iterations, from white (requires less iterations) to black (requires more iterations). It is noticable that with fixed step size (Left), the screen is mostly black-gray, meaning it requires more iteration to reach the object. Meanwhile, even sphere tracing requires less iteration, it is noticable that the algorithm is expensive around the edges of the object.

#### Over-relaxation method
Unexpectedly, over-relaxation (with k = 1.2) does not speed up the program much (The different is around 2-5 fps, from 30 fps). I suspect that this is due to the branch divergence that is caused by its condition checking.
Binary file added img/Adaptive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Fixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/src.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading