locked
Change the opacity of an object RRS feed

  • Question

  • Hello, I want to modify the opacity of an object with directx 9.0 and C++, but I don't know how, Does anybody know?

    Thanks. 

    Saturday, May 13, 2006 12:55 AM

Answers

  • I'm assuming that you're drawing a number of objects using either ID3DXMesh::DrawSubset(), or using IDirect3DDevice9::DrawIndexedPrimitive() (or similar) functions.

    To support transparent objects, your rendering loop should look like this:

    foreach object:
      foreach material/subset of the object
        if it is transparent, put it (and its position and other parameters) in a list of things to draw last
        else draw this material/subset of the object
    sort the list by distance to camera, furthest first
    enable framebuffer blend
    foreach thing in the list
      set the appropriate textures/states
      draw the thing
    disable framebuffer blend

    Once you have this basic method (drawing transparent things last), you can modify the degree of transparency of the object by modifying how much alpha the object outputs. You can do this by using a texture with an alpha channel, or you can do this in fixed function by changing the various material parameters (ambient and diffuse alpha values, typically), or you can do this in shaders by outputting an alpha value that's less than 1 for the OCOLOR value.

    Sunday, May 14, 2006 12:44 AM