Jump to content


Photo

Avoiding the alpha glitch with surfaces


  • Please log in to reply
5 replies to this topic

#1 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2437 posts
  • Version:GM:Studio

Posted 22 February 2012 - 12:40 PM

I'm trying to make it possible to paint textures onto my model, and for this I want the borders between the textures to be smooth. However, the method I'm using results in an alpha glitch, where the transparent parts of the texture drawn on top of the other don't blend with what's already on the surface, but instead make the surface transparent.
Is there a way to avoid this? I've looked at blend modes, but none I've found let me keep the normal colour scheme as well as keeping the surface completely opaque.

Here are three different settings. The first one is close to how I want it to look, except the border between the textures is very jagged. The second one would work nicely if the surface didn't take over the alpha of whatever is drawn on it, and the third one is a futile attempt at switching blend modes
Posted Image

Are there any standard techniques for painting textures onto surfaces?
  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9259 posts
  • Version:Unknown

Posted 22 February 2012 - 02:20 PM

It's not a glitch. It's just blending.

If you want to make an area of a surface opaque without altering the colors, just set the blend mode to bm_add and draw in black. In your case, you'd do whatever overlaying you're doing now, and at the end of it all, set the blend mode to bm_add and draw a full-black circle in the area you want to keep.

-IMP
  • 2

#3 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2437 posts
  • Version:GM:Studio

Posted 22 February 2012 - 02:35 PM

It's not a glitch. It's just blending.

If you want to make an area of a surface opaque without altering the colors, just set the blend mode to bm_add and draw in black. In your case, you'd do whatever overlaying you're doing now, and at the end of it all, set the blend mode to bm_add and draw a full-black circle in the area you want to keep.

-IMP

Omg, thanks! I had no idea that was possible. Thanks so much :D

Needless to say - it worked

EDIT:
When I said glitch, I meant it resulted in my game being glitchy. I don't know what it's for though, and why it's different from normal drawing, but it's probably there for a reason

Edited by TheSnidr, 22 February 2012 - 02:42 PM.

  • 0

#4 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9259 posts
  • Version:Unknown

Posted 22 February 2012 - 04:36 PM


It's not a glitch. It's just blending.

If you want to make an area of a surface opaque without altering the colors, just set the blend mode to bm_add and draw in black. In your case, you'd do whatever overlaying you're doing now, and at the end of it all, set the blend mode to bm_add and draw a full-black circle in the area you want to keep.

-IMP

Omg, thanks! I had no idea that was possible. Thanks so much :D

Needless to say - it worked

EDIT:
When I said glitch, I meant it resulted in my game being glitchy. I don't know what it's for though, and why it's different from normal drawing, but it's probably there for a reason

It's only different from "normal" drawing because your window is opaque. The blending on a surface and the blending directly on the window are exactly the same, the only difference being that after the blending the screen contents are boosted to 100% opacity since that's all it can display. A surface doesn't have that limitation and can support full opacity from 0-1.

The normal blending mode, when drawing a color <Rs, Gs, Bs, As> onto a color <Rd, Gd, Bd, Ad>, combines them this way:

<NewR, NewG, NewB, NewA> = As * <Rs, Gs, Bs, As> + (1-As) * <Rd, Gd, Bd, Ad>

Notice that the source alpha affects the final alpha? That's what's happening here. On the screen, that doesn't matter, since the alpha is always pushed back to 1, but on a surface, whatever resulting alpha you get there stays in the pixel.

The bm_add mode does this:

<NewR, NewG, NewB, NewA> = <Rs, Gs, Bs, As> + <Rd, Gd, Bd, Ad>

So, since opaque black is <0,0,0,1>, you'll notice adding it won't affect the color but will push the alpha back up to 1 in the end.

-IMP
  • 2

#5 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2437 posts
  • Version:GM:Studio

Posted 22 February 2012 - 05:59 PM

Ah, I see. Thanks for the explanation :)

This is what the "game" (it's not really a game yet) looks like now, with smooth transitions:
http://img851.images...1024/pic1uo.jpg
Everything's temporary

EDIT:
Newer picture
http://img221.images.../utennavnth.jpg

Edited by TheSnidr, 22 February 2012 - 11:14 PM.

  • 0

#6 xot

xot

    media multimixer

  • Global Moderators
  • 4648 posts
  • Version:GM:Studio

Posted 22 February 2012 - 06:27 PM

You'll probably also find this topic useful, TheSnidr.

http://gmc.yoyogames...howtopic=474273
  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users