问题描述
我试图以与精灵渲染器相同的方式在Unity3D中用Color着色Texture2D。 最好的方法是什么?
编辑: 这是我尝试的代码:
private Color Tint(Color source,Color tint) {
Color tinted = source;
//tinted.r = Math.Min(Math.Max(0f,(source.r + (255f - source.r) * tint.r)),255f);
//tinted.g = Math.Min(Math.Max(0f,(source.g + (255f - source.g) * tint.g)),255f);
//tinted.b = Math.Min(Math.Max(0f,(source.b + (255f - source.b) * tint.b)),255f);
//tinted.r = (float)Math.Floor(source.r * tint.r / 255f);
//tinted.g = (float)Math.Floor(source.g * tint.g / 255f);
//tinted.b = (float)Math.Floor(source.b * tint.b / 255f);
Color.RGBToHSV(source,out float sourceH,out float sourceS,out float sourceV);
Color.RGBToHSV(tint,out float tintH,out float tintS,out float tintV);
tinted = Color.HSVToRGB(tintH,tintS,sourceV);
tinted.a = source.a;
return tinted;
}
解决方法
Afaik通常Renderer
的色调是通过乘法完成的(黑色保持黑色),可以简单地使用*
operator来实现
private Color Tint(Color source,Color tint)
{
return source * tint;
}