Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
how to get the texture of a shader in p5js

I have two simple shaders in p5js, and I'd like to pass the output of the first as a texture input on the second.

I thought hacking the camera example would do the trick but I can't find how to retrieve the texture of the first shader.

My naïve implementation doesn't work :

  ...
  shader2.setUniform('tex0', shader1);
  ...
// get texture from previous shader
uniform sampler2D tex0;

// grab texcoords from vert shader
varying vec2 vTexCoord;

void main() {
    vec2 uv = vTexCoord;
    uv.y = 1.0 - uv.y;
    vec4 tex = texture2D(tex0, uv);
    gl_FragColor = vec4(tex.rgb, 1.0);
}

error :

Uncaught TypeError: o is undefined
    Texture http://127.0.0.1:5500/libraries/p5.min.js:3
    getTexture http://127.0.0.1:5500/libraries/p5.min.js:3
    setUniform http://127.0.0.1:5500/libraries/p5.min.js:3
    draw http://127.0.0.1:5500/sketch.js:24
    redraw http://127.0.0.1:5500/libraries/p5.min.js:3
    _draw http://127.0.0.1:5500/libraries/p5.min.js:3
    _draw http://127.0.0.1:5500/libraries/p5.min.js:3
    _draw http://127.0.0.1:5500/libraries/p5.min.js:3
    _draw http://127.0.0.1:5500/libraries/p5.min.js:3
    _runIfPreloadsAreDone http://127.0.0.1:5500/libraries/p5.min.js:3
    _decrementPreload http://127.0.0.1:5500/libraries/p5.min.js:3
    t http://127.0.0.1:5500/libraries/p5.sound.min.js:2
    promise callback* http://127.0.0.1:5500/libraries/p5.sound.min.js:2
    _ http://127.0.0.1:5500/libraries/p5.min.js:3
    _ http://127.0.0.1:5500/libraries/p5.min.js:3
    [261]</< http://127.0.0.1:5500/libraries/p5.min.js:3
    promise callback*[261]< http://127.0.0.1:5500/libraries/p5.min.js:3
    u http://127.0.0.1:5500/libraries/p5.min.js:3
    u http://127.0.0.1:5500/libraries/p5.min.js:3
    [248]< http://127.0.0.1:5500/libraries/p5.min.js:3
    u http://127.0.0.1:5500/libraries/p5.min.js:3
    i http://127.0.0.1:5500/libraries/p5.min.js:3
    <anonymous> http://127.0.0.1:5500/libraries/p5.min.js:3
    <anonymous> http://127.0.0.1:5500/libraries/p5.min.js:3
    <anonymous> http://127.0.0.1:5500/libraries/p5.min.js:3

I'm not even sure what I'm trying to do is possible with p5

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're missing a step here : you can't pass the shader object directly to an other shader. You should create an offscreen graphics buffer with createGraphics (doc) , apply the first shader to it, then pass the buffer to the second shader.

ex:

setup(){
  // ...
  buffer = createGraphics(width, height, WEBGL);
  // ...
}
draw(){
  // ...
  buffer.shader(shader1);
  buffer.rect(0,0,width, height);
  shader2.setUniform('tex0', buffer);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!