好的,所以我使用这个带有颜色“漂移”的故障效应(模拟效应)。
https://github.com/keijiro/KinoGlitch
它附带了一个明暗器和这个模拟故障脚本(全部链接):
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Kino Image Effects/Analog Glitch")]
public class AnalogGlitch : MonoBehaviour
{
#region Public Properties
// Scan line jitter
[SerializeField, Range(0, 1)]
float _scanLineJitter = 0;
public float scanLineJitter {
get { return _scanLineJitter; }
set { _scanLineJitter = value; }
}
// Vertical jump
[SerializeField, Range(0, 1)]
float _verticalJump = 0;
public float verticalJump {
get { return _verticalJump; }
set { _verticalJump = value; }
}
// Horizontal shake
[SerializeField, Range(0, 1)]
float _horizontalShake = 0;
public float horizontalShake {
get { return _horizontalShake; }
set { _horizontalShake = value; }
}
// Color drift
[SerializeField, Range(0, 1)]
float _colorDrift = 0;
public float colorDrift {
get { return _colorDrift; }
set { _colorDrift = value; }
}
#endregion
#region Private Properties
[SerializeField] Shader _shader;
Material _material;
float _verticalJumpTime;
#endregion
#region MonoBehaviour Functions
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (_material == null)
{
_material = new Material(_shader);
_material.hideFlags = HideFlags.DontSave;
}
_verticalJumpTime += Time.deltaTime * _verticalJump * 11.3f;
var sl_thresh = Mathf.Clamp01(1.0f - _scanLineJitter * 1.2f);
var sl_disp = 0.002f + Mathf.Pow(_scanLineJitter, 3) * 0.05f;
_material.SetVector("_ScanLineJitter", new Vector2(sl_disp, sl_thresh));
var vj = new Vector2(_verticalJump, _verticalJumpTime);
_material.SetVector("_VerticalJump", vj);
_material.SetFloat("_HorizontalShake", _horizontalShake * 0.2f);
var cd = new Vector2(_colorDrift * 0.04f, Time.time * 606.11f);
_material.SetVector("_ColorDrift", cd);
Graphics.Blit(source, destination, _material);
}
#endregion
我需要找出如何改变它“小故障”的颜色-正如你现在看到的,它小故障绿色和洋红。我需要红色和蓝色,但找不到具体的颜色值。
我可以根据需要发布明暗器-我如何才能实现这个小故障,但在统一的红色/蓝色?
明暗器:
Shader "Hidden/Kino/Glitch/Analog"
{
Properties
{
_MainTex ("-", 2D) = "" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
float2 _MainTex_TexelSize;
float2 _ScanLineJitter; // (displacement, threshold)
float2 _VerticalJump; // (amount, time)
float _HorizontalShake;
float2 _ColorDrift; // (amount, time)
float nrand(float x, float y)
{
return frac(sin(dot(float2(x, y), float2(12.9898, 78.233))) * 43758.5453);
}
half4 frag(v2f_img i) : SV_Target
{
float u = i.uv.x;
float v = i.uv.y;
// Scan line jitter
float jitter = nrand(v, _Time.x) * 2 - 1;
jitter *= step(_ScanLineJitter.y, abs(jitter)) * _ScanLineJitter.x;
// Vertical jump
float jump = lerp(v, frac(v + _VerticalJump.y), _VerticalJump.x);
// Horizontal shake
float shake = (nrand(_Time.x, 2) - 0.5) * _HorizontalShake;
// Color drift
float drift = sin(jump + _ColorDrift.y) * _ColorDrift.x;
half4 src1 = tex2D(_MainTex, frac(float2(u + jitter + shake, jump)));
half4 src2 = tex2D(_MainTex, frac(float2(u + jitter + shake + drift, jump)));
return half4(src1.r, src2.g, src1.b, 1);
}
ENDCG
SubShader
{
Pass
{
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#pragma target 3.0
ENDCG
}
}