Last active
May 11, 2020 14:51
-
-
Save CharStiles/2e5889a660b8c7cbf8d1e0b5ff4bf1e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define some constants | |
const int steps = 128; // This is the maximum amount a ray can march. | |
const float smallNumber = 0.001; | |
const float maxDist = 10.; // This is the maximum distance a ray can travel. | |
float scene(vec3 position){ | |
// So this is different from the prev sphere equation in that I am | |
// splitting the position into it's three different parts | |
// and adding a 10th of a cos wave to the x position so it oscillates left | |
// to right and a (positive) sin wave to the z position | |
// so it will go back and forth. | |
float sphere = length( | |
vec3( | |
position.x + cos(time)/10., | |
position.y, | |
position.z+ sin(time) +1.) | |
)-0.5; | |
// This is different from the ground equation because the UV is only | |
// between -1 and 1 we want more than 1/2pi of a wave per length of the | |
// screen so we multiply the position by a factor of 10 inside the trig | |
// functions. Since sin and cos oscillate between -1 and 1, that would be | |
// the entire height of the screen so we divide by a factor of 10. | |
float ground = position.y + sin(position.x * 10.) / 10. | |
+ cos(position.z * 10.) / 10. + 1.; | |
// We want to return whichever one is closest to the ray, so we return the | |
// minimum distance. | |
return min(sphere,ground); | |
} | |
void main() { | |
vec2 uv = uv(); | |
vec3 rayOrigin = vec3(uv, 0.0); | |
vec4 color = vec4(scene(rayOrigin)); | |
gl_FragColor = color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment