Code Monkey home page Code Monkey logo

shadertoylite.js's Introduction

ShaderToyLite.js is a full featured ShaderToy renderer, in ~400 lines of code.

Demo

ShaderToyLite-demo.html

^ This demo renders Paint Streams by Michael Moroz

Note: iOS has rendering artifcacts due to texelFetch not being fully supported

Features

  • direcly load any ShaderToy shaders (except sound & vr) without modification
  • supports buffer shaders (i.e BufferA, BufferB, BufferC, BufferD)
  • pixel perfect rendering
  • supports all uniforms
  • upload your own textures
  • shader common code (i.e. 'Common' tab in ShaderToy)
  • update shaders at any time
  • uses the same texture format as ShaderToy (RGBA float32)
  • WebGL 2.0 (only)

Not Supported:

  • VR, Sound, Keyboard
  • pre-provided textures ('Wood', 'Rock Tiles', etc)

Usage

// initialize
var toy = new ShaderToyLite('myCanvas');

// add webgl textures (optional)
toy.addTexture(texture, 'rock');

// set shaders
toy.setCommon("");
toy.setBufferA({source: bufferA, iChannel0: 'rock'});
toy.setImage({source: image, iChannel0: 'A'});

// draw callback (optional)
toy.setOnDraw((){
    console.log(toy.getTime());
})

// start render loop
toy.play();

// pause render loop
toy.pause();

// currently playing?
tod.getIsPlaying();

// reset time to zero
toy.rewind();

Minimal Example

Minimal example showing multiple buffer usage.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ShaderToyLite</title>
</head>
<body>
    <canvas id="myCanvas" width="840" height="472"></canvas>
    <script>
    var a = `
    void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
        vec2 uv = fragCoord/iResolution.xy;
        vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
        fragColor = vec4(col,1.0);
    }
    `;
    var image = `
    void mainImage( out vec4 fragColor, in vec2 fragCoord ) {  
        vec2 uv = fragCoord.xy / iResolution.xy;
        vec4 col = texture(iChannel0, uv);
        fragColor = vec4(col.rgb, 1.);
    }
    `;
    var toy = new ShaderToy('myCanvas');
    toy.setCommon('');
    toy.setBufferA({source: a});
    toy.setImage({source: image, iChannel0: 'A'});
    toy.play();
    </script>
</body>
</html>

shadertoylite.js's People

Contributors

chipweinberger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bradparks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.