Using Screen(‘DrawTexture’) and globalAlpha to draw multiple orientated gratings in same location with equal luminance

I wish to present a vertical, horizontal, diagonal right and diagonal left oriented grating texture in the same location at the same time, such that each texture has equal luminance. However, when drawing to the same location, the last texture will be the only texture visible if all have equal globalAlpha.
I am wondering what the rule is for globalAlpha such that each texture can be presented with equal luminance in the same location (so, the first texture drawn has equal luminance to the last).
For example, if I draw a vertical texture with globalAlpha=1, and in the next line of code, draw a horizontal texture in the same location, I presume the globalalpha for horizontal should be given as 0.5. That would mean that both vertical and horizontal textures are equally presented on screen.
However, what happens if I want to draw multiple (i.e. 4) textures, one on top of the other? So 4 lines of code, all using “Screen(‘DrawTexture’)”, each drawing a differently oriented grating.
What is the rule (if any) when drawing textures over one another, so that the end result is that they are all equally presented on screen?

Thanks for any help

Read about opengl blending equations/functions, and make sure you set one with screen(‘blendfunction’) (or something like that, I’m on my phone and can’t check). Then you can work it out. If you don’t set a ‘blendfunction’, then globslalpha does nothing. For equal luminance and two textures, you’d draw the back one with alpha of 1 and front one with .5, assuming blend function of alpha,1-alpha

Thanks for your reply.
I have set the screen as screen(‘blendfunction’).
I understand that if I draw the back texture with alpha of 1, and the front one with .5, they will have equal luminance.
But what I am not sure about is when we go beyond 2 textures drawn back to back. So if I have a third texture on top of the previous 2, what alpha would I make that, so that all 3 have equal luminance?

Have you looked at AdditiveBlendingForLinearSuperPositionTutorial.m ? Or GarboriumDemo.m / ProceduralGarboriumDemo.m? Those are about what you try to do afaiu. Also the ECVP2013 tutorial in PsychDocumentation/ had some bits about alpha blending.

1 Like

Ok thank you very much, I will look into these