Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

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

Open
diroru opened this issue Nov 5, 2017 · 4 comments

Comments

@diroru
Copy link
Contributor

diroru commented Nov 5, 2017

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
Copy link
Owner

codeanticode commented Jan 10, 2018

@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
Copy link
Contributor Author

diroru commented Jan 15, 2018

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
Copy link
Owner

@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
Copy link
Contributor Author

diroru commented Jan 19, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants