in showcases/wind/src/layers/wind-layer/wind-layer-vertex.js [59:125]
void main(void) {
// position in texture coords
float x = (positions.x - bbox.x) / (bbox.y - bbox.x);
float y = (positions.y - bbox.z) / (bbox.w - bbox.z);
vec2 coord = vec2(x, 1. - y);
vec4 texel1 = texture2D(dataFrom, coord);
vec4 texel2 = texture2D(dataTo, coord);
vec4 texel = mix(texel1, texel2, delta);
// angle
float angleFrom = texel1.x * PI4;
float angleTo = texel2.x * PI4;
if (angleFrom < 0.) {
angleFrom += PI * 2.;
}
if (angleTo < 0.) {
angleTo += PI * 2.;
}
if (angleFrom < angleTo) {
if (abs(angleTo - angleFrom) > abs(angleTo - (angleFrom + PI * 2.))) {
angleFrom += PI * 2.;
}
} else {
if (abs(angleFrom - angleTo) > abs(angleFrom - (angleTo + PI * 2.))) {
angleTo += PI * 2.;
}
}
float angle = mix(angleFrom, angleTo, delta);
mat2 rotation = mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
// wind speed in 0-1
float wind = 0.05 + (texel.y - bounds1.x) / (bounds1.y - bounds1.x) * 0.95;
// float wind = (texel.y - bounds1.x) / (bounds1.y - bounds1.x);
float factor = wind * 4.;
vec2 vertex = rotation * vertices.xy;
vec2 normal = rotation * normals.xy;
vec2 pos = project_position(positions.xy + vertex.xy * factor);
// OLD
// vec3 extrudedPosition = vec3(pos.xy, 1.0);
// NEW
float elevation = project_scale((vertices.z + texel.w) * ELEVATION_SCALE);
vec3 extrudedPosition = vec3(pos.xy, elevation + 1.0);
vec4 position_worldspace = vec4(extrudedPosition, 1.0);
gl_Position = project_to_clipspace(position_worldspace);
// temperature in 0-1
float temp = (texel.z - bounds2.x) / (bounds2.y - bounds2.x);
// OLD
// temp = floor((log(temp + 1.) * 3.) * 3.) / 3.;
// vColor = vec4(vec3(temp, temp, 0.8), 1);
// NEW
temp = floor(temp * 3.) / 3.;
vColor = vec4((1. - vec3(3. * temp, 0.25, 0.4)), 1);
vPosition = position_worldspace;
vNormal = vec4(normal, normals.z, 1);
vAltitude = getAltitude(positions.xy);
// out of bounds
if (texel.x == 0. && texel.y == 0. && texel.z == 0.) {
vColor.a = 0.;
}
}