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: Megan Moore #7

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
69bc1a0
Update README.md
megmo21 Oct 19, 2015
5e65118
gifs
megmo21 Oct 19, 2015
4f666d9
Update README.md
megmo21 Oct 19, 2015
0fad372
new files
megmo21 Oct 19, 2015
4b9f138
final filesMerge branch 'master' of https://github.com/megmo21/Projec…
megmo21 Oct 19, 2015
a84ea14
Update README.md
megmo21 Oct 19, 2015
e662f47
Update README.md
megmo21 Oct 19, 2015
f35d11f
Update README.md
megmo21 Oct 19, 2015
87ea3f0
images
megmo21 Oct 19, 2015
01bf788
Update README.md
megmo21 Oct 19, 2015
97ad3c4
img
megmo21 Oct 19, 2015
d72fce5
Merge branch 'master' of https://github.com/megmo21/Project5-GLSL-Ray…
megmo21 Oct 19, 2015
5984edb
Update README.md
megmo21 Oct 19, 2015
cfa5e95
Update README.md
megmo21 Oct 19, 2015
6872599
more images
megmo21 Oct 19, 2015
2605d47
stuffMerge branch 'master' of https://github.com/megmo21/Project5-GLS…
megmo21 Oct 19, 2015
7688292
Update README.md
megmo21 Oct 19, 2015
b2f368b
Update README.md
megmo21 Oct 19, 2015
7eb5a3e
nother gif
megmo21 Oct 19, 2015
34e8e51
Update README.md
megmo21 Oct 19, 2015
a5a7589
new train gif
megmo21 Oct 19, 2015
b97f374
Update README.md
megmo21 Oct 19, 2015
83250c6
Update README.md
megmo21 Oct 19, 2015
f31d1b6
Update README.md
megmo21 Oct 19, 2015
451e8f3
Update README.md
megmo21 Oct 19, 2015
aad35e5
Update README.md
megmo21 Oct 19, 2015
3d2bc0a
Update README.md
megmo21 Oct 19, 2015
cb34cb3
new images
megmo21 Oct 19, 2015
bc8d05a
Update README.md
megmo21 Oct 19, 2015
17bab79
soft shadow
megmo21 Oct 19, 2015
81e3f2e
Update README.md
megmo21 Oct 19, 2015
621eaa8
images
megmo21 Oct 19, 2015
ca06cff
Update README.md
megmo21 Oct 19, 2015
437b863
Update README.md
megmo21 Oct 19, 2015
1ed9649
Update README.md
megmo21 Oct 19, 2015
de111f2
Update README.md
megmo21 Oct 19, 2015
de7abc0
gif
megmo21 Oct 19, 2015
1cf7637
Update README.md
megmo21 Oct 19, 2015
c561638
Update README.md
megmo21 Oct 19, 2015
d04e6e6
new image
megmo21 Oct 19, 2015
8192b93
Update README.md
megmo21 Oct 19, 2015
6af1a13
Update README.md
megmo21 Oct 19, 2015
2626e25
Update README.md
megmo21 Oct 19, 2015
ad6c36c
images
megmo21 Oct 19, 2015
654e218
Update README.md
megmo21 Oct 19, 2015
8b76c7b
Update README.md
megmo21 Oct 19, 2015
e5c627f
Update README.md
megmo21 Oct 19, 2015
7fa9c30
Update README.md
megmo21 Oct 20, 2015
e82f736
Update README.md
megmo21 Oct 20, 2015
2d02feb
Update README.md
megmo21 Oct 20, 2015
2ed02ea
images
megmo21 Oct 20, 2015
c8c7105
Update README.md
megmo21 Oct 20, 2015
0eed779
Update README.md
megmo21 Oct 20, 2015
d905e86
Update README.md
megmo21 Oct 20, 2015
3fe783c
Update README.md
megmo21 Oct 20, 2015
c75a47e
pie
megmo21 Oct 20, 2015
93a48f2
Update README.md
megmo21 Oct 20, 2015
756a487
image
megmo21 Oct 20, 2015
6c3d1b6
Update README.md
megmo21 Oct 20, 2015
a68f317
Update README.md
megmo21 Oct 20, 2015
1802aa1
Update README.md
megmo21 Oct 20, 2015
dc0d7ca
Update README.md
megmo21 Oct 20, 2015
c4deb62
Update README.md
megmo21 Oct 20, 2015
9cf0302
Update README.md
megmo21 Oct 20, 2015
d476816
final code
megmo21 Oct 20, 2015
3a77098
readme(?)
megmo21 Oct 20, 2015
16f4453
Update README.md
megmo21 Oct 20, 2015
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
199 changes: 94 additions & 105 deletions README.md

Large diffs are not rendered by default.

547 changes: 547 additions & 0 deletions bridge.glsl

Large diffs are not rendered by default.

410 changes: 410 additions & 0 deletions finalScene.glsl

Large diffs are not rendered by default.

347 changes: 347 additions & 0 deletions firstScene.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,347 @@
//http://www.iquilezles.org/www/articles/menger/menger.htm - mendel sponge
//https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model - blinn-phong lighting
//http://graphics.cs.williams.edu/courses/cs371/f14/reading/implicit.pdf - ray marching/sphere tracing
//http://www2.compute.dtu.dk/pubdb/views/edoc_download.php/6392/pdf/imm6392.pdf - ambient occlusion/soft shadows
//--Distance Functions-------------------------------------------------------------------
#define NO_DEBUG 1
#define NORMALS 0
#define RAY_STEPS 0
#define DISTANCE 0
#define SPHERE_TRACE 1


float planeDist( vec3 p )
{
/*if (p.y < ((sin(p.x) - sin(p.z)) / 4.0)) return (sin(p.x) - sin(p.z)) / 4.0;
else return 100.0;
return 100.0;*/
return p.y;

}

float sphereDist(vec3 p, float r) {
return length(p) - r;
}

float boxDist( vec3 p, vec3 b )
{
vec3 d = abs(p) - b;
return min(max(d.x,max(d.y,d.z)),0.0) + length(max(d,0.0));
}

float torusDist( vec3 p, vec2 t )
{
return length( vec2(length(p.xz)-t.x,p.y) )-t.y;
}

float roundBoxDist( vec3 p, vec3 b, float r )
{
return length(max(abs(p)-b,0.0))-r;
}

float crossDist( in vec3 p )
{
float da = boxDist(p.xyz,vec3(100000,1.0,1.0));
float db = boxDist(p.yzx,vec3(1.0,100000,1.0));
float dc = boxDist(p.zxy,vec3(1.0,1.0,100000));
return min(da,min(db,dc));
}

//--CSG Functions----------------------------------------------------------------------

float diffFunc(float d1, float d2) {
return max(d1, -d2);
}

float intersectionFunc(float d1, float d2) {
return max(d1, d2);
}

float repeat( vec3 p, vec3 c )
{
vec3 q = mod(p,c)-0.5*c;
vec4 height = texture2D(iChannel0, p.xz);
//float avg = clamp((height.x + height.y + height.z + height.w) / 4.0, 0.0, 2.0);
return roundBoxDist(q - vec3(0.0, 0.0, 0.0), vec3(.35, 0.1, .35), 0.1);
}

float displace( vec3 p )
{
float d1 = torusDist(p, vec2(1.0, .2));
float d2 = (sin(20.0*p.x)*sin(20.0*p.y)*sin(20.0*p.z)) / (16.0*p.y);
return d1+d2;
}

vec3 transform(vec3 pt, vec3 translate, vec3 rot, vec3 scale) {
scale.x = 1.0/scale.x;
scale.y = 1.0/scale.y;
scale.z = 1.0/scale.z;
mat3 invRot = mat3(scale.x*cos(rot.y)*cos(rot.x), sin(rot.y)*sin(rot.z)*cos(rot.x) - cos(rot.z)*sin(rot.x) , sin(rot.y)*sin(rot.x) + cos(rot.z)*sin(rot.y)*cos(rot.x) ,
cos(rot.y)*sin(rot.x), (sin(rot.z)*sin(rot.y)*sin(rot.x) + cos(rot.z)*cos(rot.x))*scale.y, sin(rot.x)*sin(rot.y)*cos(rot.z) - cos(rot.x)*sin(rot.z),
-sin(rot.y), cos(rot.y)*sin(rot.z), cos(rot.y)*cos(rot.z)*scale.z);
mat4 trans = mat4(scale.x*cos(rot.y)*cos(rot.x), sin(rot.y)*sin(rot.z)*cos(rot.x) - cos(rot.z)*sin(rot.x) , sin(rot.y)*sin(rot.x) + cos(rot.z)*sin(rot.y)*cos(rot.x) , 0.0,
cos(rot.y)*sin(rot.x), (sin(rot.z)*sin(rot.y)*sin(rot.x) + cos(rot.z)*cos(rot.x))*scale.y, sin(rot.x)*sin(rot.y)*cos(rot.z) - cos(rot.x)*sin(rot.z), 0.0,
-sin(rot.y), cos(rot.y)*sin(rot.z), cos(rot.y)*cos(rot.z)*scale.z, 0.0,
(-invRot*translate).x, (-invRot*translate).y, (-invRot*translate).z, 1.0);

vec4 newPt = vec4(pt, 1.0);
newPt = trans*newPt;
return vec3(newPt);

}
//--Different Scenes-------------------------------------------------------------------

float sceneFractal(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + rd*t;

float tmin = boxDist(pt - vec3(1.0, 0.0, 0.0), vec3(.5));

float s = 1.0;
for( int m=0; m<3; m++ )
{
vec3 a = mod( pt*s, 2.0 )-1.0;
s *= 3.0;
vec3 r = abs(1.0 - 3.0*abs(a));

float da = max(r.x,r.y);
float db = max(r.y,r.z);
float dc = max(r.z,r.x);
float c = (min(da,min(db,dc))-1.0)/s;

tmin = max(tmin,c);
}
tmin = min(tmin, planeDist(pt - vec3(0.0, -.5, 0.0)));
return tmin;

}

float sceneDisplacement(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + rd*t;
float tmin = displace(pt);

return tmin;
}

float sceneNothin(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + rd*t;
float tmin = 0.0;

return tmin;
}
float sceneRepeat(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + rd*t;
float tmin = repeat(pt, vec3(1.0, 0.0, 1.0));

return tmin;

}

float sceneTransform(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + t*rd;

vec3 pos = transform(vec3(pt), vec3(1.0, 0.0, 0.0), vec3(radians(iGlobalTime), radians(0.), radians(45.)), vec3(.5, 1.0, 1.0));
float tmin = boxDist(pos, vec3(0.5));

return tmin;
}

float sceneHeight(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + rd*t;
vec4 color1 = texture2D (iChannel0, pt.xz);

float tmin = pt.y - (color1.y);
return tmin;
}

float sceneLighting(vec3 ro, vec3 rd, float t) {
vec3 pt = ro + rd*t;
float tmin = sphereDist(pt - vec3(0.0, -1.0, 0.0), .50);
tmin = min(tmin, planeDist(pt - vec3(0.0, -.5, 0.0)));
tmin = min(tmin, boxDist(pt - vec3( 1.0,-.25, 0.0), vec3(0.25)));
tmin = min(tmin, torusDist(pt - vec3(-1.0, 0.25, 0.0), vec2(0.20,0.05)));
tmin = min(tmin, diffFunc(boxDist(pt - vec3(0.0), vec3(0.50, 0.30, 0.30)), sphereDist(pt - vec3(0.0), 0.40)));
return tmin;
}

//--Ray Marching------------------------------------------------------------------

vec3 calcNorm( in vec3 pos )
{
vec3 eps = vec3( 0.001, 0.0, 0.0 );
vec3 nor = vec3(
scene(pos+eps.xyy, vec3(0.0), 0.0) - scene(pos-eps.xyy, vec3(0.0), 0.0),
scene(pos+eps.yxy, vec3(0.0), 0.0) - scene(pos-eps.yxy, vec3(0.0), 0.0),
scene(pos+eps.yyx, vec3(0.0), 0.0) - scene(pos-eps.yyx, vec3(0.0), 0.0) );
return normalize(nor);
}

vec2 findRoot(vec3 ro, vec3 rd) {
float dist = 100.0;
float i = 0.0;
for (float t = 0.0; t < 5.0; t += .01) {
i++;
if (scene(ro, rd, t) < 0.0) {
dist = t;
break;
}
}

return vec2(dist, i);

}

vec2 sphereTrace(vec3 ro, vec3 rd) {
float t = 0.0;
float dt;
float numTraces = 0.0;
for (int i = 0; i < 50; i++) {
numTraces++;
dt = scene(ro, rd, t);
t = t + dt;
if (dt < 0.0001) {
break;
}
}
return vec2(t, numTraces);
}

float softshadow( in vec3 ro, in vec3 rd, in float tmin, in float tmax )
{
float shadow = 1.0;
float t = tmin;
float d = 0.0;
for( int i=0; i<16; i++ )
{
d = scene(ro, rd, t);
if (d < 0.0001) return 0.0;
shadow = min( shadow, 8.0*d/t );
t += d;
if( d<0.0001 || t > tmax) break;
}
return clamp(shadow, 0.0, 1.0);

}

float ambientOcc( in vec3 pt, in vec3 norm )
{
float occ = 0.0;
float d = 0.0;
for(float k=1.0; k<10.0; k++ )
{
d = scene(pt, norm, .01*k);
occ = (1.0 / pow(2.0, k)) * (k*.01 - d);
}
return clamp(1.0 - 3000.0*occ, 0.0, 1.0);
}

vec3 render(in vec3 ro, in vec3 rd) {
// TODO
int debug = 1;
bool root;
if (SPHERE_TRACE == 1) root = false;
else root = true;
vec3 col = vec3(.8, .9, 1.0);
float t = -1.0;
vec2 dist;
if (root) {
dist = findRoot(ro, rd);
}
else {
dist = sphereTrace(ro, rd);
}
t = dist.x;
if (t < 10.0) {
vec3 pt = ro + rd*t;
vec3 norm = calcNorm(pt);

//material
vec4 x = texture2D( iChannel1, pt.yz );
vec4 y = texture2D( iChannel1, pt.zx );
vec4 z = texture2D( iChannel1, pt.yx );
vec3 a = abs(norm);
vec4 diffuse = (x*a.x + y*a.y + z*a.z) / (a.x + a.y + a.z);

//end material

vec3 ref = reflect(rd, norm);
vec3 light = normalize(vec3(0.0, 2.0, 2.0) - pt);
float lambert = clamp(dot(light, norm), 0.0, 1.0);
float amb = ambientOcc(pt, norm);
//soft shadows
lambert *= softshadow( pt, light, 0.02, 2.5 );
float dom = smoothstep( -0.1, 0.1, ref.y );
dom *= softshadow( pt, ref, 0.02, 2.5 );

float specular = 0.0;
if (lambert > 0.0) {
vec3 viewDir = normalize(-pt);
vec3 halfDir = normalize(light + viewDir);
float specAngle = clamp(dot(halfDir, norm), 0.0, 1.0);
specular = pow(specAngle, 4.0);

}

col = vec3(.2) + lambert * vec3(diffuse) + specular * vec3(0.5); //amb*

col = pow(col, vec3(1.0/2.2));
col *= 1.0 - smoothstep( 20.0, 40.0, t );
if (NORMALS == 1) {
col = norm;
}
else if (RAY_STEPS == 1) {
if (root) {
col = vec3(1.0, 0.0, 0.0)*(dist.y / 500.0);
}
else {
col = vec3(1.0, 0.0, 0.0)*(dist.y / 50.0);
}
}
else if (DISTANCE == 1) {
col = vec3(1.0) * ((5.0 - t) / 5.0);
}
}
return col; //rd; // camera ray direction debug view
}

mat3 setCamera(in vec3 ro, in vec3 ta, float cr) {
// Starter code from iq's Raymarching Primitives
// https://www.shadertoy.com/view/Xds3zN

vec3 cw = normalize(ta - ro);
vec3 cp = vec3(sin(cr), cos(cr), 0.0);
vec3 cu = normalize(cross(cw, cp));
vec3 cv = normalize(cross(cu, cw));
return mat3(cu, cv, cw);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// Starter code from iq's Raymarching Primitives
// https://www.shadertoy.com/view/Xds3zN

vec2 q = fragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0 * q;
p.x *= iResolution.x / iResolution.y;
vec2 mo = iMouse.xy / iResolution.xy;

float time = 15.0 + iGlobalTime;

// camera
vec3 ro = vec3(
-0.5 + 3.5 * cos(0.1 * time + 6.0 * mo.x),
1.0 + 2.0 * mo.y,
0.5 + 3.5 * sin(0.1 * time + 6.0 * mo.x));
vec3 ta = vec3(-0.5, -0.4, 0.5);

// camera-to-world transformation
mat3 ca = setCamera(ro, ta, 0.0);

// ray direction
vec3 rd = ca * normalize(vec3(p.xy, 2.0));

// render
vec3 col = render(ro, rd);

col = pow(col, vec3(0.4545));

fragColor = vec4(col, 1.0);
}
Binary file added img/amb_occ_debug.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/ambient_occlusion.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/before_amb_occ.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/blinn_phong_lighting.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/bridge2.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/bridge_over_water.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/bridge_tracks.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/bridge_under_water.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/debug_image.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/debug_image_norm.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/debug_image_orig.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/debug_image_steps.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/debug_naive.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/debug_sphere.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/final_scene_gif.gif
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/height_map1.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/height_map2.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/menger_sponge.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/pie.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/rotating.gif
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/rotating_box_gif.gif
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/smoke.gif
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/soft_shadow.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/sun_reflecting.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/train.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/train_gif.gif
Binary file added img/train_smoke.png
Binary file added img/wood_material.png
47 changes: 0 additions & 47 deletions raymarch.glsl

This file was deleted.