I get a nice interpolation of color at the beginning, but then at the end I get an abrupt change of color.
Just curious if anyone can help me figure out how to fade at the end of the cycle instead of an abrupt change. Thanks.
The noise and random are from BookofShaders.com
float random (vec2 st) {
return fract(sin(dot(st.xy,vec2(12.9898,78.233)))+(agk_time/20.0));
}
float noise (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));
// Smooth Interpolation
// Cubic Hermine Curve. Same as SmoothStep()
vec2 u = f*f*(3.0-2.0*f);
// u = smoothstep(0.,1.,f);
// Mix 4 coorners percentages
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
{
float wave_max = ((1.0-0.25)*sin((agk_time+posVarying.z))+1.0+0.25)/2.0;
float wave_min = ((.25-0.0)*sin((agk_time+posVarying.x))+.25+0.0)/2.0;
vec2 st = posVarying.xz;
vec2 posn = vec2(st*.85)*1.25;
float n = clamp(noise(posn),.75,1.0);
mediump vec3 offsetcolor = finalColor;
finalColor = mix( finalColor, vec3(n), clamp(abs((1.0+posVarying.y)/(1.0-.75)), wave_min, wave_max ) );
finalColor = mix( offsetcolor, finalColor, clamp(abs((1.0+posVarying.y)/(1.0-.85)), 0.0, 1.0 ) );
gl_FragColor = vec4(finalColor, 1.0);
}