DirectX 9 materials acting weird

This is a discussion on DirectX 9 materials acting weird within the Game Programming forums, part of the General Programming Boards category; When I apply a material that has a specular values, my cube (wich is made from multi colored vertices) turns ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    DirectX 9 materials acting weird

    When I apply a material that has a specular values, my cube (wich is made from multi colored vertices) turns pure yellow/green.

    Here is my light:

    Code:
    	eng.SetLighting(true);
    	eng.GetDevice()->SetRenderState(D3DRS_SPECULARENABLE, true);
    	eng.GetDevice()->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
    	
    	
        LIGHT light;
        ZeroMemory(&light, sizeof(light));
        light.Type = D3DLIGHT_POINT;
        light.Position.x = 0;
        light.Position.y = 5;
        light.Position.z = 0;
        light.Diffuse.r = 1;
        light.Diffuse.g = 1;
        light.Diffuse.b = 1;
        light.Diffuse.a = 1;
        light.Attenuation0 = 1;
        light.Range = 20;
        
        light.Specular.r = 1.0f;
    	light.Specular.g = 1.0f;
    	light.Specular.b = 1.0f;
    	light.Specular.a = 1.0f;
        
        eng.LightAdd(0, light);
        eng.LightEnable(0, true);
    eng is my engine, and there are NO errors, it runs just fine.

    Here is my material:

    Code:
    	MATERIAL mat;
    	ZeroMemory(&mat, sizeof(mat));
    	
    	mat.Specular.r = 0.5f;
    	mat.Specular.g = 0.5f;
    	mat.Specular.b = 0.5f;
    	mat.Specular.a = 0.5f;
    	mat.Power = 20.0f;
    	
    	buf.SetMaterial(mat);
    Where buf is my vertex buffer, and yes the material is loaded and applied, I already tested that.

    The problem is, if I take away the buf.SetMaterial(...) line of code it works fine but without the specular effects. Any idea why this is happening?

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I have now found out that this single line of code:

    Code:
    light.Specular.g = 1.0f;
    in my light is making everything Green/Yellow (It looks yellow to me).

    I tried october and december releases of directx 9 to make sure it wasn't a bug and it happened with both versions.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Sorry for triple post but I got pics now. The first pic is what it looks like with the line of code and the second is what it looks like without that line of code.

    EDIT: I just figured out that the shinyness that you see in the pic is only on the blue sides. If I change those sides to anouther color that shinyness won't happen and it will be green.
    ..
    Attached Images Attached Images   
    Last edited by Rune Hunter; 12-25-2005 at 08:38 PM.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    The power is too high.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Ok I did a quick test, I turned power to 0 (I even tried 0.0f) and it did the same exact thing.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    For your material make sure you specify the other properties. Diffuse, Ambient, and Emissive all play a role in the final equation.

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I set them all. I tried all to 1 than all to 0 than difuse at 1 the rest at 0. (non of these tests count changing the specular value).

    I'm now wondering if anyone can show me there code to do this. Both light and material.

  8. #8
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I feel stupid now, it was my engines fault! I accidently incorectly used pointers. And I am good with pointers too, they never trubled me from the start so why now!?

    Anyways it is all fixed now, thanks for your help. Although it makes me wonder what it really was doing to get those weird effects.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Floating Values acting weird.
    By torqu3e in forum C Programming
    Replies: 9
    Last Post: 12-19-2006, 11:12 AM
  2. atof() acting weird?
    By Mellowz in forum C Programming
    Replies: 4
    Last Post: 07-09-2006, 04:48 AM
  3. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  4. char[] acting weird
    By Leeman_s in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2003, 07:45 PM
  5. n00b needs help with api graphics acting very weird
    By CheeseWeaver in forum Windows Programming
    Replies: 2
    Last Post: 03-18-2003, 03:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21