Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TwinsShader.cs
Go to the documentation of this file.
1using System;
4
6
8{
9 private readonly Vector4 _eyeColor;
10
11 private readonly Vector4 _veinColor;
12
13 private readonly Vector4 _laserColor;
14
15 private readonly Vector4 _mouthColor;
16
17 private readonly Vector4 _flameColor;
18
19 private readonly Vector4 _backgroundColor;
20
21 private static readonly Vector4[] _irisColors = new Vector4[2]
22 {
23 Color.Green.ToVector4(),
24 Color.Blue.ToVector4()
25 };
26
27 public TwinsShader(Color eyeColor, Color veinColor, Color laserColor, Color mouthColor, Color flameColor, Color backgroundColor)
28 {
29 _eyeColor = eyeColor.ToVector4();
30 _veinColor = veinColor.ToVector4();
31 _laserColor = laserColor.ToVector4();
32 _mouthColor = mouthColor.ToVector4();
33 _flameColor = flameColor.ToVector4();
34 _backgroundColor = backgroundColor.ToVector4();
35 }
36
37 [RgbProcessor(/*Could not decode attribute arguments.*/)]
38 private void ProcessLowDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
39 {
40 for (int i = 0; i < fragment.Count; i++)
41 {
42 Vector2 canvasPositionOfIndex = fragment.GetCanvasPositionOfIndex(i);
43 Point gridPositionOfIndex = fragment.GetGridPositionOfIndex(i);
44 Vector4 value = Vector4.Lerp(_veinColor, _eyeColor, (float)Math.Sin(time + canvasPositionOfIndex.X * 4f) * 0.5f + 0.5f);
45 float dynamicNoise = NoiseHelper.GetDynamicNoise(gridPositionOfIndex.X, gridPositionOfIndex.Y, time / 25f);
46 dynamicNoise = Math.Max(0f, 1f - dynamicNoise * 5f);
47 value = Vector4.Lerp(value, _irisColors[((gridPositionOfIndex.Y * 47 + gridPositionOfIndex.X) % _irisColors.Length + _irisColors.Length) % _irisColors.Length], dynamicNoise);
48 fragment.SetColor(i, value);
49 }
50 }
51
52 [RgbProcessor(/*Could not decode attribute arguments.*/)]
53 private void ProcessHighDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
54 {
55 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
56 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
57 //IL_000f: Invalid comparison between Unknown and I4
58 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
59 if ((int)device.Type != 0 && (int)device.Type != 6)
60 {
61 ProcessLowDetail(device, fragment, quality, time);
62 return;
63 }
64 bool flag = true;
65 float num = time * 0.1f % 2f;
66 if (num > 1f)
67 {
68 num = 2f - num;
69 flag = false;
70 }
71 Vector2 vector = new Vector2(num * 7f - 3.5f, 0f) + fragment.CanvasCenter;
72 for (int i = 0; i < fragment.Count; i++)
73 {
74 Vector2 canvasPositionOfIndex = fragment.GetCanvasPositionOfIndex(i);
75 Point gridPositionOfIndex = fragment.GetGridPositionOfIndex(i);
76 Vector4 vector2 = _backgroundColor;
77 Vector2 vector3 = canvasPositionOfIndex - vector;
78 float num2 = vector3.Length();
79 if (num2 < 0.5f)
80 {
81 float amount = 1f - MathHelper.Clamp((num2 - 0.5f + 0.2f) / 0.2f, 0f, 1f);
82 float num3 = MathHelper.Clamp((vector3.X + 0.5f - 0.2f) / 0.6f, 0f, 1f);
83 if (flag)
84 {
85 num3 = 1f - num3;
86 }
88 float value2 = (float)Math.Atan2(vector3.Y, vector3.X);
89 if (!flag && (float)Math.PI - Math.Abs(value2) < 0.6f)
90 {
92 }
93 vector2 = Vector4.Lerp(vector2, value, amount);
94 }
95 if (flag && gridPositionOfIndex.Y == 3 && canvasPositionOfIndex.X > vector.X)
96 {
97 float value3 = 1f - Math.Abs(canvasPositionOfIndex.X - vector.X * 2f - 0.5f) / 0.5f;
98 vector2 = Vector4.Lerp(vector2, _laserColor, MathHelper.Clamp(value3, 0f, 1f));
99 }
100 else if (!flag)
101 {
102 Vector2 vector4 = canvasPositionOfIndex - (vector - new Vector2(1.2f, 0f));
103 vector4.Y *= 3.5f;
104 float num4 = vector4.Length();
105 if (num4 < 0.7f)
106 {
107 float dynamicNoise = NoiseHelper.GetDynamicNoise(canvasPositionOfIndex, time);
108 dynamicNoise = dynamicNoise * dynamicNoise * dynamicNoise;
109 dynamicNoise *= 1f - MathHelper.Clamp((num4 - 0.7f + 0.3f) / 0.3f, 0f, 1f);
110 vector2 = Vector4.Lerp(vector2, _flameColor, dynamicNoise);
111 }
112 }
113 fragment.SetColor(i, vector2);
114 }
115 }
116}
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
Point GetGridPositionOfIndex(int index)
Definition Fragment.cs:81
void SetColor(int index, Vector4 color)
Definition Fragment.cs:97
Vector2 GetCanvasPositionOfIndex(int index)
Definition Fragment.cs:75
readonly RgbDeviceType Type
Definition RgbDevice.cs:8
static double Atan2(double y, double x)
static double Abs(double value)
static double Sin(double a)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static float GetDynamicNoise(int index, float currentTime)
void ProcessHighDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
void ProcessLowDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
static readonly Vector4[] _irisColors
TwinsShader(Color eyeColor, Color veinColor, Color laserColor, Color mouthColor, Color flameColor, Color backgroundColor)
static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
Definition Vector4.cs:277