Skip to content

Commit

Permalink
[Feature] allow uploading custom textures
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Oct 20, 2023
1 parent dc4e362 commit 98344eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ShaderToyLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 98344eb

Please sign in to comment.