Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <button id="toggle">Toggle Waves</button><br>

<div id="container" ></div>

<!-- ACTUAL CODE YOU NEED TO EDIT TO CHANGE EFFECT  -->
<script id="fragmentShader" type="x-shader/x-fragment" hidden>
        varying vec2 vUv;
        uniform vec2 u_resolution;
        uniform vec2 u_mouse;
        uniform float u_time;
        uniform float u_animation;
        uniform sampler2D texture;
        uniform sampler2D map;
        void main() {

            vec2 xy = vUv.xy / u_resolution.xy;
            float map=texture2D(map,vUv).r * u_animation;
            float m =  (u_mouse.x/u_resolution.x - 0.5) * 0.01;
            
            float frequency=100.0;
            float amplitude=0.005;
            float distortion=1.5* sin(vUv.y*frequency + u_time)*amplitude +m;
            vec4 color=texture2D(texture,vec2(vUv.x + distortion * map, vUv.y));
            gl_FragColor = vec4((1.0-map)*color.rgb+ map*vec3(color.r+color.g+color.b)/3.0,1.0);
        }
    </script>
    <script id="vertexShader" type="x-shader/x-vertex" hidden>
        varying vec2 vUv;
        void main() {
             vUv = (position.xy+1.0)*0.5;
             gl_Position = vec4(position, 1.0);
        }
    </script>

    <img src="https://cssing.org.ua/shaders/texture1.png" alt="" width="300">
<img src="https://cssing.org.ua/shaders/map2.png" alt="" width="300"><br>
<a href="https://www.youtube.com/watch?v=YEYmYI7ZpQc">Video(russian) about this technique</a>
              
            
!

CSS

              
                div,img,canvas{float:left}
body{text-align:center;margin-top:0}
button{
  padding: 10px 20px;
  margin: 10px;
}
              
            
!

JS

              
                // this is just preparing the scene, you would only need to edit the shaders in HTML
var container;
var camera, scene, renderer;
var uniforms;
var mouse = {x:0, y:0};
var loader = new THREE.TextureLoader();
loader.crossOrigin = '';
document.onmousemove = getMouseXY;
init();
animate();
function getMouseXY(e) {
    mouse.x = e.pageX;
    mouse.y = e.pageY;
    uniforms.u_mouse.value.x = mouse.x;
    uniforms.u_mouse.value.y = mouse.y;
}
        
function init() {
    container = document.getElementById( 'container' );

    camera = new THREE.Camera();
    camera.position.z = 1;
    scene = new THREE.Scene();
    var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
    uniforms = {
        u_time: { type: "f", value: 1.0 },
        u_mouse: { type: "v2", value: new THREE.Vector2() },
        u_animation: { type: "f", value: 1.0 },
        u_resolution: { type: "v2", value: new THREE.Vector2() },
        texture: {value: loader.load( "https://cssing.org.ua/shaders/texture1.png?123" ) },
        map: {value: loader.load( "https://cssing.org.ua/shaders/map2.png?123" ) }
    };
    var material = new THREE.ShaderMaterial( {
        uniforms: uniforms,
        vertexShader: document.getElementById( 'vertexShader' ).textContent,
        fragmentShader: document.getElementById( 'fragmentShader' ).textContent
    } );
    var mesh = new THREE.Mesh( geometry, material );
    scene.add( mesh );
    renderer = new THREE.WebGLRenderer();
    renderer.setPixelRatio( window.devicePixelRatio );

    container.appendChild( renderer.domElement );
    onWindowResize();
    window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize( event ) {
    renderer.setSize( 600,600 );
    uniforms.u_resolution.value.x = 600;
    uniforms.u_resolution.value.y = 600;
    uniforms.u_mouse.value.x = mouse.x;
    uniforms.u_mouse.value.y = mouse.y;
}
function animate() {
    requestAnimationFrame( animate );
    render();
}
function render() {
    uniforms.u_time.value += 0.05;
    renderer.render( scene, camera );
}


// clicking the button
var tween = new TimelineMax({paused: true})
    .to(uniforms.u_animation,1,{value: 0});

document.getElementById('toggle').addEventListener('click',function(){
  if(uniforms.u_animation.value == 1){
    tween.play();
  } else{
    tween.reverse();
  }
})
              
            
!
999px

Console