Sign in to follow this  
Hunter_Ex

Mesh Lighting and Color

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 ??

Share this post


Link to post
Share on other sites

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