Lighting in Mini-Map question

Problems building or running the engine, queries about how to use features etc.
Post Reply
Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Lighting in Mini-Map question

Post by Owl53 » Mon May 20, 2019 4:09 pm

Ogre Version: 1.11
Operating System: Windows 10
Render System: GL

Hi,

Using the example in the following link (http://wiki.ogre3d.org/Intermediate+Tutorial+7), I managed to use the RTT to create a minimap. There is a strange issue however that I don't know what's causing it. Simplifying the scene to explain the problem - I have a flat floor, with an object on it at about (0, 17, 0). In the scene, there is a spotlight at (0, 350, 0). In the main camera and viewport, the scene is lit, the object has a shadow, but in the RTT camera view, the scene is much darker. When the object at (0, 17, 0) is moved from that point, the RTT viewport becomes fully lit like the main viewport is. Why is the position of the object affecting the lighting of the RTT viewport? In addition, in more complex scenes, when any object intersects with 0 in the x and z directions the same problem occurs. I should add that the object in question has a radius of only about 5.

Here is the relevant code for the creation of the light:

Code: Select all

light.reset(sceneManager->createLight(lightName));
light->setDiffuseColour(Ogre::ColourValue::White);
light->setSpecularColour(Ogre::ColourValue::White);
light->setType(Ogre::Light::LT_SPOTLIGHT);

lightNode.reset(sceneManager->getRootSceneNode()->createChildSceneNode());
lightNode->attachObject(light.get());
lightNode->setDirection(0, -1, 0);
lightNode->setPosition(Ogre::Vector3(0, 350, 0));
light->setCastShadows(true);
light->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
Here is the relevant code for the RTT camera view:

Code: Select all

cameraNode.reset(sceneManager->getRootSceneNode()->createChildSceneNode());
cameraNode->setPosition(cameraPos);
camera = sceneManager->createCamera("MiniMapCamera");
camera->setNearClipDistance(1);
camera->setFarClipDistance(5000);
cameraNode->attachObject(camera);

texPtr = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, window->getWidth(), window->getHeight(), 0, Ogre::PF_R8G8B8A8, Ogre::TU_RENDERTARGET);

renderTexture = texPtr->getBuffer()->getRenderTarget();
renderTexture->addListener(this);

viewport = renderTexture->addViewport(camera);
viewport->setClearEveryFrame(true);
viewport->setBackgroundColour(Ogre::ColourValue::Black);
viewport->setOverlaysEnabled(false);
viewport->setShadowsEnabled(false);

rect = new Ogre::Rectangle2D(true); 
rect->setCorners(-0.25f, 0.975f, 0.25f, 0.475f);
rect->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);

textureNode = sceneManager->getRootSceneNode()->createChildSceneNode();
textureNode->attachObject(rect);

Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
matPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
matPtr->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
rect->setMaterial(matPtr);
I can post additional code if needed, but I thought that would be the relevant code for what is causing the problem. Thanks
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Wed May 22, 2019 11:35 am

Here is some additional information that will hopefully help diagnose the problem. If I disable shadows, the RTT camera view becomes fully lit like the main viewport has been. I don't know why shadows would be affecting the lighting for the whole RTT viewport, the light is so far away from the objects.

I also tried seeing if the issue was there with a point light instead of a spotlight, and it is.
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Wed May 22, 2019 1:46 pm

Here are screenshots showing what I mean. I have reduced the scene to just two cubes - one stretched to act as the floor and one test cube to show the problem:

In the first image, the cube starts at (0, 45, 0) and falls to the floor to the position shown in the image. The cube is only 5 units in each direction. The mini-map camera is at (0, 50, 0). As you can see, in the main camera the scene is lit, but in the RTT viewport it is dark.

Image

In the second image I have moved the cube to (10, 45, 0), and that is the only change in the test. In this case though, the RTT viewport is lit. Why is it affected by having an object at (0, x, 0)?

Image
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 850
Joined: Sun Mar 30, 2014 2:51 pm
x 165
Contact:

Re: Lighting in Mini-Map question

Post by paroj » Wed May 22, 2019 10:31 pm

is this again using shadows of any sort? if so are they texture based?
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Thu May 23, 2019 11:34 am

paroj wrote:
Wed May 22, 2019 10:31 pm
is this again using shadows of any sort? if so are they texture based?
Yes, both screenshots have shadows. Texture shadows yeah, SHADOWTYPE_TEXTURE_MODULATIVE. I call viewport->setShadowsEnabled(false) for the RTT viewport though, if that helps to pinpoint the problem.
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Thu May 23, 2019 12:46 pm

After your question Paroj I decided to test if the problem is there with Stencil shadows, and it isn't. Both viewports are lit the same. Why is the problem there with texture shadows? I would like to try and stick with them if I can
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 850
Joined: Sun Mar 30, 2014 2:51 pm
x 165
Contact:

Re: Lighting in Mini-Map question

Post by paroj » Thu May 23, 2019 2:34 pm

shadow maps are tricky. see here: https://docs.microsoft.com/en-us/window ... depth-maps

one thing that might go wrong is the shadow camera setup: https://ogrecave.github.io/ogre/api/lat ... setup.html

another one is that once you enable texture shadows, all receiver materials will get an additional pass that modulates the colour. It will stay there regardless whether you disable shadows on a viewport. Therefore disabling shadows might not works as expected.
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Thu May 23, 2019 2:41 pm

paroj wrote:
Thu May 23, 2019 2:34 pm
shadow maps are tricky. see here: https://docs.microsoft.com/en-us/window ... depth-maps

one thing that might go wrong is the shadow camera setup: https://ogrecave.github.io/ogre/api/lat ... setup.html

another one is that once you enable texture shadows, all receiver materials will get an additional pass that modulates the colour. It will stay there regardless whether you disable shadows on a viewport. Therefore disabling shadows might not works as expected.
Thanks for the links. I will read through them properly. Based on a quick look though, I just wanted to clarify something. Are you suggesting that it might be worth trying using one of the alternative shadow map techniques available in Ogre (like LiSPSM), as opposed to the standard texture shadows to see if it solves the issue?
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 850
Joined: Sun Mar 30, 2014 2:51 pm
x 165
Contact:

Re: Lighting in Mini-Map question

Post by paroj » Thu May 23, 2019 3:36 pm

I think that the camera setup has something to do with the fact that moving the object influences the rendering. However the core issue is rather that disabling shadows does not work.
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Thu May 23, 2019 3:50 pm

paroj wrote:
Thu May 23, 2019 3:36 pm
I think that the camera setup has something to do with the fact that moving the object influences the rendering. However the core issue is rather that disabling shadows does not work.
I see. In that case I'm not really sure how to go about fixing the problem. I've tried to base my camera and shadow setup from the examples, but I guess I must have made a mistake somewhere that's causing the issue. Here is the code setup for my camera, main viewport and shadows. The code for the RTT viewport is in the original post.

Code: Select all

sceneManager = root->createSceneManager("DefaultSceneManager", "Scene");
sceneManager->setAmbientLight(Ogre::ColourValue(1, 1, 1));
sceneManager->setShadowTechnique(Ogre::ShadowTechnique::SHADOWTYPE_TEXTURE_MODULATIVE);
sceneManager->setShadowTextureCountPerLightType(Ogre::Light::LT_SPOTLIGHT, 1);
sceneManager->setShadowTextureSettings(2048, 1);
sceneManager->setShadowColour(Ogre::ColourValue(0.35f, 0.35f, 0.35f));
sceneManager->setShadowFarDistance(550);

Code: Select all

node.reset(sceneManager->getRootSceneNode()->createChildSceneNode());
node->lookAt(Ogre::Vector3(0, 0, 0), Ogre::Node::TransformSpace::TS_WORLD);

camera.reset(sceneManager->createCamera("Camera"));
camera->setNearClipDistance(1);
node->attachObject(camera.get());

viewport = m_window->addViewport(camera.get());
viewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 1.0f));
viewport->setCamera(camera.get());
viewport->setOverlaysEnabled(true);

camera->setAspectRatio(Ogre::Real(viewport->getActualWidth() / viewport->getActualHeight()));
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Fri May 24, 2019 12:27 pm

Code: Select all

Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
matPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
matPtr->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
rect->setMaterial(matPtr);
I've found a solution to the problem, if I add the line matPtr->setReceiveShadows(false) to the above RTT material code from the original post, the problem is resolved and the RTT viewport is fully lit like the main viewport.
1 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 850
Joined: Sun Mar 30, 2014 2:51 pm
x 165
Contact:

Re: Lighting in Mini-Map question

Post by paroj » Fri May 24, 2019 3:17 pm

so it was the minimap rect receiving shadows? would not have guessed.. but it makes somehow sense..
0 x

Owl53
Halfling
Posts: 83
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Re: Lighting in Mini-Map question

Post by Owl53 » Fri May 24, 2019 3:49 pm

paroj wrote:
Fri May 24, 2019 3:17 pm
so it was the minimap rect receiving shadows? would not have guessed.. but it makes somehow sense..
Apparently so, I wouldn't have either, tried so many other things before considering this, just glad it's solved now :) Thanks for helping me identify the problem!
0 x

Post Reply