Skip to content

Instantly share code, notes, and snippets.

@co3moz
Created February 15, 2016 07:01
Show Gist options
  • Save co3moz/9694cbaabd95db44b043 to your computer and use it in GitHub Desktop.
Save co3moz/9694cbaabd95db44b043 to your computer and use it in GitHub Desktop.
Simple math function drawer in glsl shader fragment
#define drawFunctionRGB(function, r, g, b) if(distance(position.y, (1. + function(position.x*10.))/2.) < 0.01) color = vec3(r, g, b)
#define drawFunctionRGB_shifted(function, shift, r, g, b) if(distance(position.y, (1. + function(position.x*10. + shift))/2.) < 0.01) color = vec3(r, g, b)
// use wisely
precision mediump float;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
#define drawFunctionRGB(function, r, g, b) if(distance(position.y, (1. + function(position.x*10.))/2.) < 0.01) color = vec3(r, g, b)
float myFunction(float x) {
return sin(x*sin(time));
}
void main() {
vec2 position = ( gl_FragCoord.xy / resolution.xy );
vec3 color;
drawFunctionRGB(myFunction, 1, 1, 0);
gl_FragColor = vec4( color, 1.0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment