P5.js: createShader() won't apply to texture / layers, but loadShader() does...?

Created on 12 Nov 2020  路  2Comments  路  Source: processing/p5.js

Most appropriate sub-area of p5.js?

  • [x] WebGL

Details about the bug:

  • p5.js version: 1.1.9
  • Web browser and version: Chrome 86.0.4240.183
  • Operating System: MacOS 10.13.6
  • Steps to reproduce this:

Getting into shaders with p5.js = !! And ran into a strange issue while trying to use a shader as a texture of a 3d primative, rather than directly rendered. I'm trying to use vert/frag's inline, loaded as string variables on the single main p5 sketch, for the purpose of live-coding them within P5LIVE. There's no problem to load vert/frag as variable strings using createShader() within the setup(), but when trying to apply that to a texture layer, it fails. If I use loadShader() from the preload() function with external vert/frag files, then it works as expected. This might be a feature request, but seems like a bug, since I'd expect createShader() and loadShader() to behave similarly, just be built from different sources. While researching to see if the issue already came up, I found a few issues with loadShader() that told people to use the preload() function, which solved it.. unfortunately createShader() can't be used in the preload(), as it returns an error of : Uncaught TypeError: Cannot read property '_renderer' of undefined 鈥撀爏ince the _renderer must not yet be defined in preload(). Looking at the src of material.js, on line 176, is it because the createShader() is directly applied to this._renderer?? Maaybe that can be removed, or allow a custom renderer, ie the layer, to be passed in?

Examples of the issue:

bug

All 2 comments

@ffd8 I think in your example where it's failing you need to call:

theShader = tex.createShader(frag, vert); // note the tex.

@aferriss many thanks! Makes perfect sense now looking closer at all the other functions being p5.prototype.______ and using them with tex. as prefix. Somehow flew right over my head while calling createShader() to do the same.. ugh.

I'll try extending the current ref example for this function, so it's clear to the next person (or my future self).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aman-tiwari picture aman-tiwari  路  3Comments

aferriss picture aferriss  路  3Comments

b0nb0n picture b0nb0n  路  3Comments

aparrish picture aparrish  路  3Comments

kappaxbeta picture kappaxbeta  路  3Comments