You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Specify whether to use floating point storage for the color texture
80
+
- Defaults to `'unsigned_byte'`
81
+
- Note: If you use floating point colors, in Firefox you must also call `setAttributes({ alpha: true })`
82
+
76
83
Notes:
77
84
-`draw()` uses the same p5 context as the rest of your sketch! Make sure to wrap your callback code in a `push()` and `pop()` to ensure your settings don't leak out into your non-Framebuffer code.
78
85
- When you `resizeCanvas`, the Framebuffer will automatically resize accordingly. You probably will want to clear it and redraw to it if you had a texture cached.
79
86
80
87
A live example: https://davepagurek.github.io/p5.Framebuffer/examples/simple
81
88
89
+
### Floating point textures
90
+
91
+
Sometimes, you want to write code that adds on to or modifies the previous frame. You may notice weird artifacts that show up due to the fact that colors are internally stored as integers: sometimes if you overlay a color with a very small alpha, the change in color is too small to round the resulting color up to the next integer value, so it doesn't change at all.
92
+
93
+
This can be fixed if you store colors as floating point values! You can specify this in an optional options object when creating a Framebuffer object.
94
+
95
+
<table>
96
+
<tr>
97
+
<tdrowspan="4">
98
+
99
+
```js
100
+
let fboPrev, fboNext
101
+
let canvas
102
+
103
+
functionsetup() {
104
+
canvas =createCanvas(400, 400, WEBGL)
105
+
// There's a bug in Firefox where you can only make floating point textures
106
+
// if they're RGBA, and it breaks if it's just RGB
107
+
setAttributes({ alpha:true })
108
+
109
+
// Try changing `float` to `unsigned_byte` to see it leave a trail
110
+
options = { colorFormat:'float' }
111
+
fboPrev =createFramebuffer(options)
112
+
fboNext =createFramebuffer(options)
113
+
imageMode(CENTER)
114
+
rectMode(CENTER)
115
+
noStroke()
116
+
}
117
+
118
+
functiondraw() {
119
+
// Swap prev and next so that we can use the previous frame as a texture
120
+
// when drawing the current frame
121
+
[fboPrev, fboNext] = [fboNext, fboPrev]
122
+
123
+
// Draw to the Framebuffer
124
+
fboNext.draw(() => {
125
+
clear()
126
+
127
+
background(255)
128
+
129
+
// Disable depth testing so that the image of the previous
130
+
// frame doesn't cut off the sube
131
+
_renderer.GL.disable(_renderer.GL.DEPTH_TEST)
132
+
push()
133
+
scale(1.003)
134
+
texture(fboPrev.color)
135
+
plane(width, -height)
136
+
pop()
137
+
138
+
push()
139
+
// Fade to white slowly. This will leave a permanent trail if you don't
- Specify whether to use floating point storage for the color texture
191
+
- Defaults to `'unsigned_byte'`
192
+
- Note: If you use floating point colors, in Firefox you must also call `setAttributes({ alpha: true })`
193
+
82
194
### Depth of field blur
83
195
84
196
The library provides a helper that bundles a Framebuffer with a shader that applies focal blur, leaving objects at a provided distance in focus and blurring things more the farther away from that point they are.
0 commit comments