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

**URL:** <https://blenderartists.org/t/rp-resource-limit-texture-color-to-only-black-or-white/1390761>\
**Category:** Game Engine Resources\
**Tags:** code, upbge, bge, materials\
**Created:** [July 12, 2022, 8:00pm UTC](https://blenderartists.org/t/rp-resource-limit-texture-color-to-only-black-or-white/1390761 "2022-07-12T20:00:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RPaladin](https://blenderartists.org/user_avatar/blenderartists.org/rpaladin/32/981579_2.png) [@RPaladin](https://blenderartists.org/u/RPaladin)\
**Post date:** [July 12, 2022, 8:00pm UTC](https://blenderartists.org/t/rp-resource-limit-texture-color-to-only-black-or-white/1390761/1 "2022-07-12T20:00:59Z")

</div>

This resource is compatible with either BGE or UPBGE 0.2x versions (legacy versions). Post originally posted [here](https://blender.stackexchange.com/questions/268907/how-to-invert-game-theme-colour).

# 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`.

 ![image](https://blenderartists.org/uploads/default/original/4X/2/4/e/24e783369dbfcaffac284005e53ccf91bed118ae.jpeg)

# 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`.

 ![image](https://blenderartists.org/uploads/default/original/4X/9/4/8/94837502f53a6d5b18d7a084884fedf5ebbd7fb3.png)

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

```python
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])

```
