Am 08.11.2013 12:02, schrieb Bram Vaessen:
Also, Do you setup a blendfunction and activate it for the stateset?

No I didn't. The thing is, I made some other shaders for a volume light, and 
there I just enabled blending and it worked as I expected. And to clarify what 
I mean with that: I thought that normal 'standard' blending involved mixing the 
colors something like this:

mix(source.rgb, dest.rgb, dest.a). so in other words, it would use the rgb in 
the framebuffer and mix the color of the new pixels based on the alpha of the 
new pixel (ignoring the alpha value from the source pixel).
You're mixing up source and destination. Source is the incoming color (i.e. the color written in the shader), destination the color in the buffer (i,e, what was already in the target buffer).
Simple blendigng works with two parameters:

First parameter is the source factor, the second the destination factor,
So for instance glBlendFunc(GL_ONE, GL_ZERO) would take the source * 1.0 and the target * 0.0. Effectively overwritting the buffer. (mix(source.rgb, target, 0.0)) glBlendFunc(GL_ONE, GL_ONE) therefore would give you mix(source, target, 0.5)

There are more parameters which don't use a simple factor, but the source and destination colors/alphas to scale contribution of the written result. The OpenGL specification shows how to use them to get an appropriate result. So you'll have to dig into this.

Anyways, some combinations are not valid. For instance you cannot scale your src with GL_SRC_COLOR.




I don't understand what you mean? Can you point to the blendfunction here?
There is no simple way to blend onyl gl_FragData[0] without touching the
other buffers.

I guess, now I looked at the blend functions of opengl better (sorry I'm kinda 
new with opengl), that I would like a glBlendFunc(GL_ONE_MINUS_DST_ALPHA, 
GL_DST_ALPHA);

Does that make sense? that matched with I said above right?
Somehow. Frankly I have to look up the correct blending function every time I do something out of the ordinary.
If I'm not mistaken the above equation will effectively write.
vec4(1 - source.a) * source.rgba + vec4(dst.a) * dst.rgba


Another thing to mention is
glBlendFuncSeparate. In OSG its simply the blendfunc with four parameters.
It allows to set different factors for rgb and alpha values. So this sounds what you're after.

My suggestion here is to start with a simple task to get used to the different blending modes. I found them counter-intuitive in the beginning, but actually they are designed pretty smart ;-)





As said before: Blending function is applied to all bound
buffers.


what about glBlendFunci, which enabled different blendings per buffer... or is 
that not supported?
I asked this a while ago. There is no function prototype, so it has to be added to the extensions somehow I guess....


So could try to post your buffer setup and your passes or at least
create a minimalistic example showing your problem?
A little more context on what you are trying to achieve would be helpful too

I will try to post some code tonight if needed, don't have access to it right 
now.

For context: I am rendering terrain with water. the surface of the water is 
partly transparant. for the part underwater I want to use some form of fog 
effect and for the part above water I use some other 3d fog effect. So if the 
camera is above water and look at the water it need to do the following for 
each pixel:
-start with the terrain color (from rendered terrain)
-apply underwater effect
-apply the semi-transparent water-surface pixel (from rendered water)
-apply above water fog effect

So the thing is: I need both the original rendered terrain pixel and also the 
original rendered water-surface pixel.
so that is why I want to render my terrain and my water-surface to two separate 
buffers, so that in the 'final' shader (the deffered one or however you call 
it) I have access to both the rendered water and the rendered terrain under 
that water and calculate the final pixel in a way that I find logical. I 
understand that there might be tons of other ways to do this, but as I'm pretty 
new I hope to do things first in a way which seems logical to me, before doing 
it some other way that is harder to understand for me. But still if you have a 
better idea on how to do what I want I'm open for it :)

If I got this correctly, you have your terrain-buffer in one texture and your water result in another. Then you don't need hw-blending to combine them. The pass would simply take both inputs and you can mix them freely and write it to your destination buffer. The destination however cannot be one of the bound textures. So if you want to reuse one of the buffers as final one. you'll have to go with blending.

But seriously, this seems a lot to swallow given your just starting to use OSG/OpenGL. Start off with a simpler example to get the blending things right ;-)

hth,
cheers
Sebastian

Hope I explained this clear enough!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=57134#57134





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to