Mesh Lighting and Color

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

Recommended Posts

hey ive got more problem with my mesh but it shows up perfectly before i used just a buffer and a DrawPrimitive with lights and colored vertices but with the mesh vertices is only affected by the AMBIENT color no lighting no color only black with ambient light : ( the D3DXComputeNormals is not returning fail the mesh is created and filled by me using "D3DXCreateMeshFVF()" so plzz help me get color and lighting to my mesh... the FVF has D3DFVF_NORMAL hunter_ex

Share on other sites
The FVF should also have a D3DFVF_DIFFUSE parameter. With this you can chance the color of your object.

If you use a material, you can also have the desired effect with the following command:

Device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);

This command says that the Diffuse color of the set material will be used instead of the diffuse color of your vertex.

I hope this helps.

Share on other sites
the fvf also includes
#define FVF_CUSTOM ( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_NORMAL)

it showed colors and lighting when i drawed the primitives manually using a vertex buffer and drawprimitive call but now it reduses is it something that prevent colors and lighting in meshes ??

Share on other sites
When using lighting, you have to tell the lighting system that you've got colored vertices, and which parts of the lighting equation use vertex colors and which parts use material colors.

D3DRS_COLORVERTEX, true
D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1
D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL
D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL
D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL

if you have specular in your vertices, you'll want
D3DRS_SPECULARMATERIALSOURCE, D3DMCS_COLOR2

Note that you can actually use vertex diffuse be ambient or emissive, or have vertex specular, but use it for diffuse, etc. D3DFVF_DIFFUSE means D3DMCS_COLOR1 exists. D3DFVF_SPECULAR means D3DMCS_COLOR2 exists.

And, of course, you'll need to create lights with valid settings, Set them, and enable them, before you see your mesh's colors.

Sometimes you also want ambient to also use vertex diffuse, rather than just a plain solid color from the material.

Share on other sites
ive experimented with the states but i dont made the thing better
but when i took lighting OFF the colors were visible so i think 100 % is that my D3DXComputeNormals(...) parameter dont work

but it doesnt return error :S

LPD3DXBUFFER aBuffer = NULL;   D3DXCreateBuffer(3 * mesh[mesh_index]->GetNumFaces() * sizeof(DWORD),&aBuffer);      mesh[mesh_index]->GenerateAdjacency(1.0f,(DWORD*)aBuffer->GetBufferPointer());      mesh[mesh_index]->OptimizeInplace( D3DXMESHOPT_ATTRSORT |                                       D3DXMESHOPT_COMPACT |                                       D3DXMESHOPT_VERTEXCACHE,		                              (DWORD*)aBuffer->GetBufferPointer(),                                       NULL, NULL, NULL );      HRESULT res;   res = D3DXComputeNormals(mesh[mesh_index],(DWORD*)aBuffer->GetBufferPointer());   if (res != D3D_OK) MessageBox(0,"error","error",0);      if( aBuffer != NULL ) aBuffer->Release();

is it anything wrong with that code ??

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633732
• Total Posts
3013584
×