0.00
60.0 fps

fresh.flowers

Gyroid noise from shadertoy.com/view/ddx3wb

Log in to post a comment.

#version 300 es
precision highp float;

uniform float z; // value=0.3, min=0.0, max=5.0, step=0.0001
uniform float speed; // value=1, min=0, max=10.0, step=0.001
uniform int total; // value=6, min=1, max=20, step=1

uniform float scale; // value=0.5, min=0.00001, max=0.5, step=0.0001

uniform float s1; // value=10.0, min=0, max=10.0, step=0.001
uniform float s2; // value=0.0, min=0, max=10.0, step=0.001
uniform float sunflowerSize; // value=0.95, min=-2.0, max=2.0, step=0.001
uniform float theme; // value=0, min=0, max=3, step=1 
//(Daisy, Tullip, Tressor, Rose)

uniform float iTime;

in  vec2 vScreen;
out vec4 fragColor;

//vec3 RED = vec3(0.808,0.122,0.173);
vec3 BLUE = vec3(0.204,0.498,0.816);
vec3 YELLOW_ORANGE = vec3(0.776,0.49,0.);
vec3 YELLOW_GREEN = vec3(0.408,0.365,0.184);
vec3 YELLOW = vec3(0.886,0.675,0.082);
vec3 GREEN = vec3(0.153,0.243,0.078);
vec3 GREEN_DARK = vec3(0.09,0.125,0.059);
vec3 GREEN_PALE = vec3(0.24,0.35,0.20);

vec3 WHITE = vec3(0.933,0.933,0.933);
vec3 GRAY = vec3(0.8,0.8,0.8);
vec3 BLACK = vec3(0.067,0.067,0.067);

vec3 PINK_DARK = vec3(0.59,0.00,0.07);
vec3 PINK = vec3(1.00,0.45,0.67);
vec3 PINK_MEDIUM = vec3(1.00,0.18,0.40);

vec3 ORANGE_DARK = vec3(0.71,0.00,0.00);
vec3 ORANGE = vec3(1.00,0.30,0.00);
vec3 ORANGE_PALE = vec3(1.00,0.49,0.24);

vec3 RED_DARK = vec3(0.36,0.00,0.07);
vec3 RED = vec3(0.86,0.00,0.18);
vec3 RED_PALE = vec3(1.00,0.31,0.42);

// white noise from: https://www.shadertoy.com/view/tlcBRl
float noise1(float seed1,float seed2){
    return (
        fract(seed1+12.34567*
        fract(100.*(abs(seed1*0.91)+seed2+94.68)*
        fract((abs(seed2*0.41)+45.46)*
        fract((abs(seed2)+757.21)*
        fract(seed1*0.0171))))))
        * 1.0038 - 0.00185;
}
float noise2(float seed1, float seed2) {
    float buff1 = abs(seed1+100.94) + 1000.;
    float buff2 = abs(seed2+100.73) + 1000.;
    buff1 = (buff1*fract(buff2*fract(buff1*fract(buff2*0.63))));
    buff2 = (buff2*fract(buff2*fract(buff1+buff2*fract(seed1*0.79))));
    buff1 = noise1(buff1, buff2);
    return(buff1 * 1.0038 - 0.00185);
}
vec3 noise2to3(vec2 pos) {
    return vec3(noise2(pos.x, pos.y),noise2(pos.x*2., pos.y*3.),noise2(pos.x*3., pos.y*4.));
}

// source: https://www.shadertoy.com/view/3tSGDy
// signed distance to a n-star polygon with external angle en
float sdStar(in vec2 p, in float r, in int n, in float m) // m=[2,n] 
{
    // these 4 lines can be precomputed for a given shape
    float an = 3.141593/float(n);
    float en = 3.141593/m;
    vec2  acs = vec2(cos(an),sin(an));
    vec2  ecs = vec2(cos(en),sin(en)); // ecs=vec2(0,1) and simplify, for regular polygon,

    // symmetry (optional)
    p.x = abs(p.x);
    
    // reduce to first sector
    float bn = mod(atan(p.x,p.y),2.0*an) - an;
    p = length(p)*vec2(cos(bn),abs(sin(bn)));

    // line sdf
    p -= r*acs;
    p += ecs*clamp( -dot(p,ecs), 0.0, r*acs.y/ecs.y);
    return length(p)*sign(p.x);
}

float smoothing(in float d, in float h) {
     return d - h;
}

float opSmoothUnion( float d1, float d2, float k ) {
    float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );
    return mix( d2, d1, h ) - k*h*(1.0-h); }

float gyroid (vec3 seed) {
    return dot(sin(seed),cos(seed.yzx));
}

float fbm (vec3 seed) {
    float result = 0., a = .5;
    for (int i = 0; i < total; ++i) {
        // extra spicy twist
        seed.z += result*z;
        // bounce it with abs
        result += abs(gyroid(seed/a))*a;
        a *= scale;
    }
    return result;
}

float noise (vec2 p) {
    // improvise 3d seed from 2d coordinates
    vec3 seed = vec3(p, length(p) - iTime * (.025*speed));
    vec3 seed2 = vec3(p, length(p*3.2) - iTime * (.033*speed));
    
    // make it slide along the sin wave
    return (sin(fbm(seed)*s1 * sin(cos(fbm(seed2)*s2))))*.5+.5;
}

float inverseLerp(float x, float y, float v) {
    return clamp((v - x) / (y - x), 0., 1.);
}

void main() {
    vec3 LEAF_CLR1 = GREEN;
    vec3 LEAF_CLR2 = GREEN_DARK;
    vec3 LEAF_CLR3 = BLACK;
    
    vec3 SKY_CLR1 = WHITE;
    vec3 SKY_CLR2 = GREEN_PALE;

    SKY_CLR1 = WHITE;
    SKY_CLR2 = BLUE;
    
    vec3 SUNFLOWER_CLR1 = YELLOW;
    vec3 SUNFLOWER_CLR2 = GRAY;
    vec3 SUNFLOWER_SHADE_1 = YELLOW;
    vec3 SUNFLOWER_SHADE_2 = YELLOW_ORANGE;
    
    if (theme == 1.) {
        LEAF_CLR1 = PINK;
        LEAF_CLR2 = PINK_MEDIUM;
        LEAF_CLR3 = PINK_DARK;
        
        SKY_CLR1 = WHITE;
        SKY_CLR2 = BLUE;
        
        SUNFLOWER_CLR1 = SUNFLOWER_SHADE_1 = GREEN_DARK;
        SUNFLOWER_CLR2 = GREEN;
        SUNFLOWER_SHADE_2 = GREEN_PALE;
    } else if (theme == 2.) {
        LEAF_CLR2 = GREEN_PALE;
        
        SKY_CLR1 = WHITE;
        SKY_CLR2 = BLUE;
        
        SUNFLOWER_CLR1 = ORANGE_DARK;
        SUNFLOWER_SHADE_1 = ORANGE_PALE;
        SUNFLOWER_CLR2 = ORANGE_PALE;
        SUNFLOWER_SHADE_2 = ORANGE;
    } else if (theme == 3.) {
        SKY_CLR1 = WHITE;
        SKY_CLR2 = BLUE;
        
        SUNFLOWER_CLR1 = SUNFLOWER_SHADE_1 = RED;
        SUNFLOWER_CLR2 = RED_DARK;
        SUNFLOWER_SHADE_2 = RED_PALE;
    }
     
    vec3 color;
    float len = length(vScreen.xy);
    
    
    float ni = noise(vScreen.yx*0.5);
    ni = ni*ni*ni*ni;
    
    float n = noise(vScreen);
    n = smoothstep(0., 1.0,n*n*n*n);
    
    
    
    float sides = 7.;
    float a = fract(0.5);
    float w = 2.0 + a*a*(sides-2.0);
    float star = sdStar(vScreen*2., sunflowerSize, int(sides), w);
    
    float flowerShape = len-(sunflowerSize*0.5);
    if (theme == 0. || theme == 2.) {
       flowerShape = star * 0.6;
    }
    
    
    float n2 = noise(vScreen + vec2(0.0,0.2));
    n2 = mix(n2, 1.0, 1. - abs(1. - flowerShape-0.45) );
     /*if (length(vScreen.yx) < 0.6) {
        n2 -= 0.7;
    }*/
    
    float mask1 = inverseLerp(0.45, 0.5, n2);
   
    vec3 lineColor = WHITE;
    vec3 color1 = mix(mix(LEAF_CLR2,LEAF_CLR1,n+n), LEAF_CLR3, smoothstep(0., 1.0, abs(n2-0.3)));
    vec3 color2 = mix(SKY_CLR1, SKY_CLR2, (n+ni)*0.5);
    
    
    // mix colors
    color = mix(color1, color2, mask1);
    
     
    vec3 sunflower = mix(SUNFLOWER_CLR1, SUNFLOWER_CLR2, mix(ni,n,flowerShape));
    // sunflower border 1
    sunflower = mix(sunflower, SUNFLOWER_SHADE_1, smoothstep(0.98, 1.0, abs(flowerShape+ni*0.3)));
    // sunflower border 2
    sunflower = mix(sunflower, SUNFLOWER_SHADE_2, smoothstep(0.98, 1.0, abs(flowerShape+n*0.2)));
    
    // add lines
    color = mix(color, lineColor, smoothstep(fwidth(n) * 2., 0., abs(n-0.4)));
    
    
    if (theme == 0. || theme == 2.) {
        color = mix(mix(GREEN_DARK,color,0.8), color, smoothstep(0.0, 0.1, star));
        color = mix(WHITE, color, smoothstep(0.0, 0.02, star));
       
    }
    
    color = mix(sunflower, color, smoothstep(0.98, 1.0, (flowerShape+n*0.1)));
    
    fragColor.xyz = mix(color, noise2to3(vScreen), 0.1);
}