We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! For a SSAO effect I'm storing normals on the RGB channel and depth information on the alpha channel, but I'm guessing that due to the transparency the information from objects overlaping is corrupted. Only the normal from the foremost object should prevail no matter the alpha value, instead of blending with the colors/normals from the objects behind.
When I save the normals in one pass and the depth in another one, the effect works nicely, but when using the alpha channel it doesn't work.
I have tried different combinations of gl.glDisable(GL.GL_DEPTH_TEST), gl.glEnable(GL.GL_BLEND) and gl.glBlendFunc() but none of them work as I expect.
Thanks
Answers
AFAIK, Processing always mess up w/ the alpha part in order to render a corresponding RGB opaque image.
As you seem to call OpenGL functions directly, Processing shouldn't interfere with your rendering. Could you show us your shader code?
I'm using Processing 1 + GLGraphics, rendering from a GLGraphicsOffscreen object. The depth test and blend mode are the only direct OpenGL calls.
The shader is pretty simple, just storing the information:
This is pretty standard, but I'm missing something. I tried every combination of depth test, enable/disable GL_BLEND and blend mode, and none of them seem to not blend the colors/normals from objects overlapping.
Thanks!
The following code works fine for me. It stores the screenspace position (X and Y) in the RGB channels and the depth in the alpha channel:
I'm using Processing 2.1, but the example should be downportable.
Edit: Processing's blendMode(REPLACE); should behave like: gl.glBlendFunc(GL.GL_ONE, GL.GL_ZERO);
Thanks Poersch! That solved my problem in Processing 2, only the values of the foremost object is being stored.
blendMode(REPLACE) was the correct blend mode. I looked in the Processing source and that translates into:
I tried that in Processing 1+ GLGraphics as:
but didn't work. Maybe this is not available in a GLGraphicsOffscreen @codeanticode?
@kosowski: No problem. Did you try yourOffscreenCanvas.setBlendMode(REPLACE)?
@Poersch Yes, tried that too with no luck. Anyway, one more reason to move projects to P5 2.
Yeah, porting to Processing 2.X is almost always worthwhile. It has a great set of improvements/(new features).