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 2c4ebf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 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,12 +32,15 @@
// 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
// draw callback (optional)
toy.setOnDraw((){
console.log(toy.getTime());
})
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 2c4ebf8

Please sign in to comment.