From 98344eb1da8d37e847138e4e1ebdba41b3e68bfa Mon Sep 17 00:00:00 2001 From: Chip Weinberger Date: Fri, 20 Oct 2023 11:44:02 -0700 Subject: [PATCH] [Feature] allow uploading custom textures --- README.md | 8 ++++++-- ShaderToyLite.js | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a64a4e..ce46d3d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ - direcly load *almost* any ShaderToy shaders - pixel perfect rendering - supports all uniforms -- multipass shaders (i.e BufferA, BufferB, BufferC, BufferD) +- upload your own textures +- shader buffers (i.e BufferA, BufferB, BufferC, BufferD) - shader common code (i.e. 'Common' tab in ShaderToy) - update shaders at any time - uses the same texture format as ShaderToy (RGBA float32) @@ -31,9 +32,12 @@ // initialize var toy = new ShaderToyLite('myCanvas'); +// add webgl textures (optional) +toy.addTexture(texture, 'rock'); + // set shaders toy.setCommon(""); -toy.setBufferA({source: bufferA}); +toy.setBufferA({source: bufferA, iChannel0: 'rock'}); toy.setImage({source: image, iChannel0: 'A'}); // optional callback diff --git a/ShaderToyLite.js b/ShaderToyLite.js index d73247c..9bea6e0 100644 --- a/ShaderToyLite.js +++ b/ShaderToyLite.js @@ -385,6 +385,11 @@ function ShaderToyLite(canvasId) { this.setOnDraw = (callback) => { onDrawCallback = callback; } + + this.addTexture = (texture, key) => { + atexture[key] = texture; + btexture[key] = texture; + } this.getTime = () => { return (prevDrawTime - firstDrawTime) * 0.001;