Weird OpenGL alpha issue (jit.gl.gridshape color)

Ben Silverman's icon

When I set a jit.gl.gridshape's color to have a semi-transparent alpha channel, I get some weird kind of artifacting or lighting malfunction. Any ideas why this may be happening?

Here's what I've coded in the patch:

I'm new to OpenGL so any help would be greatly appreciated!

Graham Wakefield's icon

When the shape has transparency you can see the back faces as well as front faces. There's an attribute of jit.gl objects that can turn back faces off, but this may not completely remove the double paint on edges or for complex objects; it just checks a face to see whether the normal points toward or away from the camera.

An additional problem is that you may be hitting the resolution of the depth buffer. Try increasing the @near_clip or reducing the @far_ clip on your camera/render object. E.g. upping the near clip from say 0.001 to 0.1 can make a massive difference.

Thirdly, bear in mind that in opengl the order in which objects are rendered can affect transparency. Too long a topic for me to explain on my phone, but generally a safe option is to render all non transparent objects first (use @layer to control render order) with depth writing on, then render transparent objects using additive blending and depth writing turned off. Can't remember the attribute names and I'm on my phone, but it should be obvious in the docs/reference. And Google for more opengl depth and transparency strategies.

Graham

Rob Ramirez's icon

yeah, probably just need to turn off back faces with @cull_face 1