Sprite transparency threshold

Place to get help with not working mods / modding interface.
Post Reply
danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Sprite transparency threshold

Post 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.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Sprite transparency threshold

Post 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.

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Sprite transparency threshold

Post 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.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Sprite transparency threshold

Post 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" }

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Sprite transparency threshold

Post 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?

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Sprite transparency threshold

Post by posila »

In 0.17.15 cropping will check all channels are zero not just alpha.

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Sprite transparency threshold

Post by danielbrauer »

Fantastic, thanks!

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Sprite transparency threshold

Post 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?

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Sprite transparency threshold

Post 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.

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Sprite transparency threshold

Post 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?

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Sprite transparency threshold

Post 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?

danielbrauer
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu May 18, 2017 2:22 pm
Contact:

Re: Sprite transparency threshold

Post 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.

Post Reply

Return to “Modding help”