What color does a fragment get if there are two vertices at the very same position with two different colors?

0

I have a question concerning the OpenGL rendering pipeline.

I have recently been reading theory about the GLSL's Geometry Shader. I think I do understand the basics of how to emit new geometry and assign colors to the new vertices. I am, however, not sure what color a fragment would get if one of those new vertices would have the very same position as one coming in from the Vertex shader.

Consider this example: I far as I understand it, I am able to handle a single vertex with the Vertex shader. I make some transformation and store the position in glPosition. It is furthermore possible to assign a color to that vertex, e.g. by storing it to glFrontColor. As an example, I give it the color red. If all channels have 32 bits, that would be 0xFFFFFFFF'00000000'00000000'00000000, right?. Next, Geometry shader is involved. I want my geometry shader to emit some additional vertices. At least one of them is at the very same position as the original vertex coming in from the Vertex shader. However, it is assigned another color, e.g. green. That would be 0x00000000'FFFFFFFF'00000000'00000000, right? Sooner or later, after every vertex has been dealt, the rasterization takes place. As I understand, both vertices are rasterized and will therefore become the very same fragment. So, there we go. What color will that particular fragment get? Is there some kind of automatic blending and the fragment becomes yellow? Or is red or rather green?

This question might be silly. But I am simply not clear on that and would appreciate if somebody could clarify that for me.

If there is no blending (which I assume), how could I possibly create a blending effect?

opengl
glsl
shader
geometry-shader
asked on Stack Overflow Nov 10, 2010 by Walter • edited Sep 4, 2019 by genpfault

2 Answers

2

Assuming you're rendering points (which seems to be what you're describing), the two vertices with the different colors will result in two fragments (one for each vertex) at the same location. What final color will be written to the output depends on the Z values for each, the blending function set and the order in which they are processed (which is effectively random -- you can't count on either order unless you do some extra sync stuff, so you need to set your blend func/Z-culling such that it doesn't matter).

answered on Stack Overflow Nov 10, 2010 by Chris Dodd
0

I think they will be Z-Fighting, if they have the exact same values for x y and z.

About blending:

This is separate from the programmable pipeline, so you don't have to do most of the work in the shaders for it. First enable blending with glEnable(GL_BLEND), then specify your desired blending function with glBlendFunc, most commonly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Now the vertices only need an alpha value set at gl_FragColor.a and their color will blend.

answered on Stack Overflow Nov 10, 2010 by Vincent K • edited Nov 11, 2010 by Vincent K

User contributions licensed under CC BY-SA 3.0