Hey all, I’m wondering if its possible to adjust the opacity of a texture when you blend it with another one?
For example, I have a rock model with a base texture and a detail texture. I want to fade the detail texture over the base so I’ve used a Blend_Overlay node however this is blending the two textures at 100% opacity. I was wondering if there’s a way to lower the opacity on one of the textures so its not so strong?
The reason I want to do this inside UE4 instead of photoshop is that the tiling on the detail texture is a lot smaller than that of the base texture.
Here you go!
The overlay blending mode is “neutral” at 0.5 (grey). So I used a linear interpolation to blend between the texture and 0.5 using a scalar parameter, this so you can easily tweak it inside material instances.
You know, I tried to use place a LERP node but couldn’t find it in the list anymore. The only ones that came up were the LERP scratchgrime nodes. I thought maybe it was removed and replaced with something else.
Totally not what I told him to do, haha…anyway, I guess you want to use this for a more detailed surface if you are close to an object? If so, you could do this easily inside the material, without scalar parameters…
I know, I’m just a big fan of using parameters when someone is not sure what the end value is going to be. This way you make the material flexible and reusable. The other benefit is that you can change it dynamically, so you don’t have to recompile the shader every time.
This material is already more expensive because of the overlay. An overlay uses a branch so it’s better not to use it.
This is the code for overlay:
return lerp((BaseBlend2),(1.0-(2.0*(1.0-Base)*(1.0-Blend))),step(0.5,Base));
The “step” is:
return x >= a;
x being the Base.
The “lerp” is:
return A+Alpha*(B-A);
So the shader is not cheap for just showing a texture. However, the scalar parameters should not have any real impact on performance, because if you are using a constant instead of a scalar you are still running the same code per pixel, just with an adjustable value. Changes of the compiler being able to optimize the constant in some way is close to 0, and even if that happens, the difference won’t be noticeable.