-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for float textures + an example
- Loading branch information
1 parent
347c052
commit 53b92e7
Showing
7 changed files
with
140 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"useTabs": false, | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 80, | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html><html lang="en"><head> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script> | ||
<script src="../../p5.Framebuffer.js" type="text/javascript"></script> | ||
<link rel="stylesheet" type="text/css" href="style.css"> | ||
<meta charset="utf-8"> | ||
|
||
</head> | ||
<body> | ||
<script src="sketch.js"></script> | ||
|
||
|
||
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
let fboPrev, fboNext | ||
let canvas | ||
|
||
function setup() { | ||
canvas = createCanvas(400, 400, WEBGL) | ||
// There's a bug in Firefox where you can only make floating point textures | ||
// if they're RGBA, and it breaks if it's just RGB | ||
setAttributes({ alpha: true }) | ||
|
||
// Try changing `float` to `unsigned_byte` to see it leave a trail | ||
options = { colorFormat: 'float' } | ||
fboPrev = createFramebuffer(options) | ||
fboNext = createFramebuffer(options) | ||
imageMode(CENTER) | ||
rectMode(CENTER) | ||
noStroke() | ||
} | ||
|
||
function draw() { | ||
// Swap prev and next so that we can use the previous frame as a texture | ||
// when drawing the current frame | ||
[fboPrev, fboNext] = [fboNext, fboPrev] | ||
|
||
// Draw to the Framebuffer | ||
fboNext.draw(() => { | ||
clear() | ||
|
||
background(255) | ||
|
||
// Disable depth testing so that the image of the previous | ||
// frame doesn't cut off the sube | ||
_renderer.GL.disable(_renderer.GL.DEPTH_TEST) | ||
push() | ||
scale(1.003) | ||
texture(fboPrev.color) | ||
plane(width, -height) | ||
pop() | ||
|
||
push() | ||
// Fade to white slowly. This will leave a permanent trail if you don't | ||
// use floating point textures. | ||
fill(255, 1) | ||
rect(0, 0, width, height) | ||
pop() | ||
_renderer.GL.enable(_renderer.GL.DEPTH_TEST) | ||
|
||
push() | ||
normalMaterial() | ||
translate(100*sin(frameCount * 0.014), 100*sin(frameCount * 0.02), 0) | ||
rotateX(frameCount * 0.01) | ||
rotateY(frameCount * 0.01) | ||
box(50) | ||
pop() | ||
}) | ||
|
||
clear() | ||
push() | ||
texture(fboNext.color) | ||
plane(width, -height) | ||
pop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
canvas { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@davepagurek/p5.framebuffer", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "p5.Framebuffer.js", | ||
"author": "Dave Pagurek <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -14,7 +14,8 @@ | |
"homepage": "https://github.com/davepagurek/p5.Framebuffer", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"minify": "^9.0.0" | ||
"minify": "^9.0.0", | ||
"prettier": "^2.7.1" | ||
}, | ||
"scripts": { | ||
"build:core": "minify p5.Framebuffer.js > p5.Framebuffer.core.min.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters