RP | Resource | Limit texture color to only black or white

This resource is compatible with either BGE or UPBGE 0.2x versions (legacy versions). Post originally posted here.

TL;TR

There’s two ways to restrict your texture color only to black or white colors.

W/ Material Nodes

  • Use the Hue Saturation Value material node to restrict a texture or material’s color to only black or white by forcing the Value setting to have a number of either be 0.0 or 1.0.

W/O Material Nodes

  • In the bottom of your Properties Editor - Texture Tab:
    • Enable the RGB to Intensity setting.
    • Set the RGB to Intensity Color input to solid black (R:0.0, G:0.0, B:0.0).
    • Lastly, toggle the Negative setting depending on whether you want your material / texture color to be black or white.

Replace Material - Script

  • If you want to replace certain UIs with one color, but different for others, here’s a script that will automatically assign a material for an object depending on if that object has a certain game-property.
    • Feel free to tweak the names of the game-properties and object with the replacement materials that the script will be looking for in the active scene.
    • UI_White & UI_Black are material names, while Textured_Object is the name of the object that already has have the material names assigned to it for easy reference and material tweaking.
import bge

def main(self):

    for o in self.owner.scene.objects:
        for p in o.getPropertyNames():
            if p == "UI_White":
                o.meshes[0].replaceMaterial(0, self.owner.scene.objects["Textured_Object"].meshes[0].materials[0])
            elif p == "UI_Black":
                o.meshes[0].replaceMaterial(0, self.owner.scene.objects["Textured_Object"].meshes[0].materials[1])
1 Like