Page 1 of 1

porting from Ogre 1.9 to 1.12.1 Shadows error with Direct3D11

Posted: Thu Sep 05, 2019 4:02 pm
by luis
Ogre Version: :1.12.1
Operating System: :Windows 10
Render System:: Direct3D11

Hi, we're updating from Ogre 1.9 to Ogre 1.12.1 and I'm having a problem with the texture shadows I just don't know how to solve it....
We are using terrains defined with a heightmap and our own TerrainMaterial generator class, everything works fine in OpenGL but in direct3d11 shadows doesn't work (see the video).

TerrainMaterial generator, code creating

Code: Select all

TerrainMaterial::Profile::generate(const Ogre::Terrain* terrain)
{
	// delete previous material definition and create a new one using updated texture names
	mat = Ogre::MaterialManager::getSingleton().getByName( TERRAIN_MATERIAL_NAME );
	if (!mat.isNull())
	{
        	Ogre::MaterialManager::getSingleton().remove(matName);
	}
	// get parent to resolve image files
	TerrainMaterial* parent = static_cast<TerrainMaterial*>(getParent());
	mat =	Ogre::MaterialManager::getSingleton().create(
						TERRAIN_MATERIAL_NAME, parent->mResourceGroup);
	mat->setCullingMode( Ogre::CULL_CLOCKWISE );
	mat->getTechnique(0)->setAmbient( 1.0, 1.0, 1.0 );
	mat->getTechnique(0)->setDiffuse( 1.0, 1.0, 1.0, 1.0 );
	mat->getTechnique(0)->setSpecular( 0.2, 0.2, 0.2, 0.2 );
	mat->getTechnique(0)->setLightingEnabled( false );
	mat->setReceiveShadows( true );
	
	****** more code related to detail and skid marks here, not relevant ****
	
	tu = mat->getTechnique(0)->getPass(0)->createTextureUnitState();
	tu->setContentType( Ogre::TextureUnitState::CONTENT_SHADOW );
	tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER);
	tu->setTextureBorderColour(Ogre::ColourValue::White);
	return mat;
};	
And this is the shadows setup:

Code: Select all

	mSceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED );
	mSceneMgr->setShadowTextureSelfShadow(true);
	mSceneMgr->setShadowCasterRenderBackFaces(true);
	mSceneMgr->setShadowColour( ColourValue(0.45,0.45,0.45) );
	mShadowCameraSetup = new Ogre::LiSPSMShadowCameraSetup();
	Ogre::ShadowCameraSetupPtr currentShadowCameraSetup = Ogre::ShadowCameraSetupPtr(mShadowCameraSetup);
	mSceneMgr->setShadowCameraSetup( currentShadowCameraSetup );

	mShadowCameraSetup->setOptimalAdjustFactor( GBGlobals::CAMERA_SHADOW_ADJUST_FAR );
	mSceneMgr->setShadowTextureSize( 2048 );
	mSceneMgr->setShadowFarDistance( 300.0f );
	mCamera->setNearClipDistance( 0.25 );
	mCamera->setFOVy( Degree( 50.0 ) );
This is how it looks now with Direct3D11 and Ogre 1.12.1


Any ideas ? thank you

Re: porting from Ogre 1.9 to 1.12.1 Shadows error with Direct3D11

Posted: Fri Sep 06, 2019 10:02 am
by luis
BTW: I have compiled Ogre 1.12.1 from sources using VS2019, all ogre samples starts but many of them don't show shadows correctly.... Terrain sample doesn't have any shadows in my own compilation nor in the pre-compiled SDK distribution.

If I activate the shadows the house meshes turns red:
ogreerror.jpg

Re: porting from Ogre 1.9 to 1.12.1 Shadows error with Direct3D11

Posted: Fri Sep 06, 2019 11:23 am
by paroj
yes, there is currently some bug with terrain shadows and D3D11. From your video it seems like some matrix (view?) is transposed.

However, as some demos do work (shadows, character), you can try to spot the difference. Also note that exactly the same HLSL shaders work fine with D3D9.

When you find the bug, please also create a pull-request.

Re: porting from Ogre 1.9 to 1.12.1 Shadows error with Direct3D11

Posted: Fri Sep 06, 2019 3:50 pm
by luis
paroj wrote:
Fri Sep 06, 2019 11:23 am
yes, there is currently some bug with terrain shadows and D3D11. From your video it seems like some matrix (view?) is transposed.

However, as some demos do work (shadows, character), you can try to spot the difference. Also note that exactly the same HLSL shaders work fine with D3D9.

When you find the bug, please also create a pull-request.
Yes, I have compared my code and the samples in the way the texture unit and material are created and everything looks the same, so I have no idea why it isn't working. Also there is no Ogre sample using LiSPSMShadows.

If the bug is in inside Ogre I won't be able to spot the bug, I have zero knowledge about shaders..... :(