Page 1 of 1

Help getting normals to display correctly

Posted: Tue Dec 14, 2010 3:00 pm
by Scribe
Hi guys,

I'm half way through writing an all in one image/FBX to xBGR16/NDS DisplayList converter tool, I have reached the point of testing a basic model so have create a simple cube in Maya and exported as an fbx and converted with my tool. I am able to then display the converted DisplayList on screen and see the cube, however, I'm unable to get it displaying correctly once I feed in the normal information. All I see is half a face.

I've confirmed that all of my normals are normalised and are are axially aligned (as the cube faces are straight) as so contain the value 1 on one of the axis and 0 on the others so this should be a fairly simple situation.

Here's my conversion code, and below I'll attach two screen shots, with and without normal data:

Code: Select all

meshFile->Write( (UInt32)FIFO_COMMAND_PACK( FIFO_BEGIN,FIFO_TEX_COORD, FIFO_VERTEX16, FIFO_NORMAL ) );
			meshFile->Write( (UInt32)GL_TRIANGLES );
			
			for( int i = 0; i < mesh->GetPolygonCount()*3; ++i )
			{			
				// Fetch vertex from polygon
				KFbxVector4 vertex = controlPoints[mesh->GetPolygonVertex( i/3, i%3 )];
				KFbxVector4 normal;
				mesh->GetPolygonVertexNormal( i/3, i%3, normal );
				//normal.Normalize();
				KFbxVector4 texture = controlPoints[mesh->GetTextureUVIndex( i/3, i%3 )];

				// Write Tex-Coord
				meshFile->Write( (UInt32)TEXTURE_PACK(floatToFixed164( vertex.GetAt( 0 ) ), floatToFixed164( vertex.GetAt( 1 ) )) );
				// Write vertex
				meshFile->Write( (UInt32)VERTEX_PACK(floatToFixed3212( vertex.GetAt( 0 ) ), floatToFixed3212( vertex.GetAt( 1 ) )) );
				meshFile->Write( (UInt32)VERTEX_PACK(floatToFixed3212( vertex.GetAt( 2 ) ), 0) );
				// Write Normal
				meshFile->Write( (UInt32)NORMAL_PACK(floatToFixed1010( normal.GetAt( 0 ) ), floatToFixed1010( normal.GetAt( 1 ) ), 
					floatToFixed1010( normal.GetAt( 2 ) )) );

				// Write next command pack
				if( mesh->GetPolygonCount()*3 - i > 1 )
				{
					meshFile->Write( (UInt32)FIFO_COMMAND_PACK(FIFO_TEX_COORD, FIFO_VERTEX16, FIFO_NORMAL, FIFO_NOP ) );
				}
			}
//.......................Normal float to fixed function
// Floating-point to fixed point 10-bit (10-bit fractional) convertion
	private: fbxShort1 floatToFixed1010( fbxDouble1 floatingPoint )
	{
		const static fbxInteger1 factor = 1 << 9;

		if( floatingPoint > 0.998 )
		{
			return (fbxShort1)0x1FF;
		}
		else
		{
			return static_cast<fbxShort1>(floatingPoint*factor);
		}
	}
cube normal.png
With Normals
(5.81 KiB) Not downloaded yet
cube.png
Without Normals
(5.57 KiB) Not downloaded yet
Thank you very much for any help/advice, please ask if you need any more information.

Re: Help getting normals to display correctly

Posted: Tue Dec 14, 2010 8:59 pm
by zeromus
The first thing to try when debugging issues like this is to get rid of the command packing. Command packing is an advanced technique and should be added in later once you know that everything is working and you understand all the related issues.

I assume youve satisfied yourself that your normals are already normalized since you commented out that line?

And finally, if you post your buildable nds project then im sure it could get debugged.

Those pics arent very helpful. What are the numbers, and are the scenes even the same?

Re: Help getting normals to display correctly

Posted: Sat Dec 18, 2010 2:12 am
by Scribe
Hi,

Problem solved,

The error was misleading, I had not correctly configured my lighting and so in an attempt to see a visual result I stuck with display list ordering that placed normals after vertices, but in exchange then when I fixed my lighting the results weren't showing.

So in short it's vital that normals go first even in the display list and that you set-up lighting correctly! =P

Now to resolve my next issue of dodgy rendering of more complex models...

Cheers

Re: Help getting normals to display correctly

Posted: Sat Dec 18, 2010 2:46 am
by zeromus
It may be beating a dead horse since youve already figured it out, but for the record, on the nds, the normal sets the color which gets committed when the vertex is submitted. setting a normal after a vert does nothing but set the color for the next vert.