Drawing textures with transparent and semi-transparent texels?

Hello,
     I have a texture and I'll draw it in 2D view, I try to make some texels of it fully transparent and the other is some transparent. Unfortunately I don't know how to do that.
     I started with DirectX plugin for Photoshop I designed the texture as fully transparent at some texels and semi transparent as others. Then I save it as DDS format I choosed format of A8R8G8B8. I load it with color key of 0xffffffff so the white color of the texture won't appear. I enabled the alpha blending and make:
 device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
 device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
 device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
     But until now I don't know any way to make it semi-transparent. Or control the alpha value of the texture through Photoshop
Thanks,
Mustafa ELBanna


Answer this question

Drawing textures with transparent and semi-transparent texels?

  • Phil Price

    Hello,
           Really thanks, this really solves the problem.
           Another thing I want to say that I use for the image format DFMT_UNKNOWN and it also works like A8R8G8B8 for an example.
    Thankss,
    Mustafa ELBanna


  • dpolyakov

    Any idea how to do this in Photoshop I am not a graphic person and I am trying to explain this process to my graphic designer.

    More specifically, how to "save out the blue channel" to a separate file.


  • zagolin

    You'll have to refer to the documentation for PhotoShop with regards to creating the texture - the commands/controls/processes can vary from version to version and program to program.

    Myself, I use Paint Shop Pro 7, and I author my image as you would normally. Save this as texture.bmp for example. I then create a copy of this and, as greyscale, draw the transparencies such that black is transparent and white is "solid". All shades of grey are different degrees of semi-transparent. I then, using PSP, save out only the blue channel. Save this file as texture_a.bmp - the _a part being important.

    With those two files you can use the DXTex tool that comes with the SDK - load in the texture.bmp file and it should automagically pick up the texture_a.bmp file as the alpha channel. You can then save it back out as a regular D3DFMT_A8R8G8B8 DDS/BMP file.

    You should then have a correctly authored/formed texture with varying per-pixel transparency.

    The next trick is to make sure it's loaded into your application with the alpha channel - D3DXCreateTextureFromFile() doesn't allow you to specify the pixel format, and in my experience it tends to "lose" the alpha data... Instead you need to use D3DXCreateTextureFromFileEx() and specify a texture format with an "A" channel (A8R8G8B8, A1R5G5B5 or A4R4G4B4 usually).

    I've tripped myself up a few times by forgetting to load the texture in with an alpha channel Tongue Tied

    After that, the three render states you've quoted should do the trick - just render as usual!

    hth
    Jack



  • Drawing textures with transparent and semi-transparent texels?