Compositor on shadow textures - How to ?
-
- 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 ?
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.
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.
-
- 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 ?
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.
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.
-
- 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 ?
Ahh, I keep replying to quickly without reading the post correctly! Sorry ! 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.....
As far as I am aware, there is no reason why you cant define a render_quad pass within the shadow node.....
- dark_sylinc
- 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 ?
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.
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.
-
- 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 ?
I've tried to do something like that, just to see how it behaves.
But even if the second clear pass is not targeting the shadow map, it's affecting it.
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
}
}
}
-
- 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 ?
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;
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
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();
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();
-
- 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 ?
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
- dark_sylinc
- OGRE Team Member
- Posts: 5296
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1278
- Contact:
- dark_sylinc
- 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 ?
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.
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.
-
- 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 ?
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 scenedark_sylinc wrote:I'll look into it.
-
- 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 ?
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!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.
- dark_sylinc
- 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 ?
Holy sh**!!al2950 wrote: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 scenedark_sylinc wrote:I'll look into it.
Thanks! Fixed
-
- 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 ?
Cool! Thanks for the fast investigation and fix !