Skip to content

Instantly share code, notes, and snippets.

@honix
Last active December 5, 2018 09:50
Show Gist options
  • Save honix/3ad5669bf0b48133fd725de4f7d6b742 to your computer and use it in GitHub Desktop.
Save honix/3ad5669bf0b48133fd725de4f7d6b742 to your computer and use it in GitHub Desktop.
glsl shader principles
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
// this is color
void main_0( void ) {
gl_FragColor = vec4(sin(time), 0.0, 1.0, 1.0);
}
// this is position
void main_1( void ) {
vec2 position = gl_FragCoord.xy / resolution.xy;
gl_FragColor = vec4(position.x, position.y, 0.0, 1.0);
}
// this is condition
void main_2( void ) {
vec2 position = gl_FragCoord.xy / resolution.xy;
if (position.y > 0.6666)
gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);
else if (position.y > 0.3333)
gl_FragColor = vec4(0.0, 0.0, 0.5, 1.0);
else
gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
}
// this is quad
void main_3( void ) {
vec2 position = gl_FragCoord.xy / resolution.xy;
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
if (position.x < 0.25 || position.x > 0.75 || position.y < 0.25 || position.y > 0.75)
gl_FragColor = vec4(1.0);
}
// this is aspect ratio
void main_4( void ) {
float aspect = resolution.x / resolution.y;
vec2 position = gl_FragCoord.xy / resolution.xy * vec2(aspect, 1.0);
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
if (position.x < 0.25 || position.x > 0.75 || position.y < 0.25 || position.y > 0.75)
gl_FragColor = vec4(1.0);
}
// this is distance
void main_5( void ) {
float aspect = resolution.x / resolution.y;
vec2 position = gl_FragCoord.xy / resolution.xy * vec2(aspect, 1.0);
float dist = distance(vec2(1, 0.5), position);
gl_FragColor = vec4(dist);
}
// this is circle
void main_6( void ) {
float aspect = resolution.x / resolution.y;
vec2 position = gl_FragCoord.xy / resolution.xy * vec2(aspect, 1.0);
float dist = distance(vec2(1, 0.5), position);
float black = step(0.25, dist);
gl_FragColor = vec4(black);
}
// this is many circles
void main_7( void ) {
float r = 0.15;
float aspect = resolution.x / resolution.y;
vec2 position = gl_FragCoord.xy / resolution.xy * vec2(aspect, 1.0);
position = mod(position, r+r);
float dist = distance(vec2(r), position);
float black = step(r, dist);
gl_FragColor = vec4(black);
}
// this is flag of many circles
void main_8( void ) {
float r = 0.15;
float aspect = resolution.x / resolution.y;
vec2 position = gl_FragCoord.xy / resolution.xy * vec2(aspect, 1.0);
position.y += sin(position.x * 5. + time) * .10;
position = mod(position, r+r);
float dist = distance(vec2(r), position);
float black = step(r, dist);
gl_FragColor = vec4(black);
}
// this is pseudo random
void main_9( void ) {
float aspect = resolution.x / resolution.y;
vec2 position = gl_FragCoord.xy / resolution.xy * vec2(aspect, 1.0);
float dist = distance(vec2(sin(time * 100000.) * 0.5 + .5 * aspect, 0.5), position);
float black = step(0.25, dist);
gl_FragColor = vec4(black);
}
// this in bad noise
void main_10( void ) {
vec2 position = gl_FragCoord.xy / resolution.xy;
gl_FragColor = vec4(sin(position.x * position.y * 100000000.));
}
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
// this is good noise
void main_11( void ) {
vec2 position = gl_FragCoord.xy / resolution.xy;
gl_FragColor = vec4(rand(position));
// gl_FragColor = vec4(rand(position * time));
}
varying vec2 surfacePosition;
// this is fractals!!!
void main( void ) {
vec2 z = surfacePosition * 2.;
int n;
for(int i = 0; i < 100; i++) {
n = i;
float x = (z.x * z.x - z.y * z.y) + .32;
float y = (z.y * z.x + z.x * z.y) + .5;
if((x * x + y * y) > 4.0) break;
z.x = x;
z.y = y;
}
gl_FragColor = vec4(float(n) * .025);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment