Jump to content
  • Advertisement
Sign in to follow this  

How is the color at a vertex eventually determined?

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

The post about Direct3D - Colors and Lighting in the FAQs Section says:

if -
D3DFVF_DIFFUSE is defined in the Vertex structure

then the color at each vertex is defined by
either (Material Or Vertex Color) * Light

(Material Color or Vertex Color) * Light – is determined by a set of four render states:

Each of them can be set to:
(a) D3DMCS_MATERIAL, which uses the value from the material
(b) D3DMCS_COLOR1, which uses the vertex's diffuse color value
(c) D3DMCS_COLOR2, which uses the vertex's specular value

In my sample code i have enabled D3DRS_COLORVERTEX & set D3DRS_DIFFUSEMATERIALSOURCE to D3DMCS_COLOR1 but it never uses either the D3DMATERIAL9.Diffuse params or the vertex color properties defined in the FVF strucuture to render my object, it always uses the D3DMATERIAL9.Ambient params.

Another interesting observation is that if i disable D3DRS_LIGHTING it uses the diffuse params from the FVF vertices to render the object.

Can anyone explain further about this behaviour? Is it that if D3DRS_LIGHTING is enabled per vertex rendering of colors is no longer supported?

Share this post

Link to post
Share on other sites
I'm going to suggest that you not burden yourself with this, nobody uses the fixed functions anymore.

The way you get the pixel color is to write a pixel shader, and write up whatever algorithm you want based on input variables to set the color. You can learn this stuff if you want but it's not really how things are done anymore.

Share this post

Link to post
Share on other sites
Well; I am not really happy with that suggestion.

I am a newbie and interested in getting my understanding right about these fundamental issues before i get on with more complicated models, by the way i am sure I will eventually write a pixel shader for meself one day. But now, I need to understand what this is about...

Another question:
I observed that no matter whatever combination of flags I try with D3DRS_DIFFUSEMATERIALSOURCE, DX never actually seems to use D3DMATERIAL9.Diffuse values of the material. Is this true? If so why is it there in the D3DMATERIAL9 structure?

Share this post

Link to post
Share on other sites
karwost is just trying to help. The fixed function pipeline is old technology for a computer built in the last 5-10 years. Even the iphone has recently added support for per-pixel programmable shaders.

Fixed function lighting and vertex / pixel shaders perform the same functions in the pipeline. They take a set of inputs, perform some maths on the inputs and output a final pixel color. You won't be missing out if you start off aiming for working with shaders as they do the same thing that the fixed function pipeline did.

As far as the answer to your question goes, you would have to post the source code in particular that is not working correctly. I believe when D3DRS_LIGHTING is enabled the lighting function expects a dynamic light to be used in the scene. I did some googling and came up with this:

TRUE to enable Direct3D lighting, or FALSE to disable it. The default value is TRUE. Only vertices that include a vertex normal are properly lit; vertices that do not contain a normal employ a dot product of 0 in all lighting calculations.

I don't know if that's particularly applicable to your situation or not. Direct3d can be a pain in the butt to learn, particularly if you're reading straight from the SDK reference. Things under the hood don't always work in the way you would think. You might want to search for a good tutorial or two on how to utilize different forms of lighting in the fixed function pipeline, or at least take a closer look at how the example applications do what you're aiming for.

Share this post

Link to post
Share on other sites
Premise: I agree with karwosts.
Original post by sastryvpr
I am a newbie and interested in getting my understanding right about these fundamental issues before i get on with more complicated
Maybe there's some subjectivity here but I think the shader-driven pipe is way easier conceptually: less enums to remember, less stages, more encapsulated state.
It's still not very good in D3D9 but it gets better.

I wish - really - I could had started from shaders back when I was a complete noob. FFP rapidly becomes a pain and most effects are borderline to being hacks on FFP. The shader-driven approach is a real treasure, I really cannot see why newcomers just trash this opportunity.

Anyway, I'm rather sure vertex colors will still pulled out, interpolated and mul'ed with lighting result. I'm not sure how this interacts with material color however, I have moved between APIs for a while and I could possibly screw it up completely.

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!