Skip to content

Commit bf13149

Browse files
committed
uniformTexture(originalImage) not getter
1 parent 307e7a9 commit bf13149

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/content/tutorials/en/intro-to-p5-strands.mdx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -612,31 +612,21 @@ function draw() {
612612
We do this by calling the following in the function we pass to `buildFilterShader()`:
613613

614614
```js
615-
const ogImage = uniformTexture(getOriginalImage)
615+
const ogImage = uniformTexture(originalImage)
616616
```
617617

618618
This line does two things, representing the two halfs of a bridge between your sketch and your shader:
619619

620620
1. It declares a uniform variable in the shader called `ogImage` which expects to receive a value from outside the shader.
621-
2. It causes your sketch to set that uniform variable **every frame** using [setUniform()](https://beta.p5js.org/reference/p5.Shader/setUniform/) on the shader. The given function (`getOriginalImage`) will be called each frame to decide the value to be passed to setUniform.
622-
623-
For step 2, perhaps it is helpful to _imagine_ the following code being run each frame:
624-
```js
625-
bloomShader.setUniform("ogImage", getOriginalImage())
626-
```
627-
(You shouldn't _write_ the above code - something like it is written and run for you, behind the scenes).
621+
2. It causes your sketch to set that uniform variable **every frame** using [setUniform()](https://beta.p5js.org/reference/p5.Shader/setUniform/) on the shader, passing the value of `originalImage`.
628622

629623
Here's our `bloomCallback` function with this original canvas image being received by the shader and sampled from:
630624

631625
```js
632-
function getOriginalImage(){
633-
return originalImage;
634-
}
635-
636626
function bloomCallback() {
637627
// Receive the original image for use
638628
// in our shader.
639-
const ogImage = uniformTexture(getOriginalImage)
629+
const ogImage = uniformTexture(originalImage)
640630

641631
filterColor.begin();
642632
// Get our textures converted into
@@ -662,14 +652,10 @@ function bloomCallback() {
662652
let bloomShader;
663653
let originalImage;
664654
665-
function getOriginalImage(){
666-
return originalImage;
667-
}
668-
669655
function bloomCallback() {
670656
// Receive the original image for use
671657
// in our shader.
672-
const preBlur = uniformTexture(getOriginalImage);
658+
const preBlur = uniformTexture(originalImage);
673659
674660
filterColor.begin();
675661
const blurred = getTexture(filterColor.canvasContent,
@@ -820,12 +806,8 @@ For more resources on shaders, try:
820806
filterColor.end();
821807
}
822808
823-
function getOriginalImage(){
824-
return originalImage;
825-
}
826-
827809
function bloomShaderCallback() {
828-
const preBlur = uniformTexture(getOriginalImage);
810+
const preBlur = uniformTexture(originalImage);
829811
830812
filterColor.begin();
831813
const blurredCol = getTexture(

0 commit comments

Comments
 (0)