[2.1] Light masks

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


User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

[2.1] Light masks

Post by devxkh »

how can i exlude an item affected from a light?

Code: Select all

OgreItemPtr->setLightMask(0x0000001);
      light->setLightMask(0x000000001);
this doesn't work...
My little OGRE engine -> FrankE WIP
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5448
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1349

Re: [2.1] Light masks

Post by dark_sylinc »

Yeah, setLightMask won't work with Forward+ (or Deferred if we had it) as this information is lost.

With Forward+ you can use two pass_scenes though, to achieve a similar result:

Code: Select all

pass_scene
{
    //Render objects and lights that have (mask & 0x00000001) != 0
    visibility_mask 0x00000001
}
pass_scene
{
    //Render objects and lights that have (mask & 0x00000001) != 0
    visibility_mask 0x00000002
    //Only work on a subset of RenderQueues to skip from processing a lot of items from the common RQs (assumes you put your Item in RQ ID 2)
    rq_first 2
    rq_first 3
}
It's not the same because you will be altering the order in which objects are rendered, but it will achieve what you're asking for.
Feanor16
Halfling
Posts: 46
Joined: Tue Feb 18, 2014 10:49 pm

Re: [2.1] Light masks

Post by Feanor16 »

if i understand, that's not possible anymore to change the mask into our code?

i tried with

Code: Select all

addWorkspace( SceneManager *sceneManager,
                                           const CompositorChannelVec &externalRenderTargets,
                                           Camera *defaultCam, IdString definitionName, bool bEnabled,
                                           int position=-1, const UavBufferPackedVec *uavBuffers=0,
                                           const ResourceLayoutMap* initialLayouts=0,
                                           const ResourceAccessMap* initialUavAccess=0,
                                           const Vector4 &vpOffsetScale = Vector4::ZERO,
                                           uint8 vpModifierMask=0x00, uint8 executionMask=0xFF );
editing executionMask when i build my workspace but it doesn't work
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5448
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1349

Re: [2.1] Light masks

Post by dark_sylinc »

Feanor16 wrote:if i understand, that's not possible anymore to change the mask into our code?
I don't understand what you mean.
Feanor16 wrote: i tried with

Code: Select all

addWorkspace( SceneManager *sceneManager,
                                           const CompositorChannelVec &externalRenderTargets,
                                           Camera *defaultCam, IdString definitionName, bool bEnabled,
                                           int position=-1, const UavBufferPackedVec *uavBuffers=0,
                                           const ResourceLayoutMap* initialLayouts=0,
                                           const ResourceAccessMap* initialUavAccess=0,
                                           const Vector4 &vpOffsetScale = Vector4::ZERO,
                                           uint8 vpModifierMask=0x00, uint8 executionMask=0xFF );
editing executionMask when i build my workspace but it doesn't work
I don't know what execution masks have to do with this.
Feanor16
Halfling
Posts: 46
Joined: Tue Feb 18, 2014 10:49 pm

Re: [2.1] Light masks

Post by Feanor16 »

Sorry, bad explain. i was looking for use an equivalent of

Code: Select all

viewport->setVisibilityMask(visibility);

but like the lights, it doesn't works
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5448
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1349

Re: [2.1] Light masks

Post by dark_sylinc »

Feanor16 wrote:Sorry, bad explain. i was looking for use an equivalent of

Code: Select all

viewport->setVisibilityMask(visibility);

but like the lights, it doesn't works
Hi! Don't change the viewport's visibility mask, as the compositor will override your changes. It's a sort of hard to remove remnant from 1.x.

Set the visibility mask to the render_scene pass either by script (use visibility_mask keyword) or by code (change CompositorPassSceneDef).
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: [2.1] Light masks

Post by rujialiu »

dark_sylinc wrote:Yeah, setLightMask won't work with Forward+ (or Deferred if we had it) as this information is lost.
Is it a limitation of Forward+ in general, or just a limitation of current implementation? For example, can we put the lighting mask of objects into the material, and light masks of lights into the global light list, and then we can test it in the pixel shader? Rendering multiple scene passes seem to be troublesome if we have transparent object.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5448
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1349

Re: [2.1] Light masks

Post by dark_sylinc »

rujialiu wrote:[quote="dark_sylinc"Is it a limitation of Forward+ in general, or just a limitation of current implementation? For example, can we put the lighting mask of objects into the material, and light masks of lights into the global light list, and then we can test it in the pixel shader? Rendering multiple scene passes seem to be troublesome if we have transparent object.
If you're asking if it can be done, yes... it can be done. But doing the mask comparison in the pixel shader will cost performance. If you really need it, then I guess I could implement it and have it globally disabled by default (to save performance to those who don't need the feature).
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: [2.1] Light masks

Post by rujialiu »

dark_sylinc wrote: If you're asking if it can be done, yes... it can be done. But doing the mask comparison in the pixel shader will cost performance. If you really need it, then I guess I could implement it and have it globally disabled by default (to save performance to those who don't need the feature).
Please do it! We want it *desperately* :) And at least another user (the original author of this post) is also interested in it too.

Also, it's a feature supported in Ogre 1.x, so supporting it (even as an optional feature) will make upgraders happier.

BTW: I was trying to do something similar mentioned above (render two passes for different visibility masks), but failed. I don't know why, but even if I do this:

Code: Select all

render_scene
{
  overlay off
  visibility_mask 0x0
// shadows DefaultShadowNode
}

render_scene
{
  overlay off
// shadows DefaultShadowNode
}
The scene becomes very dark (well, not black because we have PCC and Irradiance Volumes enabled, but turning them off yield a completely black screen). Note that the shadow nodes are commented out. If I enable them, the scene will not be dark, but still can't achieve what I want.

However, if I do this as normal:

Code: Select all

render_scene
{
  overlay off
  shadows DefaultShadowNode
}
Everything's fine now.

I debugged a bit and found the viewport's visiblity mask is correctly set before each frustum cull, But it's too difficult to inspect what items/lights are culled, with watches in VS, and I didn't have time to inspect what data are sent to GPU by RenderDoc. I just feel that something screwed up :(

But if you can support lightmasks in Forward+, I don't have to bother this anymore in near future.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5448
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1349

Re: [2.1] Light masks

Post by dark_sylinc »

rujialiu wrote:
dark_sylinc wrote: The scene becomes very dark (well, not black because we have PCC and Irradiance Volumes enabled, but turning them off yield a completely black screen). Note that the shadow nodes are commented out. If I enable them, the scene will not be dark, but still can't achieve what I want.
You've found a bug. Ogre is trying to reuse the culling results from the previous pass when it shouldn't.
I'll fix that one tomorrow along with adding per pixel shader visibility mask.

Edit: That bug is fixed.
Now I'm onto the fine granularity control.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5448
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1349

Re: [2.1] Light masks

Post by dark_sylinc »

Fine granularity got implemented for all RenderSystems.

It must be enabled via CMake variable OGRE_CONFIG_ENABLE_FINE_LIGHT_MASK_GRANULARITY to avoid penalizing other Ogre users for a feature they won't use. Once Ogre is compiled with that setting, it can be toggled via ForwardPlusBase::setFineLightMaskGranularity (which will be enabled by default).

Once enabled, Forward+ lights will only lit an object if the comparison "Light::getLightMask & MovableObject::getLightMask" returns non zero.

Normally it's a performance loss, but if the number of lights skipped via light mask has low divergence and covers a high number of pixels, it may improve performance. But most likely if you're using this feature you're more worried about aesthetics.
Though if coarse masking is enough for you, skipping lights via multiple scene passes and light_visibility_mask will be much faster. Note that coarse masking looks at getVisibilityFlags, while fine masking looks at getLightMask!
rujialiu
Goblin
Posts: 296
Joined: Mon May 09, 2016 8:21 am
x 35

Re: [2.1] Light masks

Post by rujialiu »

dark_sylinc wrote:Fine granularity got implemented for all RenderSystems.
We've tried the fine granularity one. It works perfectly for us with both D3D11 and Metal. Thanks!