Compositor on shadow textures - How to ?

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 15
Contact:

Compositor on shadow textures - How to ?

Post by Crashy » Wed Jan 07, 2015 1:32 pm

Hi,

Now that the shadow textures are defined using a compositor node, how to apply a compositor on them ?

Shadow filtering methods like VSM or ESM requires to blur the shadow maps, and back in Ogre 1.xx we (at least, me) used to get the shadow texture viewport and add some compositor on it, but now, what's the best way to do it ?

Thanks.
0 x
Follow la Moustache on Twitter or on Facebook
Image

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Compositor on shadow textures - How to ?

Post by al2950 » Wed Jan 07, 2015 2:36 pm

I discussed this issue with dark_sylinc in this post;
http://ogre3d.org/forums/viewtopic.php?f=25&t=82090

I am not too worried about it at the moment as I wanted it because I was being lazy so I have not chased up on it.
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Compositor on shadow textures - How to ?

Post by al2950 » Wed Jan 07, 2015 2:42 pm

Ahh, I keep replying to quickly without reading the post correctly! Sorry :oops: ! Your issue is slightly different.

As far as I am aware, there is no reason why you cant define a render_quad pass within the shadow node.....
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4077
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 231
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc » Fri Jan 09, 2015 4:44 am

Indeed. You can use additional render_quad passes within the same shadow node to do that kind of postprocessing.

Plugging the shadow maps directly to other nodes is something I want to explore as well.
But for now the first option is likely to be the best option.
0 x

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 15
Contact:

Re: Compositor on shadow textures - How to ?

Post by Crashy » Fri Jan 09, 2015 8:31 am

I've tried to do something like that, just to see how it behaves.

Code: Select all

compositor_node_shadow Shadows_FocusedShadowNode
{
    technique focused

	shadow_map shadow_0 1024 1024 PF_FLOAT32_R light 0 depth_pool 2
	texture blur_h 1024 1024 PF_FLOAT32_R
	
	shadow_map shadow_0
	{
		pass clear
		{
			colour_value 1 1 1 1
		}

		pass render_scene 
		{
			overlays			off
		}
	}
	target blur_h
	{
		pass clear
		{
			colour_value 1 1 1 1
		}
	}
	
}
But even if the second clear pass is not targeting the shadow map, it's affecting it. :?
0 x
Follow la Moustache on Twitter or on Facebook
Image

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Compositor on shadow textures - How to ?

Post by al2950 » Fri Jan 09, 2015 2:30 pm

I have just tried it and you are correct, something odd is happening.

I debugged it and it appears to happening because both shadow_0 and blur_h textures are given the same TexSource ID in OgreTextureDefinition::encodeTexSource. This happens because the same index is given for each texture as there are separate counters for for shadow textures and normal local textures in the script translator. I think the offending line of code is roughly line 92 in the function CompositorShadowNodeDef::addShadowTextureDefinition

It currently reads;

Code: Select all

...
        mNumLights += newLight;

        if( !isAtlas )
            addTextureSourceName( name, mShadowMapTexDefinitions.size(), TEXTURE_LOCAL );
        mShadowMapTexDefinitions.push_back( ShadowTextureDefinition( mDefaultTechnique, name,
                                                                     lightIdx, split ) );
        return &mShadowMapTexDefinitions.back();
However I think it should read the following, but not sure about the knock on effects (need dark_sylinc's view on this)
Note the index variable given to addTextureSourceName

Code: Select all

...
        mNumLights += newLight;

        if( !isAtlas )
            addTextureSourceName( name, mLocalTextureDefs.size(), TEXTURE_LOCAL );
        mShadowMapTexDefinitions.push_back( ShadowTextureDefinition( mDefaultTechnique, name,
                                                                     lightIdx, split ) );
        return &mShadowMapTexDefinitions.back();
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Compositor on shadow textures - How to ?

Post by al2950 » Fri Jan 09, 2015 3:59 pm

Actually my above fix wont work, I think it needs a slightly more complicated fix, like a separate counter stored in TextureDefinitionBase which is accessed from TextureDefinitionBase::addTextureDefinition & CompositorShadowNodeDef::addShadowTextureDefinition. Sorry this area is still a little blury for me, will definitely need dark_sylinc's help
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4077
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 231
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc » Fri Jan 09, 2015 4:17 pm

I'll look into it.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4077
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 231
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc » Fri Jan 09, 2015 5:04 pm

Fixed in https://bitbucket.org/sinbad/ogre/commi ... at=default
Thanks for the report.

@al2950
The fix wasn't that complicated. This feature was taken into account but it was just an implementation bug.
If you look at CompositorShadowNodeDef::addShadowTextureDefinition; the code assumes the user (or at least the script parser) will declare all the shadow maps before the regular textures. Otherwise it will raise an exception. This simplifies things as shadow maps will always come before regular textures.

In fact in CompositorShadowNode::CompositorShadowNode, its base class CompositorNode will first create the regular textures, and then CompositorShadowNode will move them to the end of the array.

The solution is to simply overload CompositorShadowNodeDef::addTextureSourceName so that it assigns the index "mShadowMapTexDefinitions.size() + index"; and create a separate routine that doesn't have this offset for use by addShadowTextureDefinition.

Since shadow maps must be declared first, mShadowMapTexDefinitions.size() will not change while declaring the regular textures.
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Compositor on shadow textures - How to ?

Post by al2950 » Fri Jan 09, 2015 5:31 pm

dark_sylinc wrote:I'll look into it.
Please note that when a normal texture is created it does not set the depth buffer pool, which is slightly related to this issue but easy to fix, unless you like random holes in your scene :)
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Compositor on shadow textures - How to ?

Post by al2950 » Fri Jan 09, 2015 5:36 pm

dark_sylinc wrote: @al2950
If you look at CompositorShadowNodeDef::addShadowTextureDefinition; the code assumes the user (or at least the script parser) will declare all the shadow maps before the regular textures. Otherwise it will raise an exception. This simplifies things as shadow maps will always come before regular textures.
s.
Thank you for explaining, I had not clocked that the shadow maps have to be defined first, although it makes sense looking at the code!
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4077
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 231
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc » Fri Jan 09, 2015 6:26 pm

al2950 wrote:
dark_sylinc wrote:I'll look into it.
Please note that when a normal texture is created it does not set the depth buffer pool, which is slightly related to this issue but easy to fix, unless you like random holes in your scene :)
Holy sh**!!
Thanks! Fixed :)
0 x

Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 996
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 15
Contact:

Re: Compositor on shadow textures - How to ?

Post by Crashy » Fri Jan 09, 2015 10:21 pm

Cool! Thanks for the fast investigation and fix !
0 x
Follow la Moustache on Twitter or on Facebook
Image

Post Reply