🚚 Move shader code to GLSL files

This commit is contained in:
Simon Schneegans
2022-05-13 08:27:09 +02:00
parent 77d5de7b8e
commit 46cc997e2a
43 changed files with 1303 additions and 1334 deletions
+49
View File
@@ -0,0 +1,49 @@
cogl_color_out = vec4(0, 0, 0, 0);
float progress = uForOpening ? 1.0 - uProgress : uProgress;
// Draw the individual shard layers.
for (float i = 0; i < SHARD_LAYERS; ++i) {
// To enable drawing shards outside of the window bounds, the actor was scaled
// by ACTOR_SCALE. Here we scale and move the texture coordinates so that the
// window gets drawn at the correct position again.
vec2 coords = cogl_tex_coord_in[0].st * ACTOR_SCALE - PADDING;
// Scale and rotate around our epicenter.
coords -= uEpicenter;
// Scale each layer a bit differently.
coords /= mix(1.0, 1.0 + uBlowForce * (i + 2) / SHARD_LAYERS, progress);
// Rotate each layer a bit differently.
float rotation = (mod(i, 2.0) - 0.5) * 0.2 * progress;
coords = vec2(coords.x * cos(rotation) - coords.y * sin(rotation),
coords.x * sin(rotation) + coords.y * cos(rotation));
// Move down each layer a bit.
float gravity =
(uForOpening ? -1.0 : 1.0) * uGravity * 0.1 * (i + 1) * progress * progress;
coords += vec2(0, gravity);
// Restore correct position.
coords += uEpicenter;
// Retrieve information from the shard texture for our layer.
vec2 shardCoords = (coords + uSeed) * uSize / uShardScale / 500.0;
vec2 shardMap = texture2D(uShardTexture, shardCoords).rg;
// The green channel contains a random value in [0..1] for each shard. We
// discretize this into SHARD_LAYERS bins and check if our layer falls into
// the bin of the current shard.
float shardGroup = floor(shardMap.g * SHARD_LAYERS * 0.999);
if (shardGroup == i && (shardMap.x - pow(progress + 0.1, 2)) > 0) {
cogl_color_out = texture2D(uTexture, coords);
}
}
// Shell.GLSLEffect uses straight alpha. So we have to convert from premultiplied.
if (cogl_color_out.a > 0) {
cogl_color_out.rgb /= cogl_color_out.a;
}