planetarium icon indicating copy to clipboard operation
planetarium copied to clipboard

Specifying a sampler2D along with a samplerCube in the shader breaks it.

Open diroru opened this issue 8 years ago • 4 comments

In order to implement »layered« rendering, i would like to have a background and a foreground sampler2D in the shader. When i do this, the compiler complains that i am trying to use the same texture unit. Even when i try to assign another one, it doesn’t work. Some resources say, the texture unit should be set right after linking. Is this possible with PShader or do i need fallback to JOGL, or is the problem something entirely different?

Many thanks in advance for any hints!

diroru avatar Nov 05 '17 21:11 diroru

@diroru you can set another texture unit by doing shader.set("tex", img) where img is the PImage holding the layer, is this what you tried?

codeanticode avatar Jan 10 '18 01:01 codeanticode

Hey @codeanticode, thanks for the hint; indeed, this was the approach. Alas, it generates following error message:

java.lang.RuntimeException: Cannot validate shader program:
Validation Failed: Sampler error:
  Samplers of different types use the same texture image unit.
   - or -
  A sampler's texture unit is out of range (greater than max allowed or negative).

Made a branch for it: https://github.com/diroru/planetarium/tree/bug_background_sampler.

Many thanks in advance for looking into this!

diroru avatar Jan 15 '18 13:01 diroru

@diroru this discussion on stack overflow sheds some light on the problem. Because validation in PShader happens before the texture units are bound, the compiler cannot determine if the same unit will be assigned to both the 2D and cube samplers. A hack mentioned in the stack overflow thread is to remove the validation step. I commented the validation() call in PShader, and the modified cube shader with background texture does works You could subclass PShader in planetarium, and overload the init() method.

Seems that they had the same problem with the Allosphere :-)

codeanticode avatar Jan 15 '18 16:01 codeanticode

Thank you very much! Will look into it. Cheers!

diroru avatar Jan 19 '18 12:01 diroru