Normal Mapping with multiple lights (help please)

Started by
16 comments, last by cozzie 10 years, 2 months ago

Ok. I got it to work (sort-of)... I'm currently having problems with attributes (vertex and index buffer) when there are multiple subsets. I'm using PandaSoft's directx xporter and when I include the "materials" option I can get the correct number of subsets, but it doesn't render correctly. If I don't use the "materials" option, it renders fine, but it renders all of it in a single subset. This is bad because I want to use animation where the different subsets move independently.

I have ideas about how to work around this problem:

-- read the .x file as a text file and extract the info manually

-- separate the subsets into their own .x file and assemble them on load

-- *** figure out what I'm doing wrong and fix it (this is preferred)

Advertisement

Ok. I created a test room and it seems to work fine when the light is centered in the room. When I move the light near the edge, I don't get the correct specular highlights.

[media]http:

[/media]

I'm using a "tangent space normal mapping with multiple lights in a single pass" .fx from http://www.dhpoware.com/demos/index.html

I had to manually read the .x file of the room and convert it to an indexed primitive that uses:


D3DVERTEXELEMENT9 g_roomVertexElements[] =
{
    {0,  0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
    {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
    {0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0},
    {0, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT,  0},
    D3DDECL_END()
};

The struct I used to hold the object info is:


struct MESHINDEXINFO{
	MESHINDEXINFO(){vStart=vCount=iStart=iCount=0;}
	UINT vStart,vCount,iStart,iCount;

	//amimation stuff here
	vector <D3DXMATRIX> KeyframeMatrix;
};
struct EFFECTMESH{
	EFFECTMESH(){VB=NULL;}
	IDirect3DVertexBuffer9 *VB;
	LPDIRECT3DINDEXBUFFER9 IB;
	vector <MESHINDEXINFO> indexInfo;
	int NumSubsets;
	void Release(void);
};
void EFFECTMESH::Release(){
	if (VB!=NULL){
		VB->Release();
		IB->Release();
		VB=NULL;
	}
	indexInfo.clear();
}

As I was saying, every aspect of it seems to work just fine except the specular (as illustrated in the video).....

Any ideas on what I'm doing wrong?

Thanks for the help guys...... wacko.png

I figured it out on my own. For the calculations to work, it needs to thing the camera is at the origin. Now I have another problem:

[attachment=19620:testImage.png]

As you can see, there is a sharp edge at the radius of the light when shinning on the wall. This only occurs on the +x & -x walls. It doesn't do this on any other surface. I tried skewing the vertices to see if that helps, but no joy. Well, rotating the entire box DOES change one thing: The verts that angle more away from the light seem to attenuate properly, but the ones that have been moved toward the light don't.

Let's see who can figure this out faster.....

Just a remark, I think you could rephrase your case and questions a bit to get more and quicker help.

Unfortunately I'm not very experienced yet with normal mapping. But I do know you can try KwXport for exporting X files from 3ds max, with the option to include the binormals and tangents directly. If you do this you can probaly save one step after you've loaded the model/ X file.

The last issue might have something to do with a calculation where your camera position is used but not correctly updated, meaning it would only work at x = 0.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

I'll look into KwXport.

BTW, does this also export skinned and animated meshes?

I figured out my problem. I was calculating the tangent before I read the normals from the file.

Stick with PandaSoft's exporter, it is updated for every new Max version, KWExport hasn't been updated since Max 7-8...

******************************************************************************************
Youtube Channel

Thanks for the info LancerSolurus. Do you have a suggestion for an exporter? Or perhapse a better solution to my (almost) brute force read method?
I'm using kwxport with max 2011 with no problems, including tangents, animation etc.
Good to hear that you fixed it

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement