Skip to content

Commit 00a4403

Browse files
authored
Update README.md
1 parent 6412f95 commit 00a4403

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Add the library to your source code, *after* loading p5 but *before* loading you
1818

1919
### Via CDN
2020
```html
21-
<script src="https://cdn.jsdelivr.net/npm/@davepagurek/[email protected].5/p5.Framebuffer.min.js"></script>
21+
<script src="https://cdn.jsdelivr.net/npm/@davepagurek/[email protected].6/p5.Framebuffer.min.js"></script>
2222
```
2323

2424
### Self-hosted
@@ -197,6 +197,81 @@ The library provides a helper that bundles a Framebuffer with a shader that appl
197197

198198
Create a blur renderer and draw inside its `draw` callback. When you tell it to `focusHere()`, anything drawn at that transformed position will be in focus. You can use standard p5 `translate` calls to position the focal point.
199199

200+
#### Gaussian blur
201+
202+
This is likely the best-looking blur renderer, although it uses two render passes. Start by using this one, but look out the other `BlurRenderer` if it's slow.
203+
204+
<table>
205+
<tr>
206+
<td>
207+
208+
```js
209+
let blurRenderer
210+
211+
function setup() {
212+
createCanvas(400, 400, WEBGL)
213+
blurRenderer = createGaussianBlurRenderer()
214+
blurRenderer.setIntensity(0.15)
215+
blurRenderer.setSamples(20)
216+
blurRenderer.setDof(50)
217+
}
218+
219+
function draw() {
220+
blurRenderer.draw(() => {
221+
clear()
222+
push()
223+
background(255)
224+
noStroke()
225+
lights()
226+
227+
push()
228+
fill('blue')
229+
translate(-80, -80, -300)
230+
blurRenderer.focusHere()
231+
sphere(50)
232+
pop()
233+
234+
push()
235+
fill('red')
236+
sphere(50)
237+
pop()
238+
pop()
239+
})
240+
}
241+
```
242+
243+
</td>
244+
<td>
245+
<img src="https://user-images.githubusercontent.com/5315059/201497333-92a3f46e-91b7-4d4e-a675-f958d8d9ff50.png" width="400" height="400">
246+
</td>
247+
</tr>
248+
</table>
249+
250+
Methods on `GaussianBlurRenderer`:
251+
- `GaussianBlurRenderer.prototype.draw(callback: () => void)`
252+
- Draw the scene defined in the callback with blur
253+
- `GaussianBlurRenderer.prototype.focusHere()`
254+
- Tell the renderer what point in space should be in focus. It will move based on any calls to `translate()` or other transformations that you have applied.
255+
- Defaults to the origin
256+
- `GaussianBlurRenderer.prototype.setIntensity(intensity: number)`
257+
- Control the intensity of the blur, between 0 and 1: the lower the intensity, the farther objects have to be from the focal point to be blurred
258+
- Defaults to 0.1
259+
- `GaussianBlurRenderer.prototype.setDof(dof: number)`
260+
- Control the depth of field (dof), which is the distance away from the focal point that is also in focus, from 0 up
261+
- The lower the dof, the smaller range will be that has no blur. Blur amount will start to accumulate when objects are outside of the dof range
262+
- The focal target (set by `focusHere`) is located in the centre of the clear range. So assume the focal target's depth value is `z`, then the clear range becomes from `z - dof / 2` to `z + dof / 2`.
263+
- Defaults to 0
264+
- `GaussianBlurRenderer.prototype.setSamples(numSamples: number)`
265+
- Control how many random samples to use in the blur shader. More samples will look smoother but is more computationally intensive.
266+
- Defaults to 20
267+
268+
A live example: https://davepagurek.github.io/p5.Framebuffer/examples/gaussianblur
269+
270+
271+
#### One-pass blur
272+
273+
Another implementation of blur, but using a single shader pass. This will likely produce a grainier result, but might be faster on some systems.
274+
200275
<table>
201276
<tr>
202277
<td>

0 commit comments

Comments
 (0)