Hello! I’m stuck with a blending issue, hope someone can give me a clue!
I’m trying to render a simulation of row of arches with light beams coming out of them. For the light beams I just render cylinder-shaped meshes. The problem is that the blending seems inconsistent based on the angle from which the camera points at the structure.
In the below image #1 (actual image of the current state of my app) the top left view is pretty close to what I want, but the top right view (where the camera faces the structure from the other direction) you can see the blending issue I’m struggling with (transparent parts of the light beams seem to be blocking the light beams behind them).
image #1:
In the first image (above) all light beams are rendered as one big single BatchRef (generated from my custom geom::Source class).
In the below images each “arch” of beams is a separate BatchRef, and the meshes are generated by cinder’s geom::Cone Source class (I’m trying to isolate the problem by not using my custom geom class and using separate batches for rendering).
In the below images #2 and #3 I’m using the normals as color and setting the alpha to a constant 0.5 value in the fragment shader.
In #2 the cones seem almost solid, only showing transparency with the gray structure (separate mesh, rendered first) and a little bit with some of the beams from its own mesh, but NOT with the beams in the meshes behind them.
image #2
image #3 (same scene as #2 but camera again from the other side); this is closer to what I’d want, with more transparency all around.
Finally for good measure two images similar to #2 and #3, but with a single constant color, set in the fragment shader;
image #4 (like #2 but with solid color and again 0.5 alpha);
image #5 (like #3 but with solid color and again 0.5 alpha);
Finally here is the render method of a single group of beams.
Note that;
- all light-beam batches are rendered immediately after each other
- all rendering goes into an fbo, which is then rendered to the screen (I do this for the split-screen as seen in image #1)
- depth testing is enabled
- I’ve tried different blending options, but in image #2 to #5 they were always
“GL_SRC_ALPHA” (source) and GL_ONE_MINUS_SRC_ALPHA (dest).
void BeamGroup::draw() const {
ci::gl::ScopedDepth scpDepth(bDepthTestEnabled);
ci::gl::ScopedBlend scpBlend(mBlendSrc, mBlendDest);
ci::gl::pushMatrices();
ci::gl::scale(ci::vec3(3.0f));
mTexture->bind();
mBatch->draw();
ci::gl::popMatrices();
}
}
Here is my fragment shader as used for images #4 and #5;
#version 150
in vec4 Color;
in vec3 Normal;
out vec4 oColor;
void main( void )
{
oColor = vec4(1, 0.5, 0.2, 0.5);
}
Hope this makes sense. All suggestions are appreciated!