Jump to content

  • Log In with Google      Sign In   
  • Create Account


Vertex format problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 BSOD   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 May 2012 - 10:54 AM

I read a memory block of vertex positions from an file but they're in this sequance X Z Y and the FVF format is D3DFVF_XYZ - what vertex format to use to fix this problem or maybe changing the coordinate axes?

Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2343

Like
0Likes
Like

Posted 02 May 2012 - 10:58 AM

Hi,

There is no such vertex format as XZY. Either change the component ordering at load time to XYZ or use a swizzle in the vertex shader.

Best regards!

#3 BSOD   Members   -  Reputation: 100

Like
0Likes
Like

Posted 02 May 2012 - 11:06 AM

What is this

swizzle - I mean can you give me an example with a function call?



Best regards!


Thanks!



#4 kauna   Crossbones+   -  Reputation: 2343

Like
0Likes
Like

Posted 02 May 2012 - 12:50 PM

Swizzling is used in any high level shading languages:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509634(v=vs.85).aspx check here for details who swizzling works.

Or simply put in the vertex shader


float4 main(float4 pos : SV_POSITION) : SV_POSITION
{
float4 val = mul(pos.xzyw,World); //y and z components swizzled.

return val;
}

Best regards!

#5 Bacterius   Crossbones+   -  Reputation: 8533

Like
0Likes
Like

Posted 02 May 2012 - 04:47 PM

Can't you just reprocess your vertex file to rearrange the vertices in the coordinate system expected by DX9? Most likely it only involves importing and exporting the file through any good 3D design package or you could even write your own script if the format isn't too complicated.

Edited by Bacterius, 02 May 2012 - 04:48 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#6 BSOD   Members   -  Reputation: 100

Like
0Likes
Like

Posted 03 May 2012 - 04:19 AM

Lol here what I'll read this summer about -

shading. But for now here is what I do: I use a block of structures to store the vertex from the file and then I put it into the vertex buffer. Here is the code:



//The structure where I store the vertex
struct CUSTOMVERTEX {
CUSTOMVERTEX();
FLOAT X, Z, Y; FLOAT U, V, U1, V1; DWORD COLOR, COLOR1, COLOR2;
};

//The vertex format declaration

D3DVERTEXELEMENT9 dwDecl3[] =
	{
{0, 0,  D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_TEXCOORD, 0},
		{0, 20, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT,
									 D3DDECLUSAGE_TEXCOORD, 1},
		{0, 28, D3DDECLTYPE_D3DCOLOR,   D3DDECLMETHOD_DEFAULT,
									 D3DDECLUSAGE_FOG, 0},
{0, 32, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_COLOR, 1},
   {0, 36, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_COLOR, 0},
		D3DDECL_END()
	};

//The function creating the vertex buffer
void Room::CreateBuffers(unsigned long ptr, Map* BaseClass) {
//Some code........

CUSTOMVERTEX* vertex;
vertex=new CUSTOMVERTEX[NumVertices];

GetF(0, ptr+56+BaseClass->MapOffset, sizeof(CUSTOMVERTEX)*NumVertices, &vertex[0]);	  //Load the vertex positions from the file

//Create the buffer


d3ddev->CreateVertexBuffer(NumVertices*sizeof(CUSTOMVERTEX),
								   0,
								   0,
								   D3DPOOL_MANAGED,
								   &v_buffer,
								   NULL);

		 VOID* pVoid;	// a void pointer

		 // lock t_buffer and load the vertices into it
if(v_buffer) {
		 v_buffer->Lock(0, 0, (void**)&pVoid, 0);
		 memcpy(pVoid, vertex, NumVertices*sizeof(CUSTOMVERTEX));
		 v_buffer->Unlock();
delete[] vertex;
}
else
vertex=NULL;

d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
}



Any advice about this code. And I can't change the format because I don't made it - it's from a game.

Edited by BSOD, 03 May 2012 - 04:20 AM.


#7 kauna   Crossbones+   -  Reputation: 2343

Like
1Likes
Like

Posted 03 May 2012 - 05:26 AM

After the part

"GetF(0, ptr+56+BaseClass->MapOffset, sizeof(CUSTOMVERTEX)*NumVertices, &vertex[0]);"

Can't you just iterate through your vertices and swap the z and y components?

Such as

for(int i=0;i<NumVertices;++i)
{
std::swap(vertex[i].z,vertex[i].y);
}
Best regards!

Edited by kauna, 03 May 2012 - 05:27 AM.


#8 BSOD   Members   -  Reputation: 100

Like
0Likes
Like

Posted 03 May 2012 - 06:10 AM

Hmm, actually this work and the program works fast. Because I was think such of loop will slow it down and that's way I was searching for some tricks. Anyway thanks for the advice.

#9 kauna   Crossbones+   -  Reputation: 2343

Like
1Likes
Like

Posted 03 May 2012 - 07:35 AM

Hmm, actually this work and the program works fast. Because I was think such of loop will slow it down and that's way I was searching for some tricks. Anyway thanks for the advice.


I assume that you run that loop only when you are loading your assets. Since the code isn't run while your main loop is executing, it doesn't affect the performance of your program at all.

You shouldn't be afraid of writing a piece of code which does the thing that you need it to do (especially if it is simple loop). After writing the code you may find out (by using facts from profilers and user experience etc) that the code needs to be improved performance wise.

Best regards!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS