- Home /
Shader texture blend performance
I'm trying to blend two textures by an amount relative to distance to some game object. Got it working well enough using a vert program to calculate distance and frag program to combine textures. However, the performance isn't great. I comment out the distance calculation and just hard code some value, and the performance doesn't improve, so I feel like the culprit is the lerp. If I just return the main texture, it's fast.
fixed4 frag (v2f i) : COLOR
{
fixed4 mainCol = tex2D (_MainTex, i.uv_MainTex);
fixed4 decalColor = tex2D (_Decal_1, i.uv_MainTex);
return lerp(mainCol, decalColor, i.color.r); // this is slow
// return mainCol; // this is fast
}
Strange thing is if I use the non-CG basic texture blend shader here: http://wiki.unity3d.com/index.php?title=Blend_2_Textures which also uses a lerp, the performance is great:
Pass {
SetTexture[_MainTex]
SetTexture[_Texture2] {
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous // this lerp is fast
}
}
But i lose the ability to vary the blend using vertex distance.
Is there some way to calculate the vertex distance in a non-CG shader?
Is there a more performant way to blend the textures in my frag program?
Thanks!
UPDATE: after some playing around, it seems that it's not even the LERP that's the problem, just the act of having two textures and adding them. Maybe the bottleneck is loading two textures? How does the Unity ShaderLab do it with better performance?
Your answer
![](https://koobas.hobune.stream/wayback/20220613131518im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Blending between two parts of a texture atlas, using another texture atlas as an Alpha Channel 0 Answers
shader cg blending two textures 1 Answer
Logical BlendOp not working 0 Answers
When do _UseClipRect and _UseAlphaClip work in UI-Default.shader of newGUI? 0 Answers
shader for light replacement blending, instead of additive blending? 0 Answers