Page 1 of 1

Sprite transparency threshold

Posted: Fri Mar 15, 2019 8:41 am
by danielbrauer
In this FFF, it's mentioned that:
posila wrote:particles below 2% opacity don't really seem to add anything to the final picture, so we can safely not draw those to get little extra boost.
I seem to have run afoul of this threshold in one of my effects textures, since it has non-zero colour values in zero-alpha areas of the image. What would normally be drawn additively is instead optimised away to be entirely transparent.

Is there any way to disable this optimisation for a specific sprite or animation? At the moment I'm just clamping the alpha value to 0.025 so it doesn't get discarded.

Re: Sprite transparency threshold

Posted: Fri Mar 15, 2019 8:53 am
by posila
I don't think that is the problem. The optimization is per trivial-smoke particle, not per pixel. Smoke has defined some fade out animation in the prototype, and if result of that animation is 2% or less, entire particle is not drawn.

Images are premultiplied on loading, so that will destroy your non-zero color values. You can set premul_alpha = false, on sprite definitions that you want to preserve as is.

Re: Sprite transparency threshold

Posted: Fri Mar 15, 2019 9:17 am
by danielbrauer
Oh hey! :)

premul_alpha is what I found first, and turned it off because I know what my alpha and colour values should be. The result is mostly what I'd expect, but a lot of pixels missing. I'm quite certain that it's a result of some sort of thresholding because when I increase then minimum alpha from zero, then all the pixels render. Might there be something in the shader? I'm not using any tint at the moment.

Re: Sprite transparency threshold

Posted: Fri Mar 15, 2019 10:25 am
by posila
Can you share a mod that would demonstrate the issue?

Also ... the pixels might have been cropped out as cropping checks only alpha pixels, try to add to the sprite definitions following

Code: Select all

flags = { "no-crop" }

Re: Sprite transparency threshold

Posted: Fri Mar 15, 2019 10:51 am
by danielbrauer
Thanks, turning off cropping fixed the issue. I guess my other solution is better if I'm trying to keep overdraw down though, right?

Re: Sprite transparency threshold

Posted: Sun Mar 17, 2019 7:37 pm
by posila
In 0.17.15 cropping will check all channels are zero not just alpha.

Re: Sprite transparency threshold

Posted: Sun Mar 17, 2019 9:18 pm
by danielbrauer
Fantastic, thanks!

Re: Sprite transparency threshold

Posted: Mon Mar 18, 2019 8:23 am
by darkfrei
posila wrote:
Sun Mar 17, 2019 7:37 pm
In 0.17.15 cropping will check all channels are zero not just alpha.
It means that we need black alpha borders, not just zero alpha?

Re: Sprite transparency threshold

Posted: Mon Mar 18, 2019 8:27 am
by posila
darkfrei wrote:
Mon Mar 18, 2019 8:23 am
It means that we need black alpha borders, not just zero alpha?
If you use premul_alpha = false, then yes. Otherwise cropping will have the same result as before.

Re: Sprite transparency threshold

Posted: Wed Mar 20, 2019 5:40 pm
by danielbrauer
posila wrote:
Sun Mar 17, 2019 7:37 pm
In 0.17.15 cropping will check all channels are zero not just alpha.
I didn't see any mention of this in the release notes, and in my tests I'm still seeing pixels with non-zero colour being cropped. Did the change perhaps get missed?

Re: Sprite transparency threshold

Posted: Fri Mar 29, 2019 1:13 pm
by posila
The change did is in 0.17.15. I don't understand why "no-crop" would work, while not working with cropping enabled since 0.17.15. Can you share a mod that would demonstrate the issue?

Re: Sprite transparency threshold

Posted: Sat Mar 30, 2019 1:28 am
by danielbrauer
Here is a mod which shows two test sprites. The source images are identical, but one has no-crop.
CropTest_0.0.0.zip
(81.95 KiB) Downloaded 104 times
This is what it looks like in 0.17.14:

Image

Oddly enough, in 0.17.22 both sprites are missing the zero alpha section.