Texture on Texture? DX9

This is a discussion on Texture on Texture? DX9 within the Game Programming forums, part of the General Programming Boards category; Im not sure what the method is called, multitexturing, texture on texture.. basically, i want to put image #1 on ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    Texture on Texture? DX9

    Im not sure what the method is called, multitexturing, texture on texture..
    basically, i want to put image #1 on top of image #2 (making only the black part transparent in image #1).

    this is what im using at the moment

    Code:
    g_Device->SetTexture(0, TextureGrass);
    g_Device->SetTexture(1, TextureBlood);
    
    g_Device->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
    g_Device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);
    g_Device->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
    g_Device->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
    the result is in image #3
    as you can see, the black is transparent, but it blends the other colors with the grass.
    cool effect, but not what im going for.

    Thanks in advance.
    Attached Images Attached Images    

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I would just use color-key transparency for the black color in your "1.jpg".
    "...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
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    When i set the colorkey, it just changes the color to black, i tried changing it to green in the image and it would load it as black, not transparent.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    ok, so i fixed the black part (it was showing the color i cleared to), i changed my clear color to a lightblue, and as you can see in the image, instead of showing the texture under it, it just goes through the quad.

    heres the code i use

    Code:
    g_Device->SetTexture(0, GrassTexture);
    g_Device->SetTexture(1, BloodTexture);
    
    g_Device->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
    g_Device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    g_Device->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    
    g_Device->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    g_Device->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    g_Device->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
    
    g_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    g_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    
    g_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
    
    g_Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, CurrentTile[x][z]);
    
    g_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
    and heres the image of the result:
    Attached Images Attached Images  

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    You are forgetting about one important channel in order to do this in Direct3D. There is no color-key support in D3D but you can achieve the same effect with alpha blending.

    Set the texture stage alpha blend states and it will work.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    i know how its done with 1 texture, but ive never tried it with 2 textures, i did set the texture stage alpha blend states though:

    Code:
    g_Device->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    g_Device->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    g_Device->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
    do i need to set the alpha blend states for the 1st texture as well?

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    ive been trying for the past 2 days, using every possible combination i could think of for alpha ops and color ops.. but each time i get half of what i want done (e.g. sometimes the ENTIRE texture is transparent, sometimes the wrong half is)..

    ill summarize what im trying to do:

    i want to know if you can make a certain color in a texture transparent (so you can see through to the texture under it and not through the actual quad). im trying to render a quad with 2 or 3 textures and i want to overlap these textures, but leave some parts transparent to show the texture below it..

    again, any help is appreciated.

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 01:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  3. Replies: 4
    Last Post: 02-27-2008, 02:10 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. Alpha-Blending Texture - DX9
    By X PaYnE X in forum Game Programming
    Replies: 5
    Last Post: 11-17-2004, 09:02 AM

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