在Unity中,Color Correction (颜色校正) 是一种用于调整场景或游戏画面颜色的技术。其中,Curves(曲线)和Saturation(饱和度)是常用的Color Correction工具。通过Curves,可以对RGB通道进行非线性调整,从而影响画面的色调和对比度。而Saturation用于调整画面的饱和度,使颜色更加鲜艳或淡化。
在Unity中,Curves用于调整RGB通道的曲线,其参数如下:
在Unity中,Saturation用于调整画面的饱和度,其参数如下:
using UnityEngine;
public class ColorCorrectionExample : MonoBehaviour
{
public AnimationCurve redCurve;
public AnimationCurve greenCurve;
public AnimationCurve blueCurve;
private Material material;
private void Awake()
{
material = new Material(Shader.Find("Custom/ColorCorrection"));
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetTexture("_MainTex", source);
material.SetFloatArray("_RedCurve", redCurve.keys.Select(key => key.value).ToArray());
material.SetFloatArray("_GreenCurve", greenCurve.keys.Select(key => key.value).ToArray());
material.SetFloatArray("_BlueCurve", blueCurve.keys.Select(key => key.value).ToArray());
Graphics.Blit(source, destination, material);
}
}
using UnityEngine;
public class ColorCorrectionExample : MonoBehaviour
{
public AnimationCurve redCurve;
public AnimationCurve greenCurve;
public AnimationCurve blueCurve;
private Material material;
private void Awake()
{
material = new Material(Shader.Find("Custom/ColorCorrection"));
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetTexture("_MainTex", source);
material.SetFloatArray("_RedCurve", redCurve.keys.Select(key => Mathf.Sin(key.value)).ToArray());
material.SetFloatArray("_GreenCurve", greenCurve.keys.Select(key => Mathf.Cos(key.value)).ToArray());
material.SetFloatArray("_BlueCurve", blueCurve.keys.Select(key => Mathf.Tan(key.value)).ToArray());
Graphics.Blit(source, destination, material);
}
}
using UnityEngine;
public class SaturationExample : MonoBehaviour
{
[Range(0f, 2f)]
public float saturationValue = 1f;
private Material material;
private void Awake()
{
material = new Material(Shader.Find("Custom/Saturation"));
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetTexture("_MainTex", source);
material.SetFloat("_Saturation", saturationValue);
Graphics.Blit(source, destination, material);
}
}
using UnityEngine;
public class SaturationExample : MonoBehaviour
{
[Range(0f, 2f)]
public float saturationValue = 1f;
private Material material;
private void Awake()
{
material = new Material(Shader.Find("Custom/Saturation"));
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
material.SetTexture("_MainTex", source);
material.SetFloat("_Saturation", 1f / saturationValue);
Graphics.Blit(source, destination, material);
}
}
以上代码中使用了自定义的Shader(Custom/ColorCorrection和Custom/Saturation)来进行颜色校正操作。这里我们只是提供了简单的例子来演示如何使用Curves和Saturation来调整颜色,实际上可以通过调整曲线和参数来实现更复杂的颜色效果。