Jump to content
  • Advertisement
Sign in to follow this  
vcGamer

Shader declaration

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all I'm working on toon shader and I need to address two 1 dimensional texture coordinates, but while coding in D3D 9, I just can't get my declaration object sut up properly when I do so: { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, { 0, 24, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, //{ 0, 28, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, (D3DDECLUSAGE_TEXCOORD,1), 0 }, D3DDECL_END() when I uncomment the last line, the declaration object crashes up, what is going wrong here? I suppose it should be possible to work with a FLOAT2? am I right?

Share this post


Link to post
Share on other sites
Advertisement
the last variable of a D3DVERTEXELEMENT9 is the usage index. In HLSL, it's like POSITION0, POSITION1, POSITION2, TEXCOORD0, TEXCOORD1, etc. Not using an integer after the type is simply considered as index 0.

{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 28, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },

I've never used a 1 dimensional texture coordinate though, can't guarantee that it works, but you should just use a D3DDECLTYPE_FLOAT2 like so.

{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },

by the way, include <stddef.h> and you can use the offsetof macro

{ 0, offsetof(the_structure, position), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, offsetof(the_structure, normal), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, offsetof(the_structure, texture_coord), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },

[Edited by - Lee_ on June 1, 2005 9:58:06 AM]

Share this post


Link to post
Share on other sites
lol. I just realized that "(D3DDECLUSAGE_TEXCOORD,1)" ignores D3DDECLUSAGE_TEXCOORD and sets it to 1 which is D3DDECLUSAGE_BLENDWEIGHT.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!