Upgrading Irrlicht

By on September 20, 2013

I thought I’d try to upgrade from the ancient version of Irrlicht we use (1.7.2) to something newer. Checked out the trunk version of Irrlicht, which is 1.9+ and not yet released. There were some bugs, which had to be fixed. There were some problems with XEffects, but they turned out to be related to some weird int-reference to float-pointer cast into setPixelShaderConstant and setVertexShaderConstant methods.

It was this. Notice the unsigned-int-reference-cast-into-float-pointer. It puzzles me it did work with 1.7.2 of Irrlicht:

// DO NOT USE THIS
if(services->getVideoDriver()->getDriverType() == irr::video::EDT_OPENGL)
{
	irr::u32 TexVar = 0;
	services->setPixelShaderConstant("ColorMapSampler", (irr::f32*)(&TexVar), 1);

	TexVar = 1;
	services->setPixelShaderConstant("ScreenMapSampler", (irr::f32*)(&TexVar), 1);

	TexVar = 2;
	services->setPixelShaderConstant("DepthMapSampler", (irr::f32*)(&TexVar), 1);

	TexVar = 3;
	services->setPixelShaderConstant("UserMapSampler", (irr::f32*)(&TexVar), 1);
}

Now it is:

// DO NOT USE THIS
if(services->getVideoDriver()->getDriverType() == irr::video::EDT_OPENGL)
{
	float TexVar = 0.0f;
	services->setPixelShaderConstant("ColorMapSampler", &TexVar, 1);

	TexVar = 1.f;
	services->setPixelShaderConstant("ScreenMapSampler", &TexVar, 1);

	TexVar = 2.f;
	services->setPixelShaderConstant("DepthMapSampler", &TexVar, 1);

	TexVar = 3.f;
	services->setPixelShaderConstant("UserMapSampler", &TexVar, 1);
}

But that was a digression.

Here is a screenshot where Irrlicht from trunk is used.

Axe in 1.7.2

Here is the axe where the texture is somewhat strange. The same was visible on the palms too.

Axe in 1.9+ (trunk)

Axe in 1.9+ (trunk)

Replaced the generated texture with a texture from file. At least nothing wrong with the model.

Palms where the texture is loaded from file and not generated.

Palms where the texture is loaded from file and not generated.

Tried the 1.8 branch of Irrlicht. Better, but still some bugs present, like no graphics for explosions.

Palms with Irrlicht 1.8.2. Sort of a dramatic sunrise.

Palms with Irrlicht 1.8.2. Sort of a dramatic sunrise.

The result? I downgraded to Irrlicht 1.7.2, but it wasn’t quite as expected. I actually had to reverse the changes in the shader callbacks to get the shaders working again. Again, I was puzzled and it seems there have been some large changes internally with the shader handling in Irrlicht between branches 1.7 and 1.8. That is to be expected, but what is sort of puzzling is that the code did work with the minimal changes afterall.

The final shader callbacks follow this pattern to allow for (almost) painless future upgrade of Irrlicht:

// This can be used
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
#if IRRLICHT_VERSION_MINOR == 7
	int TexVar = 0;
#else
	float TexVar = 0;
#endif
	services->setPixelShaderConstant("ColorMapSampler", (float*)(&TexVar), 1);
}

If the version of Irrlicht is 1.7-something, use the int version. If not (in reality 1.8 or 1.9), use the float version. I don’t care about 1.6 and below.

Posted in: coding
Tagged: , , , , ,

Comments

Be the first to comment.

Leave a Reply