Sign in to follow this  

D3DCOLOR confusing me...

This topic is 4534 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

ok So my FVF is: #define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_NORMAL ) and my format is: typedef struct { D3DXVECTOR3 pos; D3DCOLOR color; float tu, tv; D3DXVECTOR3 norm; } VERTEX_MAP; So thats right, but in my shader I dont want to send a D3DCOLOR value, I want to send in a float r, g ,b type. not the DWORD that a D3DCOLOR value is... How do I do this inside of VERTEX_MAP struct? Thanks much, So basically, What do I put instead of D3DFVF_DIFFUSE if I want a float4 in there? Brad

Share this post


Link to post
Share on other sites
I think there's nothing you can do about D3DFVF_DIFFUSE but you can (again I think...) specify a
D3DCOLORVALUE instead od D3DCOLOR which is an A, R, G, B structure.

Each component has a value in the range 0.0 to 1.0 and these values will be converted back into DWORD for the final render.

[Edited by - VerMan on February 24, 2006 3:46:13 PM]

Share this post


Link to post
Share on other sites
Well my problem is my vertex shader takes in a color value(float4) and I cant have directx sending it a DWORD can I when im expecting 4 floats? so I need some how I can send it a float 4 instead of a DWORD but D3DFVF_DIFFUSE links to a D3DCOLOR(dword) right?

Share this post


Link to post
Share on other sites
Yea I was looking into that, but was hoping to just stay with FVF unfortunatly I think yer right there is no way to do it with FVF...

Thanks for the help guys, always appreciated.

EDIT:

I looked at that and it uses D3DDECLUSAGE_COLOR instead, which is STILL a dword value. I guess im at how do I let my vert shader accept a dword value and then how do I split it back to 3 floats inside of the shader?

thats a pain in the ass.

Or on D3DVERTEXELEMENT9 can you specify a float4 and use that as a color without problems if im making the shaders?

Share this post


Link to post
Share on other sites
I've only worked with Vertex Declarations once, and that was with the fixed function pipeline, so forgive me if I'm wrong, but could you not specify D3DDECLTYPE_FLOAT3 or D3DDECLTYPE_FLOAT4 for the type of the vertex element, and D3DDECLUSAGE_COLOR for the usage? And then specify the offsets appropriately as well, of course. It doesn't state that D3DDECLUSAGE_COLOR specifically refers to a 4-byte value; just that it refers to a color.

Share this post


Link to post
Share on other sites
Quote:
Original post by Agony
I've only worked with Vertex Declarations once, and that was with the fixed function pipeline, so forgive me if I'm wrong, but could you not specify D3DDECLTYPE_FLOAT3 or D3DDECLTYPE_FLOAT4 for the type of the vertex element, and D3DDECLUSAGE_COLOR for the usage? And then specify the offsets appropriately as well, of course. It doesn't state that D3DDECLUSAGE_COLOR specifically refers to a 4-byte value; just that it refers to a color.



Right I just hate assuming with DX. I read about the defaults and it scared me away a bit, but if that is a commmon way to do it, then I guess a "hell yea!" is in order :). Thanks

Share this post


Link to post
Share on other sites
Agony is correct. You could specify a 3-component float as your vertex colour in the vertex declaration using D3DDECLTYPE_FLOAT3 instead of D3DDECLTYPE_D3DCOLOR.

Just a question, though: If the maximum precision a colour component can have in 24bit is [0,255], what would be the point of bloating a vertex with 8 more bytes than you need? It would be far more efficient to just multiply your R,G,B float values by 255, convert to them to unsigned int, and store that number, using the D3DCOLOR_ARGB macro, into the DWORD.

Share this post


Link to post
Share on other sites
Quote:
Original post by sordid
Agony is correct. You could specify a 3-component float as your vertex colour in the vertex declaration using D3DDECLTYPE_FLOAT3 instead of D3DDECLTYPE_D3DCOLOR.

Just a question, though: If the maximum precision a colour component can have in 24bit is [0,255], what would be the point of bloating a vertex with 8 more bytes than you need? It would be far more efficient to just multiply your R,G,B float values by 255, convert to them to unsigned int, and store that number, using the D3DCOLOR_ARGB macro, into the DWORD.


Well I save my values as 255r, 255g, 255b order already. Inside of my shader I take the vertex colors and multiply them accordingly against my lights and what not.

What would be the best way then of doing this? Keeping the dword value? And if so whats the best way of using it in a shader instead of using r,g,b? All my examples and books have used r,g,b format thats why I havent invested much time in the DWORD format directx uses. I guess I need some help understand that then if it can save space and have almost no impact on speed.

Share this post


Link to post
Share on other sites
In your vertex declaration, use the DWORD value to save 8 bytes per vertex.

In shaders, everything is converted into floats anyway (ie. VertexColor : COLOR0 has components .r, .g, and .b which are [0..1] float)

Share this post


Link to post
Share on other sites
Quote:
Original post by sordid
In your vertex declaration, use the DWORD value to save 8 bytes per vertex.

In shaders, everything is converted into floats anyway (ie. VertexColor : COLOR0 has components .r, .g, and .b which are [0..1] float)


Ahh ok, so on my vertex declaration I can just use DIFFUSE and then use the macro to convert all my values to that, then when it hits the shader it automatically is split into floats r g b? That makes it nice...

EDIT: I went ahead and tried it with the old route, and the shader is not getting any color values from D3DCOLOR_RGBA macro. Passing from my vertex shader to my pixel shader is fine. And going from from there to my deferred shading is all fine. Its not going into my vertex shader correctly. Also, does it not expand on FVF only VERTEXELEMENT?

EDIT2: I found the answer, FVF does not expand D3DCOLOR to rgb floats. declarations will. (In my tests)

[Edited by - xsirxx on July 19, 2005 3:40:11 PM]

Share this post


Link to post
Share on other sites

This topic is 4534 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this