Smooth normals, not!

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Dog-E
Posts: 28
Joined: Sun Mar 30, 2008 5:52 am

Smooth normals, not!

Post by Dog-E »

Hello everyone,

I have been having major issues with smooth normals. I mean, the first time I had the issue, I figured out that it was because of the file format (3DS), so I moved to MD2 and it was working well. Now after that with other shaders I was never able to got the smooth normals to work.

I'm using this one:
http://www.irrlicht3d.org/wiki/index.ph ... ByOmaremad

I believe if I solve this one, I'll figure it out permanently. So any help would be appreciated.

Thanks!


Here is what I get in RenderMonkey:

Image

and here is what I get in Irrlicht:

Image

Irrlicht:

Code: Select all

	//Shader test
	IAnimatedMesh* boxmesh = resourceManager_.getMesh( resourceManager_.loadMeshFromFile( 
			"root/models/OBJ/ninjaHead.obj" ) ).getRawPointer();
	IMesh* tangentMesh = sysInt_.getScene()->getMeshManipulator()->createMeshWithTangents( boxmesh->getMesh( 0 ) );
	ISceneNode* boxScene = sysInt_.getScene()->addMeshSceneNode( tangentMesh );
	
	ITexture* colorMap = resourceManager_.getTexture( resourceManager_.loadTextureFromFile( 
			"root/textures/BMP/VariableSpecular.bmp" ) ).getRawPointer();
	ITexture* normalMap = resourceManager_.getTexture( resourceManager_.loadTextureFromFile( 
			"root/textures/TGA/ati.tga" ) ).getRawPointer();
	boxScene->setMaterialTexture(0,	colorMap);
	boxScene->setMaterialTexture(1,	normalMap);
//	boxScene->setScale( vector3df( 1.7, 1, 1.7 ) );
//	boxScene->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
	boxScene->setPosition( vector3df( 2002.71f, 170.0f, 2294.66f ) );
	boxScene->setMaterialType( (irr::video::E_MATERIAL_TYPE)( fxCompositor_.getEffect( FXCompositor::DIFFUSE_ENV_SPECULAR ) ) );
Callback:

Code: Select all

VEC3D lightPos( 80, 85, 100 );
	VEC3D viewPos( SystemInterface::getInstance().getScene()->getActiveCamera()->getAbsolutePosition() );
	
	core::matrix4 world = driver_->getTransform( video::ETS_WORLD );
	world = world.makeInverse();
	world = world.getTransposed();
	
	services->setVertexShaderConstant("matWorldInverseTranspose", world.pointer(), 16);
	services->setVertexShaderConstant("fvLightPosition", reinterpret_cast<f32*>(&lightPos), 3);
	services->setVertexShaderConstant("fvEyePosition", reinterpret_cast<f32*>(&viewPos), 3);
	
	VEC4D fvLowTone(1, 1, 1, 1);
	VEC4D fvSpecular(1, 1, 1, 1);
	VEC4D fvHighTone(1, 1, 1, 1);
	float fSpecularPower = 23.94250f;
	
    int var0=0;
    services->setPixelShaderConstant("baseMap", (float*)(&var0), 1); //the colormap
    
    int var1=1;
    services->setPixelShaderConstant("cube", (float*)(&var1), 1); //the cubemap 
	
	services->setPixelShaderConstant("fvLowTone", reinterpret_cast<f32*>(&fvLowTone), 4 );
	services->setPixelShaderConstant("fvSpecular", reinterpret_cast<f32*>(&fvSpecular), 4 );
	services->setPixelShaderConstant("fvHighTone", reinterpret_cast<f32*>(&fvHighTone), 4 );
	services->setPixelShaderConstant("fSpecularPower", reinterpret_cast<f32*>(&fSpecularPower), 1 );
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yeah, also .obj had a problem with smooth normals (unless you use the vertex normals directly). It was due to the vertices being duplicated (in order to support vertex normals without much overhead). But you're lucky, the latest SVN revisions (both the 1.4 branch and trunk) have this fixed, so you can smooth the normals again.
Dog-E
Posts: 28
Joined: Sun Mar 30, 2008 5:52 am

Post by Dog-E »

This one is MD2:

Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

md2 has no smooth normals - never. This is because there are only a few normal vectors which are allowed in md2. The format defines a set of normals which are indexed from each vertex. This means that you get a vertex normal with just one byte per vertex, which means 11 bytes saved (IIRC), but that also means that you will never have smoothed normals. Try b3d, ms3d, or .x, which all have a proper concept of vertex normals.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

but once the md2 is loaded it's presumably put into the same structure as the other formats use when loaded so couldn't you then recalculate the normals to make them smooth?

surely the mesh manipulators function for this would work?
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, that would work, but since md2 meshes are just one meshbuffer the horse in this case would be pretty round after the manipulation :lol:
Dog-E
Posts: 28
Joined: Sun Mar 30, 2008 5:52 am

Post by Dog-E »

The dwarf.X out of Irrlicht:

Image
Dog-E
Posts: 28
Joined: Sun Mar 30, 2008 5:52 am

Post by Dog-E »

Finally got it to work with the X format. It seems like when I did not calculate the tangents it worked. It worked with Obj too and even with MD2.

Why could it be?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The smoothed normals are lost in the current tangent calculation method. Since the improved one from the forum couldn't be verified to work correctly until very recently, it wasn't integrated into the engine, yet. But it will be, then smoothed normals won't be lost anymore.
Post Reply