# Materials How to: if Base output has blue color - then inverse the blue, otherwise do nothing?

**URL:** <https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976>\
**Category:** Asset Creation\
**Tags:** logic, unreal-engine, Blueprint, question, texture-channel\
**Created:** [January 29, 2023, 7:08am UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976 "2023-01-29T07:08:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [January 29, 2023, 7:08am UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/1 "2023-01-29T07:08:30Z")

</div>

UE4.27

1. What is the Material logic to have 2 input paths, 1 output.
2. And how to detect a color/color range + 5% in the Base feed, and if it equals a certain color (blue), then inverse that blue so the final output does not look blue?  
 ![BPGraphScreenshot_2023Y-01M-28D-22h-50m-14s-764_00](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/f/7/df71f227fb6e01f803602b67b79761fab62e8cd1.png)

- Purpose: I have a color changing Material Instance (w/ Master) and a Base texture with some blue colored highlights, while most of the texture is White, so it can be colorized.

- If the player changes the Color Param in game to red, then the White main-parts turn Red, and the Blue-highlight gets a tint of red, but it’s ok - there is still some contrast between the new Red and the Blue highlight.

- But if the player changes Param to Blue, then the White main-parts and Blue highlights are both blue, thus the highlight part can’t be distinguished.

- Thus I want a smart Material that detects if the Base output (after Color Param modifier) turns blue, then inverse the blue to not look blue.

- Please help, ty.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [January 29, 2023, 7:50am UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/2 "2023-01-29T07:50:05Z")

</div>

Just use a mask to color things differently.

A texture is less cost than trying to bungle math you don’t understand hoping to get a result.

As an example, look up any metallic material, the process is essentially the same.

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [January 29, 2023, 8:32am UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/3 "2023-01-29T08:32:07Z")

</div>

I have a texture heavy project (50x textures Id have to make a mask-change for), and I keep going over budget after increasing pool. Thus I want a non texture-asset way to do this - using code.

Do you understand the code, where I went wrong? I put it together the best I could based on different example. But I dont the parts in red.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [January 29, 2023, 10:59am UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/4 "2023-01-29T10:59:58Z")

</div>

Theres so much wrong with it, its pointless to even speculate.

Since it seems all your channels are packed, just isolate blue by using a mask for B.  
The output will be directly the blue color.  
Either before for a mask of the original, or after to change it all as it got mixed by your operations.

If you are going over texture budget, chances are you are using way too large files compared to what is needed. Usually, a 1k^2 texture is enough.  
Additionally generally speaking, specularity, roughness, metallic, and displacement get packed up into a single texture (R = roughness, G = specular or gloss, B is bump/height, and A is metallic, but people change to whatever they prefer).

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [January 29, 2023, 8:57pm UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/5 "2023-01-29T20:57:57Z")

</div>

Does anyone know the Material logic to have 2 input paths, 1 output?  
Or is it even possible?

The code I posted is incomplete because I do not understand how the nodes in the red box work, thus my question.

- **What do I put as [Value] in the Switch node?**  
I need 2 inputs A & B, a 3rd for off/on, no/yes, and an output based on the no/yes result.  
Closeup pic (full pic is in OP):  
 ![Close up 2 path check](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/9/eb9e9b0945c3d5c16f37b419719dffacb43653bd.png)

I got the idea from this pic, using Distance node as a measurement of the difference between [Base output] and [the color I want to detect]:

 ![UE distance mat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/0/1a08cd0f776a403142d985ca7d213ac286aad542.png)

> [@how can I remove background color from a material?](https://forums.unrealengine.com/t/how-can-i-remove-background-color-from-a-material/373035/3):
>
> Thank u very much! I found a solution on github: [GitHub - Tolc/Unreal-UMG-3DObjectInWidget: A simple Unreal Engine 4 project (precisely 4.7.4) showing how to render a 3D object/mesh in a UMG widget.](https://github.com/Tolc/Unreal-UMG-3DObjectInWidget). But this solution generates noticeable aliasing，how can I solve this problem? Thank u.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [January 30, 2023, 9:14am UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/6 "2023-01-30T09:14:09Z")

</div>

Your whole code is wrong period. There is no “because”.

Distance is a measure. In float.  
The input you are using is a float 3.  
The result would mean some sort of difference between RGB of A and RGB of B.  
As a float 3.  
Probably euqal to B minus A as RGB.  
Ei: blue minus blue equal 0 blue channel.  
Again, completely useless.

What you are asking for above, is only applicable by your own asking to a single channel. BLUE. So work in a single channel - which also costs less.

Further, switch makes no sense, as it takes the values and toggles them on or off based on _something_. But in theory an IF would already be doing the same thing. Either filtering out, or returning the same.

Additionally, you don’t multiply colors to change them. 0x1 is? 1x1 is? Your result of 0,0,1 x 0,0,0 would be?  
Just no.  
To color something a different hue, you use a lerp and replace light to black values to other color(s).  
You can change single channel darkenss/lightness to create a different specific color, or you can do it on a texture as a whole by feeding a desaturated version of it as the alpha.

Essentially, go back to the drawing board here. Potentially to learning how materials work.

I would suggest any Ben Cloward videos on youtube as an introductory start.

> **[Ben Cloward](https://www.youtube.com/@BenCloward?app=desktop)**
>
> This channel focuses on shader creation and other game development tips and tricks in Unity and Unreal. Subscribe and ring the bell to receive notifications when new videos are added!
> 
> Ben Cloward has been a game developer for over 20 years and has...

Also some of the Escape Studios videos - though not as basic - are probably a good idea.

> **[Escape Studios](https://www.youtube.com/@Escapestudios)**
>
> At Escape Studios, we offer undergraduate, postgraduate and short courses in Visual Effects (VFX), Game Art, Animation and Motion Graphics.
> 
> We work with an impressive list of industry partners to design and deliver our courses, from MPC, Cinesite,...

---

<div class="post-metadata">

**Author:** ![XxNotAGamerxX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@XxNotAGamerxX](https://forums.unrealengine.com/u/XxNotAGamerxX)\
**Post date:** [January 30, 2023, 6:44pm UTC](https://forums.unrealengine.com/t/materials-how-to-if-base-output-has-blue-color-then-inverse-the-blue-otherwise-do-nothing/758976/7 "2023-01-30T18:44:39Z")

</div>

> [@MostHost\_LA](#):
>
> Your whole code is wrong period

I made that clear in the first post, with the big red comment box, and the Engine saying ERROR. Thus why I posted a visual on this help forum, for the pros to see and answer.  
Ive asked for help 3 times, and you replied 3 times.

1. So do you know the Material logic to have 2 input paths, 1 output? (I showed that I am working with R,G,B.) Can you post a picture instead of words? I am a visual learner.
2. Do you know how to detect a color in the Base feed, and if it equals a certain color [that I set as a PARAM in an MI instance], then inverse that [color detected] so the final output does not look [that color]? Can you post a picture of the code? Ty

> [@MostHost\_LA](#):
>
> What you are asking for above, is only applicable by your own asking to a single channel. BLUE. So work in a single channel - which also costs less.

- No, I am asking for a “smart Material” wildcard “code” solution - that I set the [color to detect/inverse] with a Param in an MI (NOT the Master - not a one time solution for only one channel) - so that I can manually change the Param wildcard (color) as needed for ANY color in any texture-set when using this for 50x MIs.

- The color blue is irrelevant, and only posted as an example for the pros to see what I am asking for help with.

- I know the Alpha connection is wrong in my first pic (orange arrow). I posted it to show I tried many ways, and both gave errors. The RGB route is wrong too, because the Switch node is wrong.  

- I used the Switch to guess, what has 2 inputs and a selector to determine which input goes to the output? And I dont know what to put for all the inputs for the [If node], prior answers worked in older engines but not UE4.27. Thus I asked you.

- So do you know the answer?
