[posila] [1.1.72] recipe.crafting_machine_tint unexpected results with transparent black
Posted: Wed Nov 30, 2022 1:50 am
I have been fiddling with a crafting machine prototype that I wanted to display only one of two different kinds of working animation depending on the recipe, with a tinted layer involved. I realised that as long as I only want two variants, I can use the four channels of crafting_machine_tint and apply_recipe_tint with selective transparency - animation A sets primary and secondary to white and recipe-tinted respectively and sets tertiary and quaternary to transparent, and animation B does the reverse. (You could have four if none of them have to be tinted with a variable colour.)
I couldn't get it to work for ages and after much banging of head on desk figured out what the issue was. The wiki says that these are the default values of the channels if they are not specified:
{0,0,0,0} equates to (pre-multiplied) "transparent black". It shouldn't be visible at all. But the channels were appearing as if untinted or tinted by opaque white. This happens both if not specified at all (i.e. left to the default stated above) and if explicitly set to {0,0,0,0}.
I then tried other tints with various colours and transparencies. They all worked as expected - half transparent red, quarter transparent green etc. - as long as the value wasn't {0,0,0,0}.
Finally I figured out that this achieves the desired effect as a workaround:
If forced to guess I would say that a value of less than 1/255 works because the additions to the background colour channels are effectively rounded down to a value of 0 in the render.
You can't use any other transparent colour because the crafting machine tints are treated as pre-multiplied - so e.g. transparent red {1,0,0,0} gives odd-looking but correct results because the red channel should be pre-multiplied, e.g. 10% additional red should be {0.1,0,0,0.1} and 0% additional anything is {0,0,0,0}.
What I think should be happening (if full untinted opacity is the desired behaviour for not specifying a crafting machine tint channel) is that the default value should be {1,1,1,1} and explicitly setting {0,0,0,0} should be treated as fully transparent.
I couldn't get it to work for ages and after much banging of head on desk figured out what the issue was. The wiki says that these are the default values of the channels if they are not specified:
Code: Select all
crafting_machine_tint = { primary = {r=0,g=0,b=0,a=0}, secondary = {r=0,g=0,b=0,a=0}, tertiary = {r=0,g=0,b=0,a=0}, quaternary = {r=0,g=0,b=0,a=0}}
I then tried other tints with various colours and transparencies. They all worked as expected - half transparent red, quarter transparent green etc. - as long as the value wasn't {0,0,0,0}.
Finally I figured out that this achieves the desired effect as a workaround:
Code: Select all
local tint = {
primary = {r=0,g=0,b=0,a=0.000000000000001},
secondary = fluid.base_color,
tertiary = {r=0,g=0,b=0,a=0.000000000000001},
quaternary = {r=1,g=1,b=1,a=1},
}
You can't use any other transparent colour because the crafting machine tints are treated as pre-multiplied - so e.g. transparent red {1,0,0,0} gives odd-looking but correct results because the red channel should be pre-multiplied, e.g. 10% additional red should be {0.1,0,0,0.1} and 0% additional anything is {0,0,0,0}.
What I think should be happening (if full untinted opacity is the desired behaviour for not specifying a crafting machine tint channel) is that the default value should be {1,1,1,1} and explicitly setting {0,0,0,0} should be treated as fully transparent.