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

Nathan D's Robot #11

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
75c8524
Updated repo for publishing
ndevlin Sep 30, 2021
ecffe5c
Added basic raymarching code; got shaders to compile
ndevlin Sep 30, 2021
a23b031
Got sphere rendering
ndevlin Sep 30, 2021
7f5fe0e
Successfully casting rays; not currently fully correct direction
ndevlin Sep 30, 2021
98e9689
Got Ray directions working correctly
ndevlin Sep 30, 2021
50785aa
Added new README
ndevlin Oct 1, 2021
5434cde
Updated README
ndevlin Oct 1, 2021
e3f467d
Got Normals working
ndevlin Oct 1, 2021
f59d325
Corrected Normals
ndevlin Oct 6, 2021
ceabc94
Added Cube to Scene
ndevlin Oct 6, 2021
db22e70
Unioned a Cube and Sphere
ndevlin Oct 6, 2021
adf122c
Very Basic Outline
ndevlin Oct 6, 2021
7e93641
Added Lambert shading
ndevlin Oct 6, 2021
7c83917
Got hard shadow working
ndevlin Oct 6, 2021
6c31b37
Added soft shadows
ndevlin Oct 6, 2021
ba07e07
Got rotation working
ndevlin Oct 6, 2021
e4ac94b
Added capsule
ndevlin Oct 6, 2021
0b04635
Added arms
ndevlin Oct 6, 2021
dbcdd20
Added Torus
ndevlin Oct 6, 2021
f6fb47a
Added Legs
ndevlin Oct 6, 2021
a3f553e
Added Smooth Blend
ndevlin Oct 6, 2021
fd1ff50
Merge remote-tracking branch 'upstream/master' into PullWorkflowUpdates
ndevlin Oct 6, 2021
833fb73
Merge pull request #3 from ndevlin/PullWorkflowUpdates
ndevlin Oct 6, 2021
0bef774
Added reference image
ndevlin Oct 6, 2021
dddff3f
Revert "Merge pull request #3 from ndevlin/PullWorkflowUpdates"
ndevlin Oct 6, 2021
984cad8
Added Antenna Ball
ndevlin Oct 6, 2021
345befb
Modified antenna bouncing
ndevlin Oct 6, 2021
dde4ca5
Added Rounded Face
ndevlin Oct 7, 2021
fc151f1
Added scuba mask
ndevlin Oct 7, 2021
dce546f
Created face animation; Added to README
ndevlin Oct 7, 2021
259629e
Corrected typo in ReadMe
ndevlin Oct 7, 2021
bd98a00
Merge remote-tracking branch 'upstream/master' into PullUpstreamChanges
ndevlin Oct 7, 2021
463ecc4
Merge pull request #5 from ndevlin/PullUpstreamChanges
ndevlin Oct 7, 2021
a6ac1aa
Merge remote-tracking branch 'upstream/master' into PullFromUpstream
ndevlin Oct 12, 2021
57a5f56
Merge pull request #7 from ndevlin/PullFromUpstream
ndevlin Oct 12, 2021
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,3 @@ typings/

# next.js build output
.next

dist/bundle.js
dist/bundle.js.map
81 changes: 81 additions & 0 deletions ProjectSpecifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# CIS 566 Homework 2: Implicit Surfaces

## Objective
- Gain experience with signed distance functions
- Experiment with animation curves

## Base Code

Please feel free to use this code as a base (https://www.shadertoy.com/view/fsdXzM)

The code we have provided for this assignment features the following:
- A square that spans the range [-1, 1] in X and Y that is rendered with a
shader that does not apply a projection matrix to it, thus rendering it as the
entirety of your screen
- TypeScript code just like the code in homework 1 to set up a WebGL framework
- Code that passes certain camera attributes (listed in the next section),
the screen dimensions, and a time counter to the shader program.

## Assignment Requirements
- __(10 points)__ Modify the provided `flat-frag.glsl` to cast rays from a
virtual camera. We have set up uniform variables in your shader that take in
the eye position, reference point position, and up vector of the `Camera` in
the provided TypeScript code, along with a uniform that stores the screen width
and height. Using these uniform variables, and only these uniform variables,
you must write a function that uses the NDC coordinates of the current fragment
(i.e. its fs_Pos value) and projects a ray from that pixel. Refer to the [slides
on ray casting](https://docs.google.com/presentation/d/e/2PACX-1vSN5ntJISgdOXOSNyoHimSVKblnPnL-Nywd6aRPI-XPucX9CeqzIEGTjFTwvmjYUgCglTqgvyP1CpxZ/pub?start=false&loop=false&delayms=60000&slide=id.g27215b64c6_0_107)
from CIS 560 for reference on how to cast a ray without an explicit
view-projection matrix. You'll have to compute your camera's Right vector based
on the provided Up vector, Eye point, and Ref point. You can test your ray
casting function by converting your ray directions to colors using the formula
`color = 0.5 * (dir + vec3(1.0, 1.0, 1.0))`. If your screen looks like the
following image, your rays are being cast correctly:
![](rayDir.png)
- __(70 points)__ Create a scene using raymarched signed distance functions.
The subject of your scene should be based on some reference image, such as a
shot from a movie or a piece of artwork. Your scene should incorporate the
following elements:
- The SDF combination operation Smooth Blend.
- Basic Lambertian reflection using a hard-coded light source and SDF surface normals.
- Animation of at least one element of the scene, with at least two Toolbox Functions
used to control the animation(s).
- Hard-edged shadows cast by shapes in the scene onto one another using a shadow-feeler ray.

For the next assignment you will build upon this scene with procedural textures and more
advanced lighting and reflection models, so don't worry if your scene looks a bit drab
given the requirements listed above.

- __(10 points)__ Following the specifications listed
[here](https://github.com/pjcozzi/Articles/blob/master/CIS565/GitHubRepo/README.md),
create your own README.md, renaming this file to INSTRUCTIONS.md. Don't worry
about discussing runtime optimization for this project. Make sure your
README contains the following information:
- Your name and PennKey
- Citation of any external resources you found helpful when implementing this
assignment.
- A link to your live github.io demo (refer to the pinned Piazza post on
how to make a live demo through github.io)
- An explanation of the techniques you used to model and animate your scene.

## Useful Links
- [IQ's Article on SDFs](http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm)
- [IQ's Article on Smooth Blending](http://www.iquilezles.org/www/articles/smin/smin.htm)
- [IQ's Article on Useful Functions](http://www.iquilezles.org/www/articles/functions/functions.htm)
- [Breakdown of Rendering an SDF Scene](http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf)


## Submission
Commit and push to Github, then submit a link to your commit on Canvas. Remember
to make your own README!

## Inspiration
- [Alien Corridor](https://www.shadertoy.com/view/4slyRs)
- [The Evolution of Motion](https://www.shadertoy.com/view/XlfGzH)
- [Fractal Land](https://www.shadertoy.com/view/XsBXWt)
- [Voxel Edges](https://www.shadertoy.com/view/4dfGzs)
- [Snail](https://www.shadertoy.com/view/ld3Gz2)
- [Cubescape](https://www.shadertoy.com/view/Msl3Rr)
- [Journey Tribute](https://www.shadertoy.com/view/ldlcRf)
- [Stormy Landscape](https://www.shadertoy.com/view/4ts3z2)
- [Generators](https://www.shadertoy.com/view/Xtf3Rn)
90 changes: 20 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,31 @@
# CIS 566 Homework 2: Implicit Surfaces
# RayMarching SDFs

## Objective
- Gain experience with signed distance functions
- Experiment with animation curves
## Nathan Devlin - @ndevlin - ndevlin@seas.upenn.edu - www.ndevlin.com

## Base Code
Result:

Please feel free to use this code as a base (https://www.shadertoy.com/view/fsdXzM)
![](Results.png)

The code we have provided for this assignment features the following:
- A square that spans the range [-1, 1] in X and Y that is rendered with a
shader that does not apply a projection matrix to it, thus rendering it as the
entirety of your screen
- TypeScript code just like the code in homework 1 to set up a WebGL framework
- Code that passes certain camera attributes (listed in the next section),
the screen dimensions, and a time counter to the shader program.
Reference Image:

## Assignment Requirements
- __(10 points)__ Modify the provided `flat-frag.glsl` to cast rays from a
virtual camera. We have set up uniform variables in your shader that take in
the eye position, reference point position, and up vector of the `Camera` in
the provided TypeScript code, along with a uniform that stores the screen width
and height. Using these uniform variables, and only these uniform variables,
you must write a function that uses the NDC coordinates of the current fragment
(i.e. its fs_Pos value) and projects a ray from that pixel. Refer to the [slides
on ray casting](https://docs.google.com/presentation/d/e/2PACX-1vSN5ntJISgdOXOSNyoHimSVKblnPnL-Nywd6aRPI-XPucX9CeqzIEGTjFTwvmjYUgCglTqgvyP1CpxZ/pub?start=false&loop=false&delayms=60000&slide=id.g27215b64c6_0_107)
from CIS 560 for reference on how to cast a ray without an explicit
view-projection matrix. You'll have to compute your camera's Right vector based
on the provided Up vector, Eye point, and Ref point. You can test your ray
casting function by converting your ray directions to colors using the formula
`color = 0.5 * (dir + vec3(1.0, 1.0, 1.0))`. If your screen looks like the
following image, your rays are being cast correctly:
![](rayDir.png)
- __(70 points)__ Create a scene using raymarched signed distance functions.
The subject of your scene should be based on some reference image, such as a
shot from a movie or a piece of artwork. Your scene should incorporate the
following elements:
- The SDF combination operation Smooth Blend.
- Basic Lambertian reflection using a hard-coded light source and SDF surface normals.
- Animation of at least one element of the scene, with at least two Toolbox Functions
used to control the animation(s).
- Hard-edged shadows cast by shapes in the scene onto one another using a shadow-feeler ray.
![](Reference.jpeg)

For the next assignment you will build upon this scene with procedural textures and more
advanced lighting and reflection models, so don't worry if your scene looks a bit drab
given the requirements listed above.
## Live Demo
View a live WebGL Demo here!:
https://ndevlin.github.io/hw02-raymarching-sdfs/

- __(10 points)__ Following the specifications listed
[here](https://github.com/pjcozzi/Articles/blob/master/CIS565/GitHubRepo/README.md),
create your own README.md, renaming this file to INSTRUCTIONS.md. Don't worry
about discussing runtime optimization for this project. Make sure your
README contains the following information:
- Your name and PennKey
- Citation of any external resources you found helpful when implementing this
assignment.
- A link to your live github.io demo (refer to the pinned Piazza post on
how to make a live demo through github.io)
- An explanation of the techniques you used to model and animate your scene.
## Project Description

## Useful Links
- [IQ's Article on SDFs](http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm)
- [IQ's Article on Smooth Blending](http://www.iquilezles.org/www/articles/smin/smin.htm)
- [IQ's Article on Useful Functions](http://www.iquilezles.org/www/articles/functions/functions.htm)
- [Breakdown of Rendering an SDF Scene](http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf)
This project uses Signed Distance Functions (as opposed to explicit geometry) to define a scene. Ray marching is used to determine pixel colors. The project uses WebGL and was coded with TypeScript and GLSL in Visual Studio Code.

## Implementation Details

## Submission
Commit and push to Github, then submit a link to your commit on Canvas. Remember
to make your own README!
This scene is created entirely in the fragment shader. Rays are shot from the camera through the pixels of the screen to test against the sdfs that comprise the scene to determine distance of the nearest object to the camera. The scene is composed of primitives that have been combined together in various ways; for example a smooth blend operation is used to nicely blend together the toruses that compose the robot's feet/wheels with the capsule primitives that compose his lower legs.

## Inspiration
- [Alien Corridor](https://www.shadertoy.com/view/4slyRs)
- [The Evolution of Motion](https://www.shadertoy.com/view/XlfGzH)
- [Fractal Land](https://www.shadertoy.com/view/XsBXWt)
- [Voxel Edges](https://www.shadertoy.com/view/4dfGzs)
- [Snail](https://www.shadertoy.com/view/ld3Gz2)
- [Cubescape](https://www.shadertoy.com/view/Msl3Rr)
- [Journey Tribute](https://www.shadertoy.com/view/ldlcRf)
- [Stormy Landscape](https://www.shadertoy.com/view/4ts3z2)
- [Generators](https://www.shadertoy.com/view/Xtf3Rn)
The primitives are described by SDF functions at the top of the shader. Normals are calculated by sampling the scene in the same way, using small epsilon differences from the sampled fragment to determine the normal. These normals are then used to achieve lambertian shading by comparing the normal to the light position. To enhance the lighting, a shadow effect is created whereby a shadow feeler ray is sent from the camera ray's intersection point towards the light source to determine if there is an occlusion.

There is also some simple animation added to the scene. The face of the robot, which looks sort of like an old-school scuba mask is created with a boolean subtraction operation between one rounded cylinder and a smaller one. This is added to the sphere that composes the head with a Union operation to meld them together. This face is animated using rotation operations and a quadratic Impulse function combined with a sin function to create the effect that the robot abruptly looks at the camera, then slowly looks away again. Additionally, the antenna ball on his head is animated using cosin functions to give the feeling that it is bouncing around playfully.


IQ's article on SDF shapes was very useful:
https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
Binary file added Reference.jpeg
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 Results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions dist/index.html → index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>Project 0: Getting Started | CIS 566</title>
<title> Raymarching SDFs </title>
<style>
html, body {
margin: 0;
Expand All @@ -15,6 +15,6 @@
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript" src="bundle.js"></script>
<script type="text/javascript" src="dist/bundle.js"></script>
</body>
</html>
Loading