Blend function - please help (MATLAB 2020b)
7 views (last 30 days)
Show older comments
Hi,
Could someone clarify to me what the function below is needed for when setting up a script to run a stroop task?
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
Many thanks in advance.
0 Comments
Answers (1)
Walter Roberson
on 29 Oct 2020
"The most common alpha-blending factors are sourceFactorNew = GL_SRC_ALPHA and destinationFactorNew = GL_ONE_MINUS_SRC_ALPHA They are needed for proper anti-aliasing (smoothing) by Screen(‘DrawLines’), Screen(‘DrawDots’) and for drawing masked stimuli with the Screen(‘DrawTexture’) command."
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
is telling Psychtoolbox to use compute:
information to store = new screen data * alpha + old screen data * (1-alpha)
so for example if alpha were .8 then it would be new*0.8 + old*0.2
2 Comments
Thomas Pace
on 16 Feb 2021
So if, for example, I wanted to present 4 textures using Screen('DrawTexture') in the same location, and have them all end up with equal alpha, what is the formula I would use for dictating each textures globalAlpha values?
For example, if globalAlpha (GA) for the first texture drawn was set at 1, I assumed the second texture drawn on top would need to be presented with GA of 0.5. But then what would the third texture drawn GA be such that all 3 have equally presented energy? Is there a formula for this?
Walter Roberson
on 16 Feb 2021
Edited: Walter Roberson
on 16 Feb 2021
syms I1 I2 I3 I4 a1 a2 a3
t1 = I1*(1-a1) + I2*a1
t2 = t1*(1-a2) + I3*a2
t3 = t2*(1-a3) + I4*a3
t4 = collect(expand(t3),[I1,I2,I3,I4])
c1 = coeffs(t4,I1)
c2 = coeffs(t4,I2)
c3 = coeffs(t4,I3)
c4 = coeffs(t4,I4)
sol = solve([c1(end),c2(end),c3(end)]==1/4,[a1,a2,a3])
sol.a1
sol.a2
sol.a3
%cross-check
subs([c1(end),c2(end),c3(end),c4(end)], sol)
So use alpha = 1/2 for the first overlay, alpha = 1/3 for the second overlay, alpha = 1/4 for the third overlay.
See Also
Categories
Find more on Image display and manipulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!