Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Inconsistent Alpha from Procedural Gratings #505
I'd like to report two possible issues, both having to do with the alpha of procedurally-generated textures.
My preference would be to change the shaders so that both types of gratings produce opaque gratings. On the other hand, I recognize that CreateProceduralSineGrating has been around for a while and, if people are depending on this, it might be better to change the the SmoothedAperatureSineGrating shader to match the others.
I'm happy to contribute patches either way.
Wrt. 1, it's not a bug, it is meant to allow alpha channel modulation when one uses alpha blending. Iff alpha is actually modulated can be controlled via the 'modulateColor' parameter to Screen('DrawTexture'), e.g., a modulatecolor = [1,1,1,0]; would stop alpha-modulation.
Wrt. 2. The inconsistency should only happen if 'useAlpha' parameter is set to the non-default value of 1, which both our only demo and your script does. Here there is the question if the useAlpha 1 else code branch should be fixed in the shader to make it consistent if that is meaningfully doable, also adding the alpha Offset that i assume got accidentally stripped away? @iandol any opinion?
Changing the default behavior of the shaders after many years is not a good idea.
In any case, maybe we should document the behavior better in the help texts, as this can indeed be surprising that the modulation is essentially applied twice if one uses alpha blending, but doesn't select the modulateColor and BackgoundColor offset parameters accordingly.
Patches for that welcome.
Yes, we shouldn't change CreateProceduralSineGrating behaviour. And yes, I think it would be better to align SmoothedAperatureSineGrating to do what the normal grating shader does by default (i.e. allow alpha modulation without modulateColour applied). That is established behaviour.
I think a better description about what happens in the interactions between blending modulateColor and backgroundColor would be welcome. I suspect the fact I didn't quite understand this originally is why I wrote the smoothed edge shader the way I did (i.e. I also expected alpha applied once from the edge in where a contrast of 1 ends up looking correct)