Compositor on shadow textures - How to ?

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


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

Compositor on shadow textures - How to ?

Post by Crashy »

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.
Follow la Moustache on Twitter or on Facebook
Image
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Compositor on shadow textures - How to ?

Post by al2950 »

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.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Compositor on shadow textures - How to ?

Post by al2950 »

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.....
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc »

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.
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Compositor on shadow textures - How to ?

Post by Crashy »

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. :?
Follow la Moustache on Twitter or on Facebook
Image
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Compositor on shadow textures - How to ?

Post by al2950 »

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();
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Compositor on shadow textures - How to ?

Post by al2950 »

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
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc »

I'll look into it.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc »

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.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Compositor on shadow textures - How to ?

Post by al2950 »

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 :)
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Compositor on shadow textures - How to ?

Post by al2950 »

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!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Compositor on shadow textures - How to ?

Post by dark_sylinc »

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 :)
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1005
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Compositor on shadow textures - How to ?

Post by Crashy »

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