Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

DirectX Materials and Relationship to FFP

This topic is 4796 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, How are the materials in DirectX related to the fixed function pipeline? In the texture stage states, I don't see any options to modulate for example the ambient property of the material. How is the ambient light from the material added? Is this in the FFP after the texture stages? What if you use a pixel shader, do the materials then do nothing? A little confused. Thanks Ray

Share this post


Link to post
Share on other sites
Advertisement
Hi there Raeldor, How are you doing?

The Problem
How does the Material relate to the FFP (Fixed function pipeline)

The Solution
The Material is directly related to the FFP in the sense that when you use shaders, your D3DMATERIAL9 Structure is kind of void when you use the programmable pipeline known as shaders.
So when you use shaders, you give your primitive/mesh the property you want it to reflect when lights hits it's surface.
You can try it for yourself and see the effects. Create a simple diffuse shader with a light and try and set the material. What you can do is still use the material structure but send it to the shader as a parameter and use it's contents, think of your d3dmaterial9 structure as your material manager in a simple sense.

I hope this helps a bit. If it's a little out I do apologize.

Share this post


Link to post
Share on other sites
Quote:
Original post by Armadon
Hi there Raeldor, How are you doing?

The Problem
How does the Material relate to the FFP (Fixed function pipeline)

The Solution
The Material is directly related to the FFP in the sense that when you use shaders, your D3DMATERIAL9 Structure is kind of void when you use the programmable pipeline known as shaders.
So when you use shaders, you give your primitive/mesh the property you want it to reflect when lights hits it's surface.
You can try it for yourself and see the effects. Create a simple diffuse shader with a light and try and set the material. What you can do is still use the material structure but send it to the shader as a parameter and use it's contents, think of your d3dmaterial9 structure as your material manager in a simple sense.

I hope this helps a bit. If it's a little out I do apologize.


Thanks for the reply, I think I am beginning to understand a little more now. Are these light calculations carried out before or after the calculations that you set in the texture stages? Also, you set the material and the global ambient light. You seem to need both in order for it to work, does this mean that the final ambient light calculation is global * material?

Thanks!

Share this post


Link to post
Share on other sites
D3DLIGHT9 and D3DMATERIAL9 are used in vertex processing with the fixed pipe.

D3DRS_COLORVERTEX, D3DRS_DIFFUSEMATERIALSOURCE, D3DRS_AMBIENTMATERIALSOURCE, etc. control where the the lighting system finds the various material colors, either from the material structure or from vertex data.

D3DRS_SPECULARENABLE, D3DRS_LOCALVIEWER affect specular calcuations in the fixed pipeline.

Once the fixed pipeline has calculated light, the diffuse, ambient, and emissive light is output from the fixed vertex pipe as COLOR0, and specular is output as COLOR1.

If you use the TextureStageStates, D3DTA_DIFFUSE is color0, and D3DTA_SPECULAR is color1. If you use a pixel shader, an input in your shader may be "diffuse : COLOR0". Note that specular is automagically added after the texture stages / pixel shader, and you don't need to add it yourself in your stages/shader.

If you use a custom vertex shader and output COLOR1 while D3DRS_SPECULARENABLE is false, the results vary by card. On all cards, the automatic specular add is disabled. Trying to use D3DTA_SPECULAR in the texture stages varys by card. Some cards will have garbage values in COLOR1. Some cards will use the color from one of the vertices, but not interpolate. Some cards will interpolate the colors. The fact that D3DRS_SPECULARENABLE controls multiple aspects of the pipeline is annoying, as there is no way to specify you'd like the colors interpolated, but not automatically added.

edit:

Diffuse is the sum of (light contribution)*(light diffuse color)*(material or vertex color (diffusematerialsource)) for each light. Light contribution depends on normals, light types/position/direction, attenuation, etc.

Specular is (light contribution)*(light specular color)*(material or vertex color (specularmaterialsource)), summed for each light. This depends on normals, localviewer, specular power, light types/position/direction, etc.

Emissive is material or vertex color (emissivematerialsource)

Lights somehow affect ambient as well (note that D3DLIGHT9 has ambient components). I've always just set the ambient to 0 in lights. Ignoring the lights, ambient is D3DRS_AMBIENT * (material or vertex color (ambientmaterialsource)).

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!