diff --git a/resources/shaders/portal.frag b/resources/shaders/portal.frag index d1b623b..92c12e1 100644 --- a/resources/shaders/portal.frag +++ b/resources/shaders/portal.frag @@ -15,6 +15,7 @@ // The content from common.glsl is automatically prepended to each shader effect. uniform vec3 uColor; +uniform vec2 uSeed; const float PORTAL_OPEN_TIME = 0.3; const float PORTAL_WOBBLE_TIME = 0.8; @@ -60,8 +61,8 @@ float getPortalScale() { // Returns a random 2D vector in [(-0.5, -0.5) ... (0.5, 0.5)] using two time simplex // noise. The scale of the noise can be adjusted with the scale paramter. vec2 getRandomDisplace(vec2 seed, float scale) { - return vec2(simplex2D(seed * scale) - 0.5, - simplex2D(seed * scale + vec2(7.89, 123.0)) - 0.5); + return vec2(simplex2D(seed * scale + uSeed) - 0.5, + simplex2D(seed * scale + uSeed + vec2(7.89, 123.0)) - 0.5); } // Twists the given coordinates around the origin. The speedMultiplier can be used to @@ -116,7 +117,7 @@ vec4 getPortalColor() { // ---------------------------------------------------------------------------- 2. layer // Then we add the first layer of whirly bands. - float noise = simplex2D(layerCoords / detailScale * 1.0 + vec2(12.3, 56.4)); + float noise = simplex2D(layerCoords / detailScale * 1.0 + vec2(12.3, 56.4) + uSeed); vec4 layer = vec4(darken(uColor, 0.3), noise > 0.6 ? alpha : 0.0); color = alphaOver(color, layer); @@ -126,7 +127,7 @@ vec4 getPortalColor() { layerCoords = getWhirledCoords(coords - wobble * 1.5, 1.5, 0.5); displace = getRandomDisplace(layerCoords, 12.2); layerCoords += displace * 0.1; - noise = simplex2D(layerCoords / detailScale * 1.3); + noise = simplex2D(layerCoords / detailScale * 1.3 + uSeed); layer = vec4(uColor, noise > 0.6 ? alpha : 0.0); color = alphaOver(color, layer); @@ -145,7 +146,7 @@ vec4 getPortalColor() { // ---------------------------------------------------------------------------- 5. layer // Finally, we add some sparkling lights. layerCoords = getWhirledCoords(coords - wobble * 1.8, 2.5, 0.0); - noise = simplex2D(layerCoords / detailScale * 3.0); + noise = simplex2D(layerCoords / detailScale * 3.0 + uSeed); layer.rgb = lighten(uColor, 0.5) * clamp(pow(noise * rand + 0.9, 50.0), 0.0, 1.0); color.rgb += layer.rgb; diff --git a/src/Portal.js b/src/Portal.js index b9476ee..feca74c 100644 --- a/src/Portal.js +++ b/src/Portal.js @@ -44,13 +44,18 @@ var Portal = class { // Store uniform locations of newly created shaders. shader._uColor = shader.get_uniform_location('uColor'); + shader._uSeed = shader.get_uniform_location('uSeed'); // Write all uniform values at the start of each animation. shader.connect('begin-animation', (shader, settings) => { const c = Clutter.Color.from_string(settings.get_string('portal-color'))[1]; + // If we are performing an integration tests, we use a fixed seed. + const testMode = settings.get_boolean('test-mode'); + // clang-format off shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]); + shader.set_uniform_float(shader._uSeed, 2, [testMode ? 0 : Math.random(), testMode ? 0 : Math.random()]); // clang-format on }); });