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..... :(

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

Posted: Tue Nov 05, 2019 10:56 pm
by paroj
luis wrote:
Fri Sep 06, 2019 3:50 pm
If the bug is in inside Ogre I won't be able to spot the bug, I have zero knowledge about shaders..... :(
with 1.12.3 at least the houses and the RTSS demo will have correct shadows

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

Posted: Thu Dec 26, 2019 4:14 pm
by luis
paroj wrote:
Tue Nov 05, 2019 10:56 pm
luis wrote:
Fri Sep 06, 2019 3:50 pm
If the bug is in inside Ogre I won't be able to spot the bug, I have zero knowledge about shaders..... :(
with 1.12.3 at least the houses and the RTSS demo will have correct shadows
Great! those are good news, I'll recompile my game with 1.12.3 next month after deploying new game features.

I'm having a problem with 1.12.1 since there is no support for saving images except PNG format:

Code: Select all

Ogre::Image thumbnail;
thumbnail.load( projectName + "_terrain.jpg", GBGlobals::TRACKS_RESOURCENAME );
thumbnail.resize( 256, 256 );
thumbnail.save( GBGlobals::TRACKS_PATH + projectName + "_thumbnail.jpg" );
The last call "save" is throwing: InvalidCallException "currently only encoding to PNG supported"

Is there any way to support other formats for saving images ? or do I have to compile ogre with freeimage ?
thank you

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

Posted: Thu Dec 26, 2019 6:01 pm
by paroj
yes, you can extend the STBI codec to write whatever else STBI supports

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

Posted: Fri Dec 27, 2019 1:39 am
by loath
are there any errors in ogre.log?

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

Posted: Fri Dec 27, 2019 4:20 pm
by luis
finally I went for the short route and included stbi header in my project and then:

Code: Select all

bool saveImageToJPGFile(Ogre::String const& fileName, Ogre::Image const& image, int quality)
{
    return (bool)stbi_write_jpg(fileName.c_str(), image.getWidth(), image.getHeight(), 3, image.getData(), quality);
}
In my case, pixel format is always PF_R8G8B8 so I've ignored the check & conversion inside OgreSTBICodec.