Alpha blending w/o color loss

This is a discussion on Alpha blending w/o color loss within the Game Programming forums, part of the General Programming Boards category; Finally got my 2D system working inside of Direct3D. I'm ready to implement my heads up display for my space ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597

    Alpha blending w/o color loss

    Finally got my 2D system working inside of Direct3D. I'm ready to implement my heads up display for my space ships, but I have one problem.

    It seems that my alpha blending technique is causing the original color of the bitmap to be altered somewhat. I want the image color to stay intact, yet still be blended into the background.

    Here is what I'm using:

    1. Create image.
    2. Grey scale and use as alpha texture.
    3. Use DirectX texture tool to load image.
    4. Convert image to A8R8G8B8 format.
    5. Load alpha texture onto surface.
    6. Save as DDS file.
    7. Load into game engine.

    Here are the device states:

    Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA );
    Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALP HA);

    Here is the result. My blue targeting cursor has turned a sky blue color. I know why its that color, but I'm not sure how to prevent it from changing colors.

    Mr. Wizard???

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Are you after Alpha Transparency? Do you have your alpha texture stage set to:

    Code:
    SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
    Your SetRenderStates are correct.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Yes I get the same thing.
    Let me enlarge the TLVertex object and show you.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Don't worry about the frame rates. I wondered why they were not faster myself until I remembered that I have it vsynced instead of D3DPRESENT_IMMEDIATE. Without vsync this thing tears really bad so I had to enable it until I begin to tax D3D somewhat.

    Too many FPS. It's a good problem.

  5. #5
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    Seems like your alpha might be backwards, the way I do alpha blending in GL is like so:
    GL_DST_ALPHA,GL_ONE_MINUS_SRC_ALPHA

    with the destination alpha being normal, and the source alpha inverted to make it fade to black, instead of what yours seems to be doing and fading to white.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    I fixed it.

    I was using a specular component as well and this caused D3D to change the color of my texels. I'm not sure why since lighting is turned off for the heads up display textures. However, I've got it working now.

    Code:
    struct HUDTLVertex
    {
    D3DXVECTOR3 Pos;
    D3DCOLOR Diffuse;
    float u,v;
    static const DWORD FVF;
    };
     
    const DWORD HUDTLVertex::FVF=(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
    This works very well.

    I've looked into ID3DXSprite and it is not that complicated but I haven't used any of it yet. Not sure if I will or not.

    Thanks all for the help.

    Incidentally, D3DBLEND_INVSRCALPHA is 1-SrcAlpha.

  7. #7
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    Incidentally, D3DBLEND_INVSRCALPHA is 1-SrcAlpha.
    oh, duh, I misread your original code and thought it was placed in there backwards for some reason

    The engine's looking really awesome so far btw.

  8. #8
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Are you still working on lighting? I do think that this is some excellent work but for some reason that atmospere seems to create too much of a milkyness over the planet. It would loog soooooo good if the planets color was more defined.
    What is C++?

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    I'm working on doing some bump mapping and texture blending and/or detail texturing. However nothing is working.

    Device->SetTexture(0,Texture);
    Device->SetTexture(1,DetailTexture);

    Device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEX TURE);
    Device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELE CTARG1);

    Device->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_CUR RENT);
    Device->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_TEX TURE);
    Device->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_ADDS MOOTH);

    Device->SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_DISA BLE);

    Planet.GetMesh()->DrawSubset(0);


    It is as if texture stage 1 has no texture in it at all. Perhaps my card does not support multiple texture blending in one pass. This should blend texture 1 with texture 2 using the ADDSMOOTH operation. Again, its not working. Guess I'll check the device caps. I'd hate to have to re-render the whole planet just to get detail mapping done.

    This is a nasty way to detail map my planets. I'm not happy about the re-render but so far its all I can do till I get my pixel and vertex shaders up and running.
    Last edited by VirtualAce; 10-23-2004 at 03:33 AM.

  10. #10
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Vicious
    Are you still working on lighting? I do think that this is some excellent work but for some reason that atmospere seems to create too much of a milkyness over the planet. It would loog soooooo good if the planets color was more defined.
    Yes, the earths perimeter is 40,000 kilometers. However, the space begins at mere 100 km from the surface.

    Here's a nice picture
    http://grin.hq.nasa.gov/IMAGES/SMALL...000-001437.jpg
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Here is another shot with some different color settings.

    There are so many variations, I'm lost as to which one's to use.

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Here is a blue atmosphere surrounding a detail mapped earth.

    It almost looks like bump mapping but its not. It's fake bump mapping.

  13. #13
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,597
    Well my texture looks like that pic with no atmosphere and nothing extra.

  14. #14
    ---
    Join Date
    May 2004
    Posts
    1,379
    the above pic looks best imo

  15. #15
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Bubba
    Well my texture looks like that pic with no atmosphere and nothing extra.
    Of those you've shown here, I like that picture best.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Direct3D10 Sprites Alpha Blending
    By DarkMasterBosel in forum Game Programming
    Replies: 0
    Last Post: 01-17-2009, 07:17 AM
  2. Replies: 23
    Last Post: 07-09-2007, 05:49 AM
  3. 2 questions in DirectX
    By X PaYnE X in forum Game Programming
    Replies: 4
    Last Post: 12-02-2004, 09:38 AM
  4. Alpha blending rocks
    By VirtualAce in forum Game Programming
    Replies: 12
    Last Post: 04-06-2004, 09:08 PM
  5. Alpha blending
    By SMurf in forum Game Programming
    Replies: 3
    Last Post: 08-29-2003, 07:50 PM

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