Creating shadow node by code, spotlight not working

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


Post Reply
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Creating shadow node by code, spotlight not working

Post by xrgo »

Hello! I have my Compositor shadow node created by code like this:

Code: Select all

    Ogre::CompositorShadowNodeDef* shadowNodeDef = mCompositorManager->addShadowNodeDefinition( "MainEngineShadowNode" );

    mPssmSplitsCount = 2;
    mPssmLambda = 0.95;
    int spotlightsShadows = 1;
    int textureCount = mPssmSplitsCount + spotlightsShadows;

    shadowNodeDef->setNumLocalTextureDefinitions( 1 );
    shadowNodeDef->setNumShadowTextureDefinitions( textureCount );
    shadowNodeDef->setNumTargetPass( textureCount );

    Ogre::TextureDefinitionBase::TextureDefinition *texDef = shadowNodeDef->addTextureDefinition( "shadowAtlas" );
    texDef->fsaa = false;
    texDef->width = 3072;//1024*textureCount;
    texDef->height = 1024;
    texDef->formatList.push_back( Ogre::PF_D32_FLOAT );


    {
        Ogre::ShadowTextureDefinition *shadTexDef = shadowNodeDef->addShadowTextureDefinition( 0, 0, "shadowAtlas", 0, Ogre::Vector2( 0.0, 0.0 ), Ogre::Vector2( 0.33333, 1.0 ), 0 );
        shadTexDef->shadowMapTechnique = Ogre::SHADOWMAP_PSSM;
        shadTexDef->numSplits = mPssmSplitsCount;
        shadTexDef->pssmLambda = mPssmLambda;
    }
    {
        Ogre::ShadowTextureDefinition *shadTexDef = shadowNodeDef->addShadowTextureDefinition( 0, 1, "shadowAtlas", 0, Ogre::Vector2( 0.33333, 0.0 ), Ogre::Vector2( 0.33333, 1.0 ), 0 );
        shadTexDef->shadowMapTechnique = Ogre::SHADOWMAP_PSSM;
        shadTexDef->numSplits = mPssmSplitsCount;
        shadTexDef->pssmLambda = mPssmLambda;
    }
    {
        Ogre::ShadowTextureDefinition *shadTexDef = shadowNodeDef->addShadowTextureDefinition( 1, 0, "shadowAtlas", 0, Ogre::Vector2( 0.666666, 0.0 ), Ogre::Vector2( 0.33333, 1.0 ), 0 );
        shadTexDef->shadowMapTechnique = Ogre::SHADOWMAP_FOCUSED;
    }


    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 2 );
        targetDef->setShadowMapSupportedLightTypes( Ogre::Light::LT_DIRECTIONAL );
        //Clear
        Ogre::CompositorPassDef *passClearDef = targetDef->addPass( Ogre::PASS_CLEAR );
        ((Ogre::CompositorPassClearDef*)(passClearDef))->mColourValue = Ogre::ColourValue::White;
        passClearDef->mShadowMapIdx = 0;
        passClearDef->mIncludeOverlays = false;
        //Scene
        Ogre::CompositorPassDef *passSceneDef = targetDef->addPass( Ogre::PASS_SCENE );
        passSceneDef->mShadowMapIdx = 0;
        passSceneDef->mIncludeOverlays = false;
        ((Ogre::CompositorPassSceneDef*)(passSceneDef))->mUpdateLodLists = false;
    }
    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 2 );
        targetDef->setShadowMapSupportedLightTypes( Ogre::Light::LT_DIRECTIONAL );
        //Clear
        Ogre::CompositorPassDef *passClearDef = targetDef->addPass( Ogre::PASS_CLEAR );
        ((Ogre::CompositorPassClearDef*)(passClearDef))->mColourValue = Ogre::ColourValue::White;
        passClearDef->mShadowMapIdx = 1;
        passClearDef->mIncludeOverlays = false;
        //Scene
        Ogre::CompositorPassDef *passSceneDef = targetDef->addPass( Ogre::PASS_SCENE );
        passSceneDef->mShadowMapIdx = 1;
        passSceneDef->mIncludeOverlays = false;
        ((Ogre::CompositorPassSceneDef*)(passSceneDef))->mUpdateLodLists = false;
    }
    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 2 );
        targetDef->setShadowMapSupportedLightTypes( Ogre::Light::LT_SPOTLIGHT );
        //Clear
        Ogre::CompositorPassDef *passClearDef = targetDef->addPass( Ogre::PASS_CLEAR );
        ((Ogre::CompositorPassClearDef*)(passClearDef))->mColourValue = Ogre::ColourValue::White;
        passClearDef->mShadowMapIdx = 2;
        passClearDef->mIncludeOverlays = false;
        //Scene
        Ogre::CompositorPassDef *passSceneDef = targetDef->addPass( Ogre::PASS_SCENE );
        passSceneDef->mShadowMapIdx = 2;
        passSceneDef->mIncludeOverlays = false;
        ((Ogre::CompositorPassSceneDef*)(passSceneDef))->mUpdateLodLists = false;
    }
(I do those repeated things in a for loop, I just expanded them for easy viewing)
but the spotlight shadow isn't working...

using the same parameters but by script, it works

Code: Select all

compositor_node_shadow MainEngineShadowNodeTEST
{
	technique pssm

	texture shadowAtlas 3072 1024 PF_D32_FLOAT no_fsaa

	num_splits		2
	pssm_lambda		0.95
	shadow_map 0 shadowAtlas uv 0.0 0.0 0.33333 1.0 light 0 split 0
	shadow_map 1 shadowAtlas uv 0.333333 0.0 0.333333 1.0 light 0 split 1

	technique focused
	shadow_map 2 shadowAtlas uv 0.666666 0.0 0.33333 1.0 light 1

	target shadowAtlas
	{
		pass clear
		{
			colour_value 1 1 1 1
		}
	}

	shadow_map_target_type directional
	{
		shadow_map 0 1
		{
			pass render_scene
			{
			}
		}
	}

	shadow_map_target_type directional spot
	{
		shadow_map 2
		{
			pass render_scene
			{
			}
		}
	}

}
pssm shadows works fine.
What am I missing?
Does the creation order of lights/workspace could be the problem?

thank you!!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Creating shadow node by code, spotlight not working

Post by dark_sylinc »

In your C++ you're issueing a clear with every pass, yet with the script you're only issueing the clear at the beginning to the whole atlas. They're not the same thing.

Clearing does not guarantee only the subregion will be cleared, so you may be clearing the whole RTT.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Creating shadow node by code, spotlight not working

Post by dark_sylinc »

Additionally, you're passing the wrong value to setShadowMapSupportedLightTypes. See the docs:

Code: Select all

/// Used by shadow map passes only. Determines which light types are supposed
/// to be run with the current shadow casting light. i.e. usually point lights
/// need to be treated differently, and only directional lights are compatible
/// with PSSM. This bitmask contains:
///     mShadowMapSupportedLightTypes & 1u << Light::LT_DIRECTIONAL
///     mShadowMapSupportedLightTypes & 1u << Light::LT_POINT
///     mShadowMapSupportedLightTypes & 1u << Light::LT_SPOTLIGHT
So you should be calling:

Code: Select all

setShadowMapSupportedLightTypes( 1u  << Light::LT_DIRECTIONAL );
setShadowMapSupportedLightTypes( 1u  << Light::LT_SPOTLIGHT );
Instead of what you're doing now.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Creating shadow node by code, spotlight not working

Post by xrgo »

Tried this:

Code: Select all

    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 1 );
        //Clear
        Ogre::CompositorPassDef *passClearDef = targetDef->addPass( Ogre::PASS_CLEAR );
        ((Ogre::CompositorPassClearDef*)(passClearDef))->mColourValue = Ogre::ColourValue::White;
        passClearDef->mIncludeOverlays = false;
    }
    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 1 );
        targetDef->setShadowMapSupportedLightTypes( Ogre::Light::LT_DIRECTIONAL );
        //Scene
        Ogre::CompositorPassDef *passSceneDef = targetDef->addPass( Ogre::PASS_SCENE );
        passSceneDef->mShadowMapIdx = 0;
        passSceneDef->mIncludeOverlays = false;
        ((Ogre::CompositorPassSceneDef*)(passSceneDef))->mUpdateLodLists = false;
    }
    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 1 );
        targetDef->setShadowMapSupportedLightTypes( Ogre::Light::LT_DIRECTIONAL );
        //Scene
        Ogre::CompositorPassDef *passSceneDef = targetDef->addPass( Ogre::PASS_SCENE );
        passSceneDef->mShadowMapIdx = 1;
        passSceneDef->mIncludeOverlays = false;
        ((Ogre::CompositorPassSceneDef*)(passSceneDef))->mUpdateLodLists = false;
    }
    {
        Ogre::CompositorTargetDef *targetDef = shadowNodeDef->addTargetPass( "shadowAtlas" );
        targetDef->setNumPasses( 1 );
        targetDef->setShadowMapSupportedLightTypes( Ogre::Light::LT_SPOTLIGHT );
        //Scene
        Ogre::CompositorPassDef *passSceneDef = targetDef->addPass( Ogre::PASS_SCENE );
        passSceneDef->mShadowMapIdx = 2;
        passSceneDef->mIncludeOverlays = false;
        ((Ogre::CompositorPassSceneDef*)(passSceneDef))->mUpdateLodLists = false;
    }
and its the same =(
Last edited by xrgo on Mon Sep 25, 2017 10:18 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Creating shadow node by code, spotlight not working

Post by dark_sylinc »

Read my next reply :)
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Creating shadow node by code, spotlight not working

Post by xrgo »

dark_sylinc wrote:you're passing the wrong value to setShadowMapSupportedLightTypes
Yes that was it!!
Thank you soo much!!!!
Post Reply