• Advertisement

Archived

This topic is now archived and is closed to further replies.

How to use materials on my mesh?

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

Hey I want to use materials on my mesh. Like the materials that you use with lighting to colour a surface. It just won''t work with meshes. I heard something about setting the right texture stages?

Share this post


Link to post
Share on other sites
Advertisement
I think it''s

D3DTSS_COLOROP, D3DTOP_MODULATE // combine 1 & 2
D3DTSS_COLORARG1, D3DTA_TEXTURE // 1 texture
D3DTSS_COLORARG2, D3DTA_DIFFUSE // 2 material

.lick

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
I think it''s

D3DTSS_COLOROP, D3DTOP_MODULATE // combine 1 & 2
D3DTSS_COLORARG1, D3DTA_TEXTURE // 1 texture
D3DTSS_COLORARG2, D3DTA_DIFFUSE // 2 material




I see.. somehow you need to add D3DTA_CURRENT to it I''m not very smart:

1) What does this do?
D3DTSS_COLOROP, D3DTOP_MODULATE // combine 1 & 2
D3DTSS_COLORARG1, D3DTA_TEXTURE // 1 texture
D3DTSS_COLORARG2, D3DTA_CURRENT // 2 light

2) This won''t work, will it?
0, D3DTSS_COLOROP, D3DTOP_MODULATE // combine 1 & 2
0, D3DTSS_COLORARG1, D3DTA_TEXTURE // 1 texture
0, D3DTSS_COLORARG2, D3DTA_CURRENT // 2 light
1, D3DTSS_COLOROP, D3DTOP_SELECTARG1
1, D3DTSS_COLORARG1, D3DTA_DIFFUSE // 3 diffuse

I really don''t have a clue..

.lick

Share this post


Link to post
Share on other sites
first this is what i use on my loaded mesh so my point light works on it. Sets the normals or something

DWORD fvf = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_SPECULAR | D3DFVF_TEX1 );
myMesh[index]->CloneMeshFVF( D3DXMESH_MANAGED, fvf, myDevice, &myMesh[index]);
D3DXComputeNormals( myMesh[index], 0);

and about "2) This won''t work, will it?"

it sent all my meshes white. Which had nothing to do with the materials i had on it.

Share this post


Link to post
Share on other sites
hmmm i just realised that the materials i was setting on my normal surfaces could only set a max of red blue or green.

like no 200,10,200

only 1,1,1

etc

i wanted to be able to set the diffuse colour.....

Share this post


Link to post
Share on other sites
then what are materials actually for?

I heard theres a way to set the diffuse colour somehow..... eg colour of my triangle

Share this post


Link to post
Share on other sites
You can specify the diffuse colour for each vertex by adding a colour variable e.g. D3DXCOLOR Colour(255,255,255,255) to your vertex structure and then adding D3DFVF_DIFFUSE to your FVF decleration.

Share this post


Link to post
Share on other sites
hmm i tried that, but nothing seems to happen, just the colour with a value larger than 0 shows the whole colour.

Share this post


Link to post
Share on other sites
actually i tried that on the microsoft sdk example and it did work...., could it b i have the light too close to the surface?

Share this post


Link to post
Share on other sites
ok, i think my point lights setup wrong.

When i turned the point light off, and just set ambient light on, the materials worked properly, like 0.5 for red worked, u could see the difference.

anyway could you have a look at this point light and see if there is any reason it won''t show anything but the max colour for the rgb


void PointLight(int index, float x, float y, float z, float range, float r , float g, float b, float a0=0, float a2=0)
{
D3DXVECTOR3 vecDir;
D3DLIGHT9 light;
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_POINT ;
light.Diffuse.r = r;
light.Diffuse.g = g;
light.Diffuse.b = b;
light.Attenuation0 =a0;
light.Attenuation2 =a2;
light.Position= D3DXVECTOR3( x, y, z );
light.Range = range;
myDevice->SetLight( 0, &light );
}



Share this post


Link to post
Share on other sites
I finally worked out how to set the material to my mesh.

The mesh already had a material set to it. So i just removed that line, and i could use my main material code to set that aswell.

Share this post


Link to post
Share on other sites

  • Advertisement