Last active
February 24, 2020 04:37
-
-
Save gregkepler/8898825 to your computer and use it in GitHub Desktop.
Starter fragment shader for basic repeatable lines
This file contains hidden or 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
// ShaderToy Inputs | |
uniform vec3 iResolution; // viewport resolution (in pixels) | |
uniform float iGlobalTime; // shader playback time (in seconds) | |
const float PI=3.14159265358979323846; | |
float round( float x ) { | |
float val = mod( x, x ); | |
if( val >= 0.5 ){ | |
return ceil( x ); | |
}else{ | |
return floor( x ); | |
} | |
} | |
void main(void) | |
{ | |
vec2 uv = gl_FragCoord.xy / iResolution.xy; | |
// draw vertical lines | |
//float stripeVal = floor( mod(gl_FragCoord.x, 7.0) ) == 0.0 ? 1.0 : 0.0; | |
//vec4 col = vec4( stripeVal ) * 0.5; | |
// draw horizontal lines | |
//float stripeVal = floor( mod( gl_FragCoord.y, 7.0 ) ) == 0.0 ? 1.0 : 0.0; | |
//vec4 col = vec4( stripeVal ) * 0.5; | |
// draw large round checkerboard | |
//float stripeVal = cos( gl_FragCoord.x * 0.1 ) + sin( gl_FragCoord.y * 0.1 ); | |
//vec4 col = vec4( stripeVal ) * 0.5; | |
// draw diagonal lines | |
// rotating diagonal | |
//float t = iGlobalTime * 0.5; | |
// perfectly diagonal | |
float t = PI / 4.0; | |
float w = 2.0; // width (larger value = smaller width) | |
float stripeVal = cos( ( gl_FragCoord.x * cos( t ) * w ) + ( gl_FragCoord.y * sin( t ) * w ) ); | |
stripeVal = clamp( round( stripeVal ), -1.0, 0.0 ); // clamping gets rid of the random white lines | |
vec4 col = vec4( stripeVal ) * 0.1; // contrast | |
col += vec4( 0.04, 0.6, 1.0, 1.0 ); // color | |
gl_FragColor = col; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment