kleinerm / Psychtoolbox-3

This is kleinerm's git repository for development of Psychtoolbox-3. Regular end users should stay away from it, unless instructed by him otherwise, and use the official Psychtoolbox-3 GitHub page or distribution system for production releases.
104 stars 307 forks source link

Update the SineGratingSmoothedApertureShader fragment #208

Closed iandol closed 3 years ago

iandol commented 3 years ago

This shader smooths the edge of a grating. By default useAlpha is turned OFF and smoothing uses the background color directly (alpha channel untouched). In this case no change will be seen by this fix.

However when useAlpha is turned on, the shader should use the edge modifier (Mod)on the alpha channel directly. Previously the fragment shader combined the global and local alpha ((rawAlpha * Mod) + Offset.a) causing an undesired effect (as I originally contributed this it was my bug), and the edge is not smoothed. To fix this we use the Modifier value directly (Offset.a * Mod), which allows the edge to blend properly with the underlying color while leaving the rest unaffected. When the background colour and offset are the same (as is normally the case, e.g. [0.5 0.5 0.5 1]), then useAlpha ON/OFF now looks the same. If the background colour is different to the offset, now with useAlpha=ON the edge properly smooths.

I added an optional value = 2 to Method which copies what is done in the SmoothedDiscShader.frag (option to invert the smoothing mask). Previously it accepted 0 or 1, and so there will be no change unless you explicitly set this to 2.

In addition I added the .vscode folder to .gitignore, this folder gets generated if you use VS Code or VS Codium and shouldn't be tracked in git.

kleinerm commented 3 years ago

Sounds good. I see that varying float rawAlpa is now unused. Would be good to remove it from the vertex and fragment shader.

iandol commented 3 years ago

OK, I've removed rawAlpha from the vert and frag shaders.

kleinerm commented 3 years ago

Merged, thanks.