Material Function, BitMask not working?

Hi all,

I am having problems using the BitMask material function - or even recreating what it does;

Let say I am using the Red Channel of a texture, as a mask, however I only want to use the mask where the Red Value = 0, consider the below scenario:

As you can see, by previewing the BitMask node, it appears to be working as intended: The texture provided is a series of vertical lines with increasing Red Value, from 0, to eventually 255 (brightest lines near the centre of the texture). The BitMask function is correctly returning a value of 1 for where the red = 0 and a value of 0 for everything else.

The problem occurs when I increase the bit from 0. The node wants to accept any number between 0 to 255, I would of thought passing a value of 16 would return the appropriate mask of 1 where red = 16, and 0 everywhere else. However it does not.

Investigating this further - I recreated my own bit mask function (see the original function below) its very simply and works via the IF node:

I believe the issue is due to the circled parameter regarding the equals threshold. Something about the Math seems to mean that 16/255 is slightly off whatever that is in the red value is of the actual texture (which appears to be between 0 - 1). By fiddling with the equals threshold value, I can almost get my desired result - but the resolution is poor (can not distinguish between a red value smaller than 32) It is also no predictable, eg asking for mask value 16 will give me the red values >128… asking for mask value 15 would give me red values ~50-80… weird stuff like that.

Could this be something to do with how the colours are stored? i.e. maybe the 0-1 values are the stored coloured squared values, whereas the 0-255 isn’t squared?

Has anyone tried doing this before? I feel like I missing something simple or committing some trick for new players (Somewhat of a Unreal4 novice)

Any help appreciated! Cheers.

So turns out this was related to the sRGB flag set in the texture itself… as the texture sample I was using was actually a parameter - it took me a while to realise that whatever you set the ‘default’ texture to be, it will try use those settings, and not those of the texture you created.

Thus the fix in this case was to ensure my texture parametre default value was a texture that had the sRGB flag turned off in its texture properties (thus matching the texture I was passing to that parameter during the game). After this, both the bitmask - and my various bitmask work-arounds / clone - function worked as expected.