XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Texture transparency

Last post 03/11/2009 23:22 by Shawn Hargreaves. 7 replies.
  • 31/10/2009 15:18

    Texture transparency


    Hello fellow devs.

    First of all I would like to say this is a great community and would like to thank all the mods for their effort
    into posting sticky's, FAQs (which I've read) and so on.

    Here's my actual issue:

    - I have a simple background with green grass representing the 'world' and another texture with a little character (player) in a white background.
      This small character is supposed to walk around in my 'world'.
      Quite a simple task, however I cannot seem to make his white background alpha-blend (transparent) with the green grass behind him.
      I get an ugly character inside his white square moving around on top of the green grass.
     
      My world's extension is .png and my char's extension is .jpg.
      I've tried using   sprites.Begin(SpriteBlendMode.AlphaBlend);  in the Draw() method but apparently that doesn't work for me.


    How do I make the character walk around the world and blend in with it without that ugly white square behind him?


    Regards,
    LeBadman


  • 31/10/2009 15:24 In reply to

    Re: Texture transparency

    Right click your character's jpg file in Game Studio to bring up the Properties window, and there expand the Content Processor property, then change the Color Key Color value to white (255, 255, 255, 255). That's all you need to do. But keep in mind any white in your image will become transparent.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 31/10/2009 16:55 In reply to

    Re: Texture transparency

    I *highly* recommend creating transparent artwork in TGA files. It's the only file format I've found that works well with all the paint programs and the XNA pipeline at the same time. (PNG is a good second, but Photoshop has some peculiarities with PNG)
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 03/11/2009 6:53 In reply to

    Re: Texture transparency

    jwatte:
    Photoshop has some peculiarities with PNG
    Such as? I've never encountered trouble with PNGs in Photoshop...
  • 03/11/2009 17:05 In reply to

    Re: Texture transparency

    BShields:
    jwatte:
    Photoshop has some peculiarities with PNG
    Such as? I've never encountered trouble with PNGs in Photoshop...


    I've seen it discard the RGB values from areas with zero alpha (changing them to 0,0,0,0), which isn't so great if you are using alpha for anything other than premultiplied blending.
    XNA Framework Developer - blog - homepage
  • 03/11/2009 19:28 In reply to

    Re: Texture transparency

    Photoshop treats PNG transparency as "transparency," not "alpha." As Shawn says, this doesn't give you the control you want. You want alpha to live in an explicit alpha layer, rather than the "invisible" transparency layer of your image.

    And actually, I think it sets "transparent" to white -- it's the TextureProcessor in XNA that forces all transparent bits to black when choosing DXT1 format, even if there are fully transparent pixels with color information. It's been my assertion for a long time that it should choose DXT5 in these cases. Hint, hint :-)

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 03/11/2009 21:15 In reply to

    Re: Texture transparency

    Shawn Hargreaves:
    BShields:
    jwatte:
    Photoshop has some peculiarities with PNG
    Such as? I've never encountered trouble with PNGs in Photoshop...


    I've seen it discard the RGB values from areas with zero alpha (changing them to 0,0,0,0), which isn't so great if you are using alpha for anything other than premultiplied blending.
    Ah, okay, that does make some sense. I've never had reason to try and get RGB values out of a transparent pixel, though I can imagine where it might be wanted.
  • 03/11/2009 23:22 In reply to

    Re: Texture transparency

    BShields:
    I've never had reason to try and get RGB values out of a transparent pixel, though I can imagine where it might be wanted.


    Even if you're just doing regular (not premultiplied) alpha blending, the RGB of transparent pixels can be important to avoid ugly fringes around the edges of alpha cutouts as a result of texture filtering.
    XNA Framework Developer - blog - homepage
Page 1 of 1 (8 items) Previous Next