Newbie color question

Started by
7 comments, last by oliver_mpt 14 years, 2 months ago
Hello ! I'm new to DirectX, coming from OpenGL. I've noticed that 3D objects must have a color parameter for each vertex. In the case of an object with uniform color, I would like to change its color, in order to redraw it several times with different colors. Is there a way without changing the color in all vertices ? it seems pretty inneficient to me. In particular, we have the option to store the vertex and index buffers in different memories to optimize loading speed. In that case accessing to all vertices to change color is particularly not efficient. Is there something like glColor in OpenGL that allow me to change the current color - DO I need absolutely to store it in ALL vertex ? regards, Olivier
Advertisement
Are you referring to the fixed function pipeline?

IMHO the best solution is to write a simple shader.
Don't use the vertex color, set a float4 parameter and in the pixel shader just output that color.
You don't *have* to have colour per vertex, unless you are using the fixed function pipeline to render with. You could have a vertex structure like this...

float x, y, z; // Position
float nx, ny, nz; // Normal

And then use a shader to render with what ever colour you like.

If you *are* using the FFP then I think the only way is with vertex format...

float x, y, z; // Position
float nx, ny, nz; // Normal
DWORD colour; // Colour

Which means changing each vertex colour before rendering - which shouldn't be a major problem depending on how many vertices you are dealing with.

For the most efficient way, I think go the shader route - FFP rendering is becoming obsolete.
Hi,

With FFP you can use the material parameters to change the object color. No need to have per-vertex color.

Cheers!
Hello

Thanks for all the answers,

I'm not sure I unsderstand, though.
doest it read FFP = directX9 and shader route = DX10 ?

I need absolutely Windows XP compatibility, so as far as I understand no DX10.

can you clarify a bit for me ? (I told you: newbie question ;-))

Oliver
No shaders have been around for a while I think since D3D8 even...so you can have shaders in D3D9 no need for D3D10...until tomorrow...then D3D11...D3D12 etc :)
Quote:
I'm not sure I unsderstand, though.
doest it read FFP = directX9 and shader route = DX10 ?

Not exactly.

DirectX9 = FFP or shaders, depends on what you decide to use.
DirectX10 = shaders, there's no FFP.
For D3D9, I'd suggest using pixel shaders whether you use FFP or shaders for the vertices. They're simply a lot easier to understand and program than texture stages.
Thanks a lot for your help.
I'll try with pixel shaders, it seems well suited to my purpose

regards

Oliver

This topic is closed to new replies.

Advertisement