Archived

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

Alload

My materials do not work

Recommended Posts

I don''t understand why my materials don''t work... This is the way I create one: D3DMATERIAL8 mtrl; ZeroMemory(&mtrl, sizeof(D3DMATERIAL8)); mtrl.Ambient.r = 0.5; mtrl.Ambient.g = 0.1; mtrl.Ambient.b = 0.1; mtrl.Diffuse.r = 0.6; mtrl.Diffuse.g = 0.4; mtrl.Diffuse.b = 0.3; The problem is that when I render the scene, the objects appear white, and they definitively haven''t this color... So if you could help to find what is wrong. Just in case, here is how I create my light: D3D8LIGHT light; ZeroMemory(&light, sizeof(D3DLIGHT8)); light.Type = D3DLIGHT_POINT; light.Diffuse.r = 1; light.Diffuse.g = 1; light.Diffuse.b = 1; light.Ambient.r = 1; light.Ambient.g = 1; light.Ambient.b = 1; light.Range = 100; light.Position = D3DXVECTOR3(0, 0, -40); g_lpD3DDevice->SetLight(0, &light); g_lpD3DDevice->LightEnable(0, true);

Share this post


Link to post
Share on other sites
1. Have you remembered to call SetMaterial() ?

2. Are your vertex normals correct ?

3. What are your texture stage states set to ? (they should be set to modulate diffuse with texture - or just select diffuse if you want untextured shading.)

4. Does your vertex format have a colour value as well as normals ?

5. Is the LIGHTING renderstate turned on ?

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
make sure that lighting is on ( sorry if it is I''m not trying to be condescending or anything... )

also make sure that the texturestagestate is setup to use the stuff genereated by lighting etc.

  
//D3DTSS_COLOROP specifies how the colour of each pixel will be determined

//In this case it''s set to D3DTOP_MODULATE which means the colour is determined

//by combining COLORARG1 & COLORARG2.

g_d3d_device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
//D3DTSS_COLORARG1 is set to D3DTA_TEXTURE which means that colour1 is

//entirely taken from the texture and nothing else. D3DTSS_COLORARG2

//is set to D3DTA_CURRENT which will be our vertex colour if lighting

//is turned off, or the result of the lighting if it is on.

g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_CURRENT);


(btw this code comes from drunkenhyena - thanks Ken)




Share this post


Link to post
Share on other sites
1. I called SetMaterial().

2. My vertex normals are good.

3. I don''t use texture.

4. My vertex have color values.

5. I turned the lighting on.

I tried some changes and I found that the values between ]0; 1] for a color appear to be the same when my scene is rendered. That could explain why my scene is all white.

Share this post


Link to post
Share on other sites
"4. My vertex have color values."

Bingo!

With the fixed function pipeline, the D3D lighting engine can''t be mixed with your own lighting (vertex colours). If your hardware supports it, you can use the MATERIALSOURCE renderstates to make the emissive part of the material come from the vertex colour. Alternatively you could put the vertex colouring in the specular. A vertex shader would be the ideal way though.



--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
I fixed the problem changing D3D_CREATE_SOFTWARE_VERTEXPROCESSING by D3D_CREATE_HARDWARE_VERTEXPROCESSING in the CreateDevice() function.

The last problem is, I don''t understand the difference between this two flags, and why in one case the materials do not work.

Share this post


Link to post
Share on other sites
quote:
Original post by Alload
I fixed the problem changing D3D_CREATE_SOFTWARE_VERTEXPROCESSING by D3D_CREATE_HARDWARE_VERTEXPROCESSING in the CreateDevice() function.

The last problem is, I don''t understand the difference between this two flags, and why in one case the materials do not work.


BTW, I ran into this problem too. I used the code from "Zen" and it doesn''t work till I run into this post which saves me endless hours of groaning in endless frustrations...

D3D_CREATE_SOFTWARE_VERTEXPROCESSING means that D3D will use software to render the triangle. D3D_CREATE_HARDWARE_VERTEXPROCESSING means that the hardware will take care of the rendering (this is in layman''s term).

Yet another mistake in Zen...(nope, The Zen of Direct3D Programming doesn''t mention this at all...)

Share this post


Link to post
Share on other sites