codeanticode / planetarium

A Processing library for dome projection.
http://processing.andrescolubri.net/libraries/planetarium/
Other
49 stars 13 forks source link

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

Open diroru opened 6 years ago

diroru commented 6 years ago

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!

codeanticode commented 6 years ago

@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?

diroru commented 6 years ago

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!

codeanticode commented 6 years ago

@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 :-)

diroru commented 6 years ago

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