以Unity相同的方式为Texture2D着色

问题描述

我试图以与精灵渲染器相同的方式在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;
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...