+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Ultimate Subscriber
    Join Date
    Oct 2009
    Posts
    31

    Setting materials to objects

    Now in DirectX you can set textures, and those allow for the use textures created in 2D art programs. But you can also set materials, here ill explain a bit:

    A material serves the same purpose as a texture, but is much more versatile.
    For, you can edit a material's parameters actively while the application is running.

    Now alot of people like to just put al their params in DrawIndexedPrimitive, but i like to write functions to save us space, and make it clean, nd easy to handle.

    i.e.
    Code:
    void CreateMat(IDirect3DDevice9 *Device, int Name, float Diffuse_Red, float Diffuse_Green, float Diffuse_Blue, float Diffuse_Alpha, float Ambient_Red, float Ambient_Green, float Ambient_Blue, float Ambient_Alpha)
    {
        D3DMATERIAL9 Name;//declare your mat
        ZeroMemory( &Name, sizeof(D3DMATERIAL9) );
        Name.Diffuse.r     = Diffuse_Red/255;//set the diffuse red color
        Name.Diffuse.g     = Diffuse_Green/255;//set the diffuse green color
        Name.Diffuse.b     = Diffuse_Blue/255;//set the diffuse blue color
        Name.Diffuse.a     = Diffuse_Alpha/255;//set the diffuse alpha value
        Name.Ambient.r     =  Ambient_Red/255;//set the ambient red color
        Name.Ambient.g     =  Ambient_Green/255;//set the ambient green color
        Name.Ambient.b     =  Ambient_Blue/255;//set the ambient blue color
        Name.Ambient.a     =  Ambient_Alpha/255;//set the ambient alpha value
        Device->SetMaterial( &Name );
    }
    That is the function that im currently using for my materials.

    let me explain how this works a bit, a diffuse color is the "TRUE" color of the material, an ambient color is the colr that the material is where the light hits it..

    i.e.

    The gray is the diffuse color, and the white is the ambient color. the black on this example does not pertain to the material, that is controlled by lighting (ill write another topic on that later)

    Again, hope this helped.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts