Skip to content

Instantly share code, notes, and snippets.

@caioketo
Created September 13, 2013 18:35
Show Gist options
  • Save caioketo/6554375 to your computer and use it in GitHub Desktop.
Save caioketo/6554375 to your computer and use it in GitHub Desktop.
GLSL hidden
uniform sampler2D sky_texture;
uniform int hidden;
uniform float time;
varying vec2 vUv;
varying vec3 vPosition;
varying float vHeightmap;
void main()
{
vec2 sky_uv = vUv;
sky_uv.x += (sin(radians(time / 800.0)));
if (sky_uv.x < 0.0) {
sky_uv.x = 1.0 + sky_uv.x;
}
if (sky_uv.x > 1.0) {
sky_uv.x = sky_uv.x - 1.0;
}
sky_uv.y += (sin(radians(time / 900.0)));
if (sky_uv.y < 0.0) {
sky_uv.y = 1.0 + sky_uv.y;
}
if (sky_uv.y > 1.0) {
sky_uv.y = sky_uv.y - 1.0;
}
vec3 sky_point_color = texture2D ( sky_texture, sky_uv ).rgb;
vec4 sky_point = vec4(sky_point_color, sky_point_color.r);
gl_FragColor = vec4(.0, .2, .6, .6);
gl_FragColor = mix(
gl_FragColor,
sky_point,
.8
);
gl_FragColor.a = min((-2.0 * vHeightmap) + .05, 1.0);
// Determine at what point the elevation must be for the foam to display
float low_tide = -.01;
float low_tide_1 = low_tide + sin(radians(time / 10.0)) * .001; // Mostly animation speed
float tide_1_width = .001;
float low_tide_2 = low_tide + sin(radians(time / 6.0)) * .003; // Mostly animation speed
float tide_2_width = .002;
if (
(vHeightmap >= low_tide_1 && vHeightmap <= low_tide_1 + tide_1_width)
||
(vHeightmap >= low_tide_2 && vHeightmap <= low_tide_2 + tide_2_width)
) {
// Foam color
gl_FragColor = mix(
gl_FragColor,
vec4(1.0, 1.0, 1.0, 1.0),
1.0 - (vHeightmap * -60.0)
);
}
if (hidden == 1) {
gl_FragColor.a = .2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment