Archipelago

Archipelago

I'm relatively new to shaders, and most of what I've done so far has been more copy and pasting than anything else. This was also a copy paste job in a lot of ways (I am not yet up to writing my own noise function), but at least the idea for the simple composition was mine. The idea was to do a standard height map, but then try and fill in the low spots with something that looked like water. I failed at the water, but if you squint, it almost looks like what I was going for.

Made with KodeLife

#version 150

uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform vec3 spectrum;

uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D prevFrame;
uniform sampler2D prevPass;


in VertexData
{
    vec4 v_position;
    vec3 v_normal;
    vec2 v_texcoord;
} inData;

out vec4 fragColor;

float random (in vec2 st) {
    return fract(sin(dot(st.xy,
                         vec2(12.9898,78.233)))*
        43758.5453123);
}

// Gold Noise ©2015 dcerisano@standard3d.com
// - based on the Golden Ratio
// - uniform normalized distribution
// - fastest static noise generator function (also runs at low precision)

float PHI = 1.61803398874989484820459;  // Φ = Golden Ratio   

float gold_noise(in vec2 xy, in float seed){
       return fract(tan(distance(xy*PHI, xy)*seed)*xy.x);
}

// Based on Morgan McGuire @morgan3d
// https://www.shadertoy.com/view/4dS3Wd
float noise (in vec2 st) {
    vec2 i = floor(st);
    vec2 f = fract(st);

    // Four corners in 2D of a tile
    float a = random(i);
    float b = random(i + vec2(1.0, 0.0));
    float c = random(i + vec2(0.0, 1.0));
    float d = random(i + vec2(1.0, 1.0));

    vec2 u = f * f * (3.0 - 2.0 * f);

    return mix(a, b, u.x) +
            (c - a)* u.y * (1.0 - u.x) +
            (d - b) * u.x * u.y;
}

#define OCTAVES 6
float fbm (in vec2 st) {
    // Initial values
    float value = 0.0;
    float amplitude = 1.;
    float frequency = 0.;
    //
    // Loop of octaves
    for (int i = 0; i < OCTAVES; i++) {
        value += amplitude * abs(noise(st) - 0.5);
        st *= 2.;
        amplitude *= .5;
    }
    return value;
}

void main(void)
{
    vec2 uv = -1. + 2. * inData.v_texcoord;
    uv.x *= resolution.x / resolution.y;
    
    float elevation = fbm(uv * 5.0 * time * 0.005);
    vec3 color = elevation * vec3(0.5, 0.7, 0.3);
    if (elevation > 0.2) {
        fragColor = vec4(color, 0.0);
    } else {
        fragColor = vec4(0.3, 0.1, 0.7, 0.0) * noise(uv * 50.0 + time * 0.5);
    }
}

I have been able to get my recording setup working using KodeLife and SiphonRecorder. Next time I'll post a video to go along with the still!