Skip to content

Instantly share code, notes, and snippets.

View CharStiles's full-sized avatar

Char CharStiles

View GitHub Profile
float circ( vec2 p){
return length(p) - 0.3;
}
void pR(inout vec2 p, float a) {
p = cos(a)*p + sin(a)*vec2(p.y, -p.x);
}
// Repeat in two dimensions
vec2 pMod2(inout vec2 p, vec2 size) {
vec2 c = floor((p + size*0.5)/size);
float circ(vec2 p){
return length(p) - .50;
}
// http://www.iquilezles.org/www/articles/palettes/palettes.htm
// As t runs from 0 to 1 (our normalized palette index or domain),
//the cosine oscilates c times with a phase of d.
//The result is scaled and biased by a and b to meet the desired constrast and brightness.
vec3 cosPalette( float t, vec3 a, vec3 b, vec3 c, vec3 d )
{
float circ(vec2 p){
return length(p) - .50;
}
// Repeat in two dimensions
vec2 pMod2(inout vec2 p, vec2 size) {
vec2 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5,size) - size*0.5;
return c;
}
float circ(vec2 p){
return length(p) - .50;
}
// Repeat in two dimensions
vec2 pMod2(inout vec2 p, vec2 size) {
vec2 c = floor((p + size*0.5)/size);
p = mod(p + size*0.5,size) - size*0.5;
return c;
}
// 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 normal 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
// 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 normal 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
// Define some constants
const int steps = 64; // 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.
// smoothly interpolate between two fuctions with k that controls the radious/distance of the smoothness.
// read more here about smin: https://iquilezles.org/www/articles/smin/smin.htm
float smin( float a, float b, float k )
{
float h = clamp( 0.5+0.5*(b-a)/k, 0.0, 1.0 );
// 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 normal 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
void main() {
vec2 pos = uv(); // origin is in center
float r = sin(time + pos.x);
// x is left to right, why we see red moving from right to left think about us as a camera moving around
// sin returns a number from -1 to 1, and colors are from 0 to 1, so it clips to no red half the time
float g = sin(-time + pos.y * 20.); // higher frequency green stripes
// 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 normal 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