Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to get binormal and tangent to work with DBP FVF?

Author
Message
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Nov 2012 14:05 Edited at: 25th Nov 2012 14:10
Hi. In help there is a list of FVF values, but it is not complete. For example, there is no BINORMAL or TANGENT declarations. I need to convert object to use diffuse color and binormal and tangent. I know, thet in C it could be done, but in DBP?

Example:
Quote: "
DWORD dwFVF =
D3DFVF_XYZ |
D3DFVF_NORMAL |
D3DFVF_TEX3 |
D3DFVF_TEXCOORDSIZE2(0) |
D3DFVF_TEXCOORDSIZE3(1) |
D3DFVF_TEXCOORDSIZE2(2);
//and your vs input:
struct INVertexData
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 texture0 : TEXCOORD0;
float3 tangent : TEXCOORD1;
float3 binormal : TEXCOORD2;
};
"

Another example of extra values:
Quote: "
#define FVF_TEXTUREFORMAT2 0 // Two floating point values
#define FVF_TEXTUREFORMAT1 3 // One floating point value
#define FVF_TEXTUREFORMAT3 1 // Three floating point values
#define FVF_TEXTUREFORMAT4 2 // Four floating point values

#define FVF_TEXCOORDSIZE3(CoordIndex) (FVF_TEXTUREFORMAT3 << (CoordIndex*2 + 16))
#define FVF_TEXCOORDSIZE2(CoordIndex) (FVF_TEXTUREFORMAT2)
#define FVF_TEXCOORDSIZE4(CoordIndex) (FVF_TEXTUREFORMAT4 << (CoordIndex*2 + 16))
#define FVF_TEXCOORDSIZE1(CoordIndex) (FVF_TEXTUREFORMAT1 << (CoordIndex*2 + 16))
"

Another example
Quote: "
const D3DVERTEXELEMENT9 vertexDecl[] =
{
{ 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_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
{ 0, 56, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
D3DDECL_END()
};
struct VERTEX_INPUT
{
float4 position : POSITION;
float2 texCoord : TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;

float3 vertcol : COLOR1;
};
"
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 25th Nov 2012 15:31 Edited at: 25th Nov 2012 15:34
The binormal and tangent are stored as float3 TEXCOORDs so you need to include (D3DFVF_TEXTUREFORMAT3 << (CoordIndex * 2 + 16)) twice (one for each of binormal and tangent) but swapping CoordIndex for 1 and 2 respectively.

At least that is my understanding having done a little Googling. http://www.gamedev.net/topic/362388-setfvf/ and http://msdn.microsoft.com/en-gb/library/windows/desktop/bb172560(v=vs.85).aspx

The format you'd want would be D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX3|D3DFVF_TEXCOORDSIZE3(1)|D3DFVF_TEXCOORDSIZE3(2) and D3DFVF_TEXCOORDSIZE3 is defined as (D3DFVF_TEXTUREFORMAT3 << (CoordIndex*2 + 16)) and D3DFVF_TEXTUREFORMAT3 is defined as 1.

Hope that helps!


Previously TEH_CODERER.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Nov 2012 16:32 Edited at: 25th Nov 2012 16:39
set object fvf objnum, 0x002 + 0x010 + 0x300 + ??? + ??? + ??? + 0x040 (vertex color)

I don't understand it...
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 25th Nov 2012 16:58
If I had to guess I would try this:



It certainly runs without issue but I'm afraid I have way too big of a headache to do any more in depth experimentation at the moment.


Previously TEH_CODERER.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Nov 2012 17:15
Many thanks, pal! I will try that and report later!

Also I found this: http://forum.thegamecreators.com/?m=forum_view&t=13104&b=1
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 25th Nov 2012 17:26
No problem, I hope it helps.
Nice find as well; would have saved me a little time in writing that code snippet.


Previously TEH_CODERER.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Nov 2012 17:46 Edited at: 25th Nov 2012 17:47
I just have tested the code. Well, UV's are lost. Also I have had to add SPECULAR to FVF to make vertex color work.

I have read somewhere in the web that SPECULAR is used instead of TANGENT.

I think we just need to find the right offset for UV's.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 25th Nov 2012 18:05
I'm not sure about the use of specular, but the other part would be my mistake for using TEX1 instead of TEX3. Binormal and tangent count as TEXCOORDS so, along with actual UV data, there should be 3 sets of TEXCOORDS. So the line should've been:




Previously TEH_CODERER.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Nov 2012 18:22
It doesn't work too
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 25th Nov 2012 18:38
I'm afraid I'm at a bit of a loss at this stage. Whenever I've used the tangent and binormal in a shader I've always just had them in the struct like this:

float4 Position : POSITION;
float2 UV : TEXCOORD0;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float3 Normal : NORMAL;

and have never had to edit any FVF formats. I've never tried to use the diffuse value as well though.

Hopefully someone else will be able to offer some more info!


Previously TEH_CODERER.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 25th Nov 2012 20:38 Edited at: 25th Nov 2012 20:42
That is works fine until you add vertex color as :COLOR; (and, of course, the colors to object vertices)

I mean there was issues (on different dev sites) with vertex color and tangents, but there was not any good solution (or not enough my knowledge to understand the solution).
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Nov 2012 02:45
What are you using the tangents and binormals for? If you are using a shader which needs them then DBPro computes those for you.



mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 26th Nov 2012 07:54
I need this structure:



I want to use vertex colors and normal mapping.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Nov 2012 12:12
Quote: "I want to use vertex colors and normal mapping.
"


Yes, if I recall correctly there's a problem with the way DBPro handles that - or at least there used to be. I'll try to find time to check.

A simple workaround is to store the rgba components in two additional sets of UV coordinates and remove the diffuse colour. I'm sure someone posted a demo of that solution a few weeks ago.



mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 26th Nov 2012 13:17
I think the solution is in FVF offsets.

P.S. I can paint in UV's, I just want to try to store vertex color without cheating.

Login to post a reply

Server time is: 2026-06-12 20:19:20
Your offset time is: 2026-06-12 20:19:20