OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Problem blending multiple render passes


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
antiro42
User


Joined: 01 Sep 2017
Posts: 40

PostPosted: Sat Sep 09, 2017 9:44 am    Post subject:
Problem blending multiple render passes
Reply with quote

Hi,

I'm trying to compute the effect of multiple lights in a deferred shading setup. The subgraph of my scenegraph which is supposed to take care of this consists of a root node with a number of RTT cameras as children. All cameras are configured to write the effect of a single light to the exact same output texture.
On the root node I have (tried to) enable blending so the output texture will contain a combination of all the lighting that is computed, however, when I run the code, it only contains the lighting information of the last child camera (i.e. It is overwriting the output texture instead of blending it)

I have set up blending at the root node as follows:
Code:
auto passState=m_pointLightRoot->getOrCreateStateSet();
   passState->setMode(GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
   passState->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
   osg::BlendFunc *blendFunc = new osg::BlendFunc(GL_ONE,GL_ONE);
   osg::BlendEquation *blendEqn = new osg::BlendEquation(osg::BlendEquation::Equation::FUNC_ADD);
   passState->setAttributeAndModes(blendFunc,osg::StateAttribute::ON |osg::StateAttribute::OVERRIDE);
   passState->setAttributeAndModes(blendEqn,osg::StateAttribute::ON |osg::StateAttribute::OVERRIDE);



Is there something wrong with the way I set up blending? Or with my approach of having the different cameras as children of the root?

Thank you!

Cheers,
antiro
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 797

PostPosted: Sat Sep 09, 2017 10:43 am    Post subject:
Problem blending multiple render passes
Reply with quote

Hi Antiro,

Without the complete code it is hard to guess, but some things to check:

1. Are the consecutive cameras set up _not_ to clear the color buffer?
2. Have you disabled depth writes?

Quote:
Hi,

I'm trying to compute the effect of multiple lights in a deferred shading setup. The subgraph of my scenegraph which is supposed to take care of this consists of a root node with a number of RTT cameras as children. All cameras are configured to write the effect of a single light to the exact same output texture.
On the root node I have (tried to) enable blending so the output texture will contain a combination of all the lighting that is computed, however, when I run the code, it only contains the lighting information of the last child camera (i.e. It is overwriting the output texture instead of blending it)

I have set up blending at the root node as follows:

Code:
auto passState=m_pointLightRoot->getOrCreateStateSet();
passState->setMode(GL_BLEND, osg::StateAttribute:ShockedN | osg::StateAttribute::OVERRIDE);
passState->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
osg::BlendFunc *blendFunc = new osg::BlendFunc(GL_ONE,GL_ONE);
osg::BlendEquation *blendEqn = new osg::BlendEquation(osg::BlendEquation::Equation::FUNC_ADD);
passState->setAttributeAndModes(blendFunc,osg::StateAttribute:ShockedN |osg::StateAttribute::OVERRIDE);
passState->setAttributeAndModes(blendEqn,osg::StateAttribute:ShockedN |osg::StateAttribute::OVERRIDE);




Is there something wrong with the way I set up blending? Or with my approach of having the different cameras as children of the root?
I would put all lights using the same shader under one group and one
camera (e.g. one pass).

Cheers
Sebastian
Quote:

Thank you!

Cheers,
antiro

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









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
antiro42
User


Joined: 01 Sep 2017
Posts: 40

PostPosted: Sat Sep 09, 2017 11:43 am    Post subject:
Reply with quote

Hi Sebastian,

So I screwed up on both the color clearing and the depth writing, I tried to disable both is follows.
On the cameras:
Code:

//Disable depth buffer writing
osg::ref_ptr<osg::Depth> depth = new osg::Depth(osg::Depth::LESS,0,1,false);
camera->getOrCreateStateSet()->setAttribute(depth);

//Disable writing to color buffer
GLbitfield mask = 0;
camera->setClearMask(mask);


The result was that (as expected) the geometry became extremely bright within a few frames (as I had forgotten to clear the output texture in between frames), but unexpectedly still from only a single light source. After I had fixed the texture clearing in between frames the result was the same as before: Only the result of a single lighting pass is visible.
I verified that this is the LAST pass, so it seems like the results of previous passes are overwritten instead of blended?

The reason I am using multiple passes is because I want to support an arbitrary (run time determined) number of light sources. Hence I can not just load a bunch of light sources into the uniforms of a single shader.

If you have any other ideas of why my problems persist (or if I messed up with disabling color clearing/depth writing) please let me know!


Thank you!

Cheers,
antiro[/code]
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 797

PostPosted: Sat Sep 09, 2017 12:10 pm    Post subject:
Problem blending multiple render passes
Reply with quote

Hi Antiro,> Hi Sebastian,
Quote:

So I screwed up on both the color clearing and the depth writing, I tried to disable both is follows.
On the cameras:

Code:

//Disable depth buffer writing
osg::ref_ptr<osg::Depth> depth = new osg::Depth(osg::Depth::LESS,0,1,false);
camera->getOrCreateStateSet()->setAttribute(depth);

//Disable writing to color buffer
GLbitfield mask = 0;
camera->setClearMask(mask);



The result was that (as expected) the geometry became extremely bright within a few frames (as I had forgotten to clear the output texture in between frames), but unexpectedly still from only a single light source. After I had fixed the texture clearing in between frames the result was the same as before: Only the result of a single lighting pass is visible.
I verified that this is the LAST pass, so it seems like the results of previous passes are overwritten instead of blended?

If you're using multiple passes the first pass needs to clear the buffer
and all consecutive passes need to simply blend into it. Did you enable
blending in the camera state set?

Quote:

The reason I am using multiple passes is because I want to support an arbitrary (run time determined) number of light sources. Hence I can not just load a bunch of light sources into the uniforms of a single shader
So you're not doing deferred lighting? Usually one does blend all the
lighting contributions to one texture by rendering all lights as boxes,
spheres etc to limit the area in the lighting texture the light can
contribute to using viewspace-calculations. There are tons of papers and
blogs on how to do this.

Each light therefore is rendered in the same camera adding its
contribution by simply rendering its hull-volume and carrying the light
information in a bunch of uniforms per light. Since you have the
depth-buffer (and therefore the viewspace/worldspace geometry
coordiantes per fragment) you can calculate the light-geometry distance
per fragment and therefore the light contribution.

Quote:

If you have any other ideas of why my problems persist (or if I messed up with disabling color clearing/depth writing) please let me know!

Again: Try to create a minimal example! It's rather tedious to pull
information out of someone's head in order to get the possible problems.

Cheers
Sebastian
Quote:


Thank you!

Cheers,
antiro[/code]

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









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
antiro42
User


Joined: 01 Sep 2017
Posts: 40

PostPosted: Sat Sep 09, 2017 12:42 pm    Post subject:
Reply with quote

Hi,

1. I enabled blending on the root node of the subtree containing the camera's, I'm assuming this is carried over to the camera nodes.

2. I am using deferred rendering, all lighting calculations are based on the information in the GBuffer. I tried to get it to work with one camera and a subtree containing the lightvolumes with uniforms set per volume. However I couldn't get that to work, hence I thought I'd first try the simpler approach without writing to the stencil buffer.

3. I get that it is hard to help without example code and I am really grateful that you are trying anyways! The problem is that I have a pretty advanced rendering engine written in pure openGL. I decided that I wanted to port this to use OSG for improved cross platform compatibility (slowly starting to regret that decision...). This means that I'm working in a project of ~20k lines of code, which makes it really hard to isolate things into minimal examples. I never expected it to be this hard to restructure the project to work with OSG. The previous code is rather straight forward / low level: first run this shader, then run than shader etc. Now everything is attached to nodes in the scene graph and it is harder to for me wrap my head around the order things are happening in and how the openGL state is modified. If I ever get to the end of this, I might write a tutorial on porting pure openGL code to OSG. It will be the tutorial I wish I had right now Razz

Thank you!

Cheers,
antiro
Back to top
View user's profile Send private message
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 797

PostPosted: Sat Sep 09, 2017 12:50 pm    Post subject:
Problem blending multiple render passes
Reply with quote

Am 09.09.2017 um 14:42 schrieb antiro black:
Quote:
Hi,

1. I enabled blending on the root node of the subtree containing the camera's, I'm assuming this is carried over to the camera nodes.
I'd rather enable it under the camera. Camera's have a default state set
when created IIRC. So start by enabling blending in the camera itself.
Quote:

2. I am using deferred rendering, all lighting calculations are based on the information in the GBuffer. I tried to get it to work with one camera and a subtree containing the lightvolumes with uniforms set per volume. However I couldn't get that to work, hence I thought I'd first try the simpler approach without writing to the stencil buffer.
You don't need the stencil buffer for this in any case. The stencil
approach simply helps to improve performance here. Running a new camera
per light basically is a full-screen pass per light! ...
Quote:

3. I get that it is hard to help without example code and I am really grateful that you are trying anyways! The problem is that I have a pretty advanced rendering engine written in pure openGL. I decided that I wanted to port this to use OSG for improved cross platform compatibility (slowly starting to regret that decision...). This means that I'm working in a project of ~20k lines of code, which makes it really hard to isolate things into minimal examples. I never expected it to be this hard to restructure the project to work with OSG. The previous code is rather straight forward / low level: first run this shader, then run than shader etc. Now everything is attached to nodes in the scene graph and it is harder to for me wrap my head around the order things are happening in and how the openGL state is modified. If I ever get to the end of this, I might write a tutorial on porting pure openGL code to OSG. It will be the tutorial I wish I had right now Razz

You can still, for the sake of understanding the problem, set up a small
example doing two pass on one geometry.

In order to keep the mailing list pollution down you can also contact me
on a private channel.

Cheers
Sebastian
Quote:

Thank you!

Cheers,
antiro

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









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts multiple views + instancing d_a_heitbrink General 2 Wed Nov 15, 2017 7:06 pm View latest post
No new posts Osg 3.4.1 - Tutorial 12 Fails on Mac ... digitorus General 1 Sat Nov 04, 2017 12:32 pm View latest post
No new posts BVH and model axis centering: a model... Paradox Plugins [osgPlugins] 0 Mon Oct 16, 2017 4:27 pm View latest post
No new posts Problem With Osg Texture Colors! Bobykhani General [forum] 1 Tue Oct 10, 2017 8:20 am View latest post
No new posts Multiple video textures using ffmpeg ... mmaurus Plugins [osgPlugins] 6 Thu Oct 05, 2017 10:02 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP