Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Random dots in pure GLSL.
The same old random function with a different signature.
vec2 rand(vec2 co){
return vec2(
fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453),
fract(cos(dot(co.yx ,vec2(8.64947,45.097))) * 43758.5453)
Dot distance field.
float dots(in vec2 uv)
// Consider the integer component of the UV coordinate
// to be an ID of a local coordinate space.
vec2 g = floor(uv);
// "What 'local coordinate space'?" you say? Why the one
// implicitly defined by the fractional component of
// the UV coordinate. Here we translate the origin to the
// center.
vec2 f = fract(uv)*2.0-1.0;
// Get a random value based on the "ID" of the coordinate
// system. This value is invariant across the entire region.
vec2 r = rand(g)*.5;
// Return the distance to that point.
return length(f+r);
Shadertoy's entrypoint.
void mainImage( out vec4 fragColor, in vec2 fragCoord )
vec2 uv = fragCoord;
fragColor = vec4(smoothstep(.2, .22,dots(uv*.01)));

This comment has been minimized.

Show comment Hide comment

GameKyuubi Aug 2, 2017



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment