Tangent generator destroys meshes?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Tangent generator destroys meshes?

Post by omaremad »

The tangent generator seems destroy mesh data (1.7.1&1.7.2 confirmed) in certain settings. also seems to invert the tangent at uv seams?

Here is what i mean

Image

Project files atatched as well so people who have tangent meshes that work fine in irrlicht can try my code aswell. 2megs

http://www.mediafire.com/?02oydkf3u3un3do
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Same here, When i enable "recalculate normals", "smooth", or "angleWeighted" everything starts to look messed, exactly like that.

Although my renders show a correct normal mapping using the default option (everything off, but "recalculate Tangets") I will take a peek to the models.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Image

This is what i get just with the default options.

The model has some serious triangulation problems, but seem present on the Xnormal preview, so, i guess they aren't important.

There are some seams too, but they aren't as visible as the samples you posted. The normal map is the one provided, while the textures are some of mine.

Try the create Tanget mesh method without parameters (the default ones, that is everything false, but the last one), and see how it goes. That is how that model is loaded.

this is my code for loading static meshes, is pretty straight, as you can see.

Code: Select all

irr::scene::IAnimatedMeshSceneNode* FrameWork::loadModel(string s){

	core::stringc currentPath = dev->getFileSystem()->getWorkingDirectory();
	irr::scene::IAnimatedMeshSceneNode* model=0;
	irr::scene::IAnimatedMesh* LoadedMesh = 0;
	irr::scene::IMesh* Tmesh=0;
	irr::scene::IAnimatedMesh* AMesh=0;
	unsigned int i,j;

	if(!smgr->getMeshCache()->isMeshLoaded(core::stringw(s.c_str()))){

		LoadedMesh = smgr->getMesh(core::stringc(s.c_str()));
		Tmesh = smgr->getMeshManipulator()->createMeshWithTangents(LoadedMesh);
		smgr->getMeshCache()->removeMesh(LoadedMesh);

		if(Tmesh){
			AMesh = smgr->getMeshManipulator()->createAnimatedMesh(Tmesh);
			Tmesh->drop();
			if(AMesh){
				AMesh->getMesh(0)->setHardwareMappingHint(scene::EHM_STATIC);
				smgr->getMeshCache()->addMesh(core::stringw(s.c_str()),AMesh);
				model = smgr->addAnimatedMeshSceneNode(AMesh,smgr->getSceneNodeFromId(0xFEE00000));
				AMesh->drop();
			}
		}

	}else{//La malla ya estaba...
		AMesh = smgr->getMesh(core::stringc(s.c_str()));
		model = smgr->addAnimatedMeshSceneNode(AMesh,smgr->getSceneNodeFromId(0xFEE00000));
	}

	if(model){
		dev->getFileSystem()->changeWorkingDirectoryTo(path);

		for(i=0;i<model->getMaterialCount();i++){
			model->getMaterial(i).MaterialTypeParam = 192;
			model->getMaterial(i).AmbientColor=video::SColor(255,255,255,255);
			model->getMaterial(i).AntiAliasing = antialiasing;
			model->getMaterial(i).NormalizeNormals = true;
			model->getMaterial(i).Lighting=true;
			model->getMaterial(i).Shininess = 50;
			model->getMaterial(i).setTexture(2,nullNormal);
			model->getMaterial(i).setTexture(4,shadowmapTarget);//El Shadowmap target va ahi
			for(j=0;j<8;j++){
				model->getMaterial(i).TextureLayer[j].TrilinearFilter = true;
			}
		}

		dev->getFileSystem()->changeWorkingDirectoryTo(currentPath);
	}
	return model;
}
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Ok thanks for testing the mesh. Your application is directx right?
Seems for opengl i had to invert the binormal to get rid of the strange inverted normals at the boundries of uv islands. Now its better but the uv seams still show...

maybe this should be done at driver level?

I think there is a specific special case code that handles these seams, i will try and find it.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Yeah, i use directX.
Seems for opengl i had to invert the binormal to get rid of the strange inverted normals at the boundries of uv islands. Now its better but the uv seams still show...
I don't know... i knew how to map properly the binormal and tangent seeing the irrlicht source, in the DX driver code, where the extra materials were created from ASM code inside the source. Watch where the binormals and tangents are stored in OpenGL, and i hope everything goes finally well. The code for the tangents generation is independent from the drivers, so, in theory, it should work the same for OGL and DX

I don't think that the binormals are wrong in the UV boundaries. I could think better of a miscalculation or an accidental exchange of binormal and tangents, who knows?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Mel: the drivers differ in handedness.

I made some hash based seam detection code however i cant smooth the tangents exactly same way xnormal is doing it since its closed source. Ill just implement blenders tangent generator and use that as a baker.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

But you can still invert the order of the matrix/point multiplication to invert the direction of the binormal or the tangent. can't you?

Anyway, i am really unsure, since i work more with DX than OGL :?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Yep im doing that in shader.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
TCM
Posts: 53
Joined: Mon May 24, 2010 9:29 pm

Post by TCM »

omaremad wrote:Yep im doing that in shader.
Can you please explain how you do that in the shader?
Post Reply