Re: [osg-users] blending on multiple targets
Hi, thanks for the reply! I get the undefined part, that makes sense, but what I still don't understand though: I just specify blending (GL_BLEND on) is on in the nodes. But then if I do gl_FragData[0] = vec4(0,0,0,0); then it doesn't seem to matter anymore what I write to gl_FragData[1[ trough gl_FragData[3], because it doesn't seem to write anything to the other buffers, or at least I noticed that the alpha value from fragdata 0 seems to have an effect on what happens with fragdate 3 in my tests. In my test if I set gl_FragData[0] = vec4(0,0,0,0);, then fragdata 3 is also not updated, even if I write a pixel with alpha value 1 to it, vec4(1,0,0,1) for example. to clarify further, what I would like is to use the destination blend, so it should only use the alpha from my new pixels to blend, and that goes for all buffers. And obviously the alpha value from the fragdata 0 should not effect the other buffers. What would I need to set in osg to make it so? Thank you! Cheers, Bram -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57124#57124 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] blending on multiple targets
Hi Bram, Hi, thanks for the reply! I get the undefined part, that makes sense, but what I still don't understand though: I just specify blending (GL_BLEND on) is on in the nodes. But then if I do gl_FragData[0] = vec4(0,0,0,0); then it doesn't seem to matter anymore what I write to gl_FragData[1[ trough gl_FragData[3], because it doesn't seem to write anything to the other buffers, or at least I noticed that the alpha value from fragdata 0 seems to have an effect on what happens with fragdate 3 in my tests. In my test if I set gl_FragData[0] = vec4(0,0,0,0);, then fragdata 3 is also not updated, even if I write a pixel with alpha value 1 to it, vec4(1,0,0,1) for example. Sorry but you are not nearly providing enough context to understand what you are really doing here. First of all: In order to get blending working your buffers need to have alpha (GL_RGBA). Also, Do you setup a blendfunction and activate it for the stateset? I prefer to set the blending at the off-screen camera btw. to clarify further, what I would like is to use the destination blend, so it should only use the alpha from my new pixels to blend, and that goes for all buffers. And obviously the alpha value from the fragdata 0 should not effect the other buffers. 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. As said before: Blending function is applied to all bound buffers. So design your passes in a way that only the buffer to be blended is bound. What would I need to set in osg to make it so? 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 Cheers Sebastian Thank you! Cheers, Bram -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57124#57124 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] blending on multiple targets
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). 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? 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? 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 :) Hope I explained this clear enough! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57134#57134 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] blending on multiple targets
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
Re: [osg-users] blending on multiple targets
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). you are right, the word destination also makes more sense then :) I asked this a while ago. There is no function prototype, so it has to be added to the extensions somehow I guess I got this in a respons on the open gl forums: If you don't need real blending for the buffers you do want to write to, you can simply enable and disable blending for each buffer (requires EXT_draw_buffers2, or GL3.0) is that the extension? or actually that seems like it's only about disabling certain buffers (which would be great for my purpose) If I got this correctly, you have your terrain-buffer in one texture and your water result in another. hen you don't need hw-blending to combine them. No and yes, indeed I do not need or use any Hw blending in the final shader, I just use mix() etc. in that shader, that is no problem. But I don't have the writing to seperate buffers working yet, as I described above, but it might be just that I need to activate the correct blending mode for all buffers as you said, and use a vec(0,0,0,0) as output when I want to leave a buffer as is. 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 ;-) I know what you mean, I do tend to disable almost all stuff in the shaders when I start working with something new, so I experiment with very simple shaders to investigate what is exactly happening :) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57144#57144 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] blending on multiple targets
Am 08.11.2013 16:31, schrieb Bram Vaessen: You still can render to them in separate passes. 1.pass: Render texture to FBO with color buffer1 2.pass: Render water to FBO with color buffer2 3.pass: Combine to result buffer (possibly framebuffer) hmm yeah interesting... two problems that I would need to overcome then: how to do multiple passes in OSg (possibly there is a tutorial for that) but another problem is: I need to reuse the zbuffer from the terrain render for the water render or else it will just render all water pixels, including the onces hidden behind the hills of the terrain and such... is that easy to do? That's easy. Basically you can simply create multiple cameras, each with the rendertargets below them. If you add the same depth buffer texture to the passes it can be used for reading and writing. I don't have the examples at hand, but there is some multipass/offscreen example. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57146#57146 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] blending on multiple targets
Hi Bram, There is nothing weird about what you are seeing given what you're doing. Blending with MRT ist always applied to all bound render targets of the framebuffer object. If you want to blend only a single buffer, then do a separate pass, where you blend it. In case you want to apply different blend functions to different FBO attachments you cat take a look at: http://www.opengl.org/registry/specs/EXT/draw_buffers2.txt This extension would actually allow to blend only a single attachment. I've asked for support on the mailing list how to use it/integrate into OSG. Unfortunately without any response. But it is undefined behaviour not writing all attached buffers, as you do in your description. So If there is something like gl_FragData[3] = vec4(0,1,0,1); without any gl_FragData[0] .. gl_FragData[2] then you shader is invalid (yet syntactically correct) cheers Sebastian Hi, I ran into something weird, or something that I don't know how it works exactly. What I want to do when rendering to multiple targets is that I selectively write to certain color buffers in my shader, but leave others alone. for example Code: gl_FragData[3] = vec4(0,1,0,1); without setting the fragment data for the first 3 buffers... This doesn't seem to go well. for example, if I don't explicity set a value in the color buffer 4, it seems to copy the color value from the first color buffer for some reason instead of leaving it alone. So I though: ok I HAVE to explicitly set all a value on all used color buffers, so then if I don't want to touch one of the buffers, I just use blending and I write a value with an alpha of 0, so it doesn't effect the buffer. This doesn't work as expected. It seems that the blending only looks at the color buffer 0 ? if I write a some color-value with an alpha of 0 to the color buffer 0, it doesn't seem to matter what I write to the other buffers, it doesn't write anything. So not sure if you can follow what I'm explaining, but bottom line is: I would like to selectively write to certain color buffers in my shaders, and leave the other alone. Any ideas on how to do that properly? Or am I trying something impossible and do I need another solution? Thank you! Cheers, Bram -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57121#57121 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org