Is there any workaround to enable shadows for point lights or spot lights?

asked 2021-01-03 21:04:51 -0600

Veerachart gravatar image

I understand that shadows for point lights and spot lights are disabled, as discussed in issue 2083. I also checked in the source code of gazebo 11 and saw that shadows of gazebo's point lights and gazebo's spot lights cannot be enabled.

From this OGRE's tutorial, we can see that point lights and spot lights can generate shadows, so I guess it's not impossible by OGRE (the version is 1.12 while gazebo 11 uses 1.9, but it should not be that different).

I tried to create a world plugin to modify the shadow techniue, and add light sources directly through OGRE (to avoid the cast shadows being disabled by Gazebo. Below are the snippet of what I did (not sure if anything is unnecessary.

gazebo::rendering::ScenePtr scene = gazebo::rendering::get_scene();
Ogre::SceneManager *sceneManager = scene->OgreSceneManager();

sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE); // This enables shadows, but pixelated lightings
sceneManager->setShadowTextureCount(9);
sceneManager->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
sceneManager->setShadowTextureCountPerLightType(Ogre::Light::LT_POINT, 3);
sceneManager->setShadowTextureCountPerLightType(Ogre::Light::LT_SPOTLIGHT, 3);
for (unsigned int i = 0; i < 9; i++)
{
    sceneManager->setShadowTextureConfig(i, 8096u, 8096u, Ogre::PF_FLOAT32_R);
}
sceneManager->setShadowTextureSelfShadow(true);

// add green light
Ogre::Light *pointLight1 = sceneManager->createLight("point_green");
pointLight1->setDiffuseColour(0, 1, 0);
pointLight1->setSpecularColour(0, 1, 0);
pointLight1->setType(Ogre::Light::LT_POINT);
pointLight1->setCastShadows(true);
Ogre::SceneNode *node1 = sceneManager->getRootSceneNode()->createChildSceneNode();
node1->attachObject(pointLight1);
node1->setDirection(1, 1, 0.2);
node1->setPosition(gazebo::rendering::Conversions::Convert(ignition::math::Vector3d(5, 5, 3)));

// add red light
Ogre::Light *pointLight2 = sceneManager->createLight("point_red");
pointLight2->setDiffuseColour(1, 0, 0);
pointLight2->setSpecularColour(1, 0, 0);
pointLight2->setType(Ogre::Light::LT_POINT);
pointLight2->setCastShadows(true);
Ogre::SceneNode *node2 = sceneManager->getRootSceneNode()->createChildSceneNode();
node2->attachObject(pointLight2);
node2->setDirection(1, -1, 0.2);
node2->setPosition(gazebo::rendering::Conversions::Convert(ignition::math::Vector3d(5, -5, 3)));

Then, I run the world with this plugin, and add a camera with some models (sphere and hatchback car. I can get the shadows, but the lights on the models are not as good as the default lighting. It's even blocky on the sphere. two point lights with shadows

Does anyone know how we can improve the lighting on the models while keeping the shadows?

For reference, my PC has GTX 1050 Ti and has no problems with directional lights and shadows.

edit retag flag offensive close merge delete