Terra additional lights

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


Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Terra additional lights

Post by Nickak2003 »

So I have the terra directional light update working. Now I am trying to add additional lights how do I go about doing that? I tried just adding a point-light but it doesn't seem to light anything, terrain nor object.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Terra additional lights

Post by xrgo »

you need to enable forwardclustered (sceneManager->setForwardClustered)
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: Terra additional lights

Post by Nickak2003 »

cool. What's the best way to determine the params for that call?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Terra additional lights

Post by xrgo »

mmm depends on your scene, how many lights, how big (range) how close, etc
What I did is test in my scene with most lights and just used very low values and started increasing them until I saw no gitches and I get good fps, and I use this for everything

Code: Select all

    forwardPlusParams[0] = 4; //width
    forwardPlusParams[1] = 4; //height
    forwardPlusParams[2] = 24; //numSlices
    forwardPlusParams[3] = 20; //lightsPerCell
    forwardPlusParams[4] = 0; //decalsPerCell
    forwardPlusParams[5] = 5; //cubemapProbesPerCel
    forwardPlusParams[6] = 5; //minDistance
    forwardPlusParams[7] = 500; //maxDistance
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: Terra additional lights

Post by Nickak2003 »

How do I get the additional lights to cast shadows onto the terrain?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: Terra additional lights

Post by xrgo »

casting shadow lights should just work (even without forwardclustered) call light->setCastShadows(true); and you need to set a compositor shadow node with enough shadow maps to handle them, see the PbsMaterials/shadowMapDebugging samples and its respective .compositor files
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: Terra additional lights

Post by Nickak2003 »

Ok, thanks for your help, if you could bare with me =)

So I had the static shadow map tutorial implemented and working then I implemented terra and got that working, now, I tied to combine the two.
I added the shadow map code from the static shadows tutorial compostitor to the terra tutorial compositor. I'm not sure if that's what I was supposed to do or not.

I then added the code to setup the static shadow maps once terra's compositor has finished setting up.

The result is that the point light seems to have a different attenuation/range, more intense, and I do not get shadows from it. I do still get shadows from the directional light.

Heres's my terra compositor, which is just the two compositors combined:

Code: Select all

compositor_node Tutorial_TerrainRenderingNode
{
	in 0 rt_renderwindow
	in 1 TerraShadowTexture

	target rt_renderwindow
	{
		pass clear
		{
			colour_value 0.2 0.4 0.6 1
		}

		pass render_scene
		{
			load
			{
				all				clear
				clear_colour	0.2 0.4 0.6 1
			}
			store
			{
				colour	store_or_resolve
				depth	dont_care
				stencil	dont_care
			}

			expose TerraShadowTexture

			overlays	on
			shadows		Tutorial_TerrainShadowNode
		}
	}
}

compositor_node_shadow Tutorial_TerrainShadowNode
{
	technique pssm

	texture atlas 3072 2048 PFG_D32_FLOAT
	texture atlasStatic	4096 8192 PFG_D32_FLOAT
	texture tmpCubemap	1024 1024 PFG_R32_FLOAT cubemap depth_format PFG_D32_FLOAT

	num_splits		3
	pssm_lambda		0.95
	shadow_map 0 atlas uv 0.000000000000000 0.0 0.666666666666667 1.0 light 0 split 0
	shadow_map 1 atlas uv 0.666666666666667 0.0 0.333333333333333 0.5 light 0 split 1
	shadow_map 2 atlas uv 0.666666666666667 0.5 0.333333333333333 0.5 light 0 split 2

	technique focused
	shadow_map 3 atlasStatic uv 0.0 0.0 1.0 0.5 light 1
	shadow_map 4 atlasStatic uv 0.0 0.5 1.0 0.5 light 2

	target atlas
	{
		pass clear
		{
			colour_value 1 1 1 1
		}
	}

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


	//Clear the static atlas first. Do this inside a shadow_map_target_type block so that it only
	//gets executed if shadow_map 3 is flagged as dirty (instead of clearing every frame).
	shadow_map_target_type directional spot point
	{
		shadow_map 3
		{
			pass clear
			{
				clear_colour_reverse_depth_aware	1 1 1 1
				shadow_map_full_viewport yes
			}
		}
	}

	shadow_map_target_type point
	{
		shadow_map_repeat 3 4
		{
			target tmpCubemap +X : cubemap_target_shadow {}
			target tmpCubemap -X : cubemap_target_shadow {}
			target tmpCubemap +Y : cubemap_target_shadow {}
			target tmpCubemap -Y : cubemap_target_shadow {}
			target tmpCubemap +Z : cubemap_target_shadow {}
			target tmpCubemap -Z : cubemap_target_shadow {}

			shadow_map
			{
				pass render_quad
				{
					material Ogre/DPSM/CubeToDpsm
					input 0 tmpCubemap
				}
			}
		}
	}



}

workspace Tutorial_TerrainWorkspace
{
	connect_external 0 Tutorial_TerrainRenderingNode 0
	connect_external 1 Tutorial_TerrainRenderingNode 1
}
I noticed that there is a TerraShadowGenerator.compositor, I am unsure what that is.

On the c++ side I do all my normal terra stuff, except follow it up with this call, which is straight from the static maps tutorial:

Code: Select all

oid Graphics::setupShadows() {


    Ogre::Root* root = getRoot();
    Ogre::CompositorWorkspace* workspace = getWorkspace();
    Ogre::Hlms* hlmsUnlit = root->getHlmsManager()->getHlms(Ogre::HLMS_UNLIT);

    Ogre::HlmsMacroblock macroblock;
    macroblock.mDepthCheck = false;
    Ogre::HlmsBlendblock blendblock;

    Ogre::CompositorShadowNode* shadowNode =
        workspace->findShadowNode("Tutorial_TerrainShadowNode");
    const Ogre::CompositorShadowNodeDef* shadowNodeDef = shadowNode->getDefinition();
       
    for (int i = 0; i < 5; ++i){

        const Ogre::String datablockName("depthShadow" + Ogre::StringConverter::toString(i));
        Ogre::HlmsUnlitDatablock* depthShadow = (Ogre::HlmsUnlitDatablock*)hlmsUnlit->createDatablock(
            datablockName, datablockName,
            macroblock, blendblock,
            Ogre::HlmsParamVec());

        const Ogre::ShadowTextureDefinition* shadowTexDef =
            shadowNodeDef->getShadowTextureDefinition(i);

        Ogre::TextureGpu* tex = shadowNode->getDefinedTexture(shadowTexDef->getTextureNameStr());
        depthShadow->setTexture(0, tex);

        //If it's an UV atlas, then only display the relevant section.
        Ogre::Matrix4 uvOffsetScale;
        uvOffsetScale.makeTransform(Ogre::Vector3(shadowTexDef->uvOffset.x,
            shadowTexDef->uvOffset.y, 0.0f),
            Ogre::Vector3(shadowTexDef->uvLength.x,
                shadowTexDef->uvLength.y, 1.0f),
            Ogre::Quaternion::IDENTITY);
            
         

        depthShadow->setEnableAnimationMatrix(0, true);
        depthShadow->setAnimationMatrix(0, uvOffsetScale);
    }
}
I then assign the static map 3 to the point light, enable shadow casting from the light, and set it dirty each frame. Again, the light attenuation alters and there is no casted shadow.

Thanks for the help!
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: Terra additional lights

Post by Nickak2003 »

OK, I figured it out, I forgot to add the cube map code to the compositor.
Was missing:

Code: Select all

abstract target cubemap_target_shadow
{
	pass render_scene
	{
		load
		{
			all                                 clear
			clear_colour_reverse_depth_aware	1 1 1 1
		}
		store
		{
			//We only care about the contents of the colour target with point shadows
			depth			dont_care
			stencil			dont_care
		}
		camera_cubemap_reorient true
	}
}