PDA

View Full Version : How to add fragment data when overlap happened?



Gomu.Wang
05-28-2010, 05:12 AM
Hi guys~

I'm doing some experiments these days and here is a question:

We assume that there are two vertexes have the same position(which means the fragments overlaped) but different texture coordinate.

Then how can I get the two fragment output data add up?

For example, vertex1 and vertex2 have same position(so they will be sent to the same fragment position) and they have output value '10' and '20' respectively.
How can I get '30' in the renderbuffer after shading?

Here is the fragment code:


#extension GL_EXT_gpu_shader4 : enable

varying out uvec4 FragOut;
uniform usampler2D Tex1;

void main(void) {
uvec4 texel = texture2D(Tex1,gl_TexCoord[0].st);

FragOut = texel;
}


If the data is simply float gl_FragCOlor, we can use GL_BLEND to achieve the addition. But now FragOut are integers so we cannot use blend function.

Thank you very much!

Alfonse Reinheart
05-28-2010, 09:47 AM
We assume that there are two vertexes have the same position(which means the fragments overlaped)

Before you get too far into that thinking, that's not how it works. Indeed, if you have two binary-identical vertices (post-vertex shader), OpenGL's rasterization rules actually forbid the implementation from generating two fragments at the same location (unless you're multisampling).


If the data is simply float gl_FragCOlor, we can use GL_BLEND to achieve the addition. But now FragOut are integers so we cannot use blend function.

Then there's nothing you can do. I'd suggest using floats and converting them to integers in a full-screen pass.

Gomu.Wang
05-29-2010, 01:33 AM
Sorry for my late reply. The cable have some problems these days~



Before you get too far into that thinking, that's not how it works. Indeed, if you have two binary-identical vertices (post-vertex shader), OpenGL's rasterization rules actually forbid the implementation from generating two fragments at the same location (unless you're multisampling).


Actually I meant that if I wrote the same data in gl_Position of different vertexes in vertex shader(these vertexes are all GL_POINT). Then how can I get their integer data(the data is from a texture) to be added up?

I'm not quite sure that I described this question clearly enough. :)

Thanks!

Alfonse Reinheart
05-29-2010, 02:07 AM
Then how can I get their integer data(the data is from a texture) to be added up?

*ahem*:


Then there's nothing you can do. I'd suggest using floats and converting them to integers in a full-screen pass.