question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black outline in Sprites using transparent PNGs as Textures

See original GitHub issue

When using a transparent PNG as a Texture of a Sprite, when the Sprite scales in size it seems to appear a weird black outline like the above:

Sprite (See the black pixels around the triangle)

Any clue on how to avoid this?

I obviously could use very big PNGs, but that’s not an option as I am using lots of them and the loading time wouldn’t be acceptable.

So any recommendation will be very appreciated! 😃

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mrdoobcommented, Apr 4, 2012

Nope, I was just trying to explain more in details for the future reference of what’s actually going on (distinction between different behaviors for different filters is IMHO important).

Indeed!

But I am generating thousands of this images dynamically in canvas (they all look different). And I can’t manage to think of an easy (and not performance intensive) solution to “expand the colors” in code.

I see. Well, I’m of course missing context on what you’re actually doing, but you can try this:

For every image you draw the shapes a bit bigger. And then you draw the shapes again in the normal size in a temporal canvas. Then you do this:

// this allows you to only affect the alpha channel on the next operations
context.globalCompositeOperation = "destination-in";
context.drawImage( temp_canvas, 0, 0 );

That way you’ll be adding extra color padding to your color channels while the alpha channel will have the size you need.

I’m not sure it works for what you’re trying to do, but it’s a technique that can be pretty handy when used well 😃

1reaction
mrdoobcommented, Apr 4, 2012

After playing with your example a bit I think difference comes because one image has baked black transparent background while the other one has baked white transparent background.

I don’t think it’s that. The image seems fine:

http://twitpic.com/95amq5/full

I have the feeling it has something to do with premultiplication. Or maybe the blend operation…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Black boarder on transparent sprites
Hi guys,. I just created a new project and added my sprite, why am I getting these black boarders, I tried to change...
Read more >
Why do my sprites have a dark shadow/line/frame ...
The Problem is that they all are surrounded with thin dark lines. The screen shot below shows two rectangles with a png image...
Read more >
a transparent background and bring it into Blender [2.82]
In this quick tip tutorial, we will be learning how to prepare an image with transparency in GIMP and then import an image...
Read more >
three.js transparent png texture strange border webgl
The pngs get strange borders at the area between visible and transparent. I allready tried to play around with alphatest value but then...
Read more >
Photoshop Tip: Get rid of ghost outlines around sprites
The color of any onscreen pixel is actually a blend of neighboring pixels on a texture. The issue arises with opaque pixels that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found