Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MartianMadnessShader.cs
Go to the documentation of this file.
1using System;
4
6
8{
9 private readonly Vector4 _metalColor;
10
11 private readonly Vector4 _glassColor;
12
13 private readonly Vector4 _beamColor;
14
15 private readonly Vector4 _backgroundColor;
16
17 public MartianMadnessShader(Color metalColor, Color glassColor, Color beamColor, Color backgroundColor)
18 {
19 _metalColor = metalColor.ToVector4();
20 _glassColor = glassColor.ToVector4();
21 _beamColor = beamColor.ToVector4();
22 _backgroundColor = backgroundColor.ToVector4();
23 }
24
25 [RgbProcessor(/*Could not decode attribute arguments.*/)]
26 private void ProcessLowDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
27 {
28 for (int i = 0; i < fragment.Count; i++)
29 {
30 Vector2 canvasPositionOfIndex = fragment.GetCanvasPositionOfIndex(i);
31 Point gridPositionOfIndex = fragment.GetGridPositionOfIndex(i);
32 float amount = (float)Math.Sin(time * 2f + canvasPositionOfIndex.X * 5f) * 0.5f + 0.5f;
33 int num = (gridPositionOfIndex.X + gridPositionOfIndex.Y) % 2;
34 if (num < 0)
35 {
36 num += 2;
37 }
38 Vector4 vector = ((num == 1) ? Vector4.Lerp(_glassColor, _beamColor, amount) : _metalColor);
39 fragment.SetColor(i, vector);
40 }
41 }
42
43 [RgbProcessor(/*Could not decode attribute arguments.*/)]
44 private void ProcessHighDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
45 {
46 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
47 //IL_0009: Unknown result type (might be due to invalid IL or missing references)
48 //IL_000f: Invalid comparison between Unknown and I4
49 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
50 if ((int)device.Type != 0 && (int)device.Type != 6)
51 {
52 ProcessLowDetail(device, fragment, quality, time);
53 return;
54 }
55 float num = time * 0.5f % ((float)Math.PI * 2f);
56 if (num > (float)Math.PI)
57 {
58 num = (float)Math.PI * 2f - num;
59 }
60 Vector2 vector = new Vector2(1.7f + (float)Math.Cos(num) * 2f, -0.5f + (float)Math.Sin(num) * 1.1f);
61 for (int i = 0; i < fragment.Count; i++)
62 {
63 Vector2 canvasPositionOfIndex = fragment.GetCanvasPositionOfIndex(i);
64 Vector4 vector2 = _backgroundColor;
65 float num2 = Math.Abs(vector.X - canvasPositionOfIndex.X);
66 if (canvasPositionOfIndex.Y > vector.Y && num2 < 0.2f)
67 {
68 float num3 = 1f - MathHelper.Clamp((num2 - 0.2f + 0.2f) / 0.2f, 0f, 1f);
69 float num4 = Math.Abs((num - (float)Math.PI / 2f) / ((float)Math.PI / 2f));
70 num4 = Math.Max(0f, 1f - num4 * 3f);
71 vector2 = Vector4.Lerp(vector2, _beamColor, num3 * num4);
72 }
73 Vector2 vector3 = vector - canvasPositionOfIndex;
74 vector3.X /= 1f;
75 vector3.Y /= 0.2f;
76 float num5 = vector3.Length();
77 if (num5 < 1f)
78 {
79 float amount = 1f - MathHelper.Clamp((num5 - 1f + 0.2f) / 0.2f, 0f, 1f);
80 vector2 = Vector4.Lerp(vector2, _metalColor, amount);
81 }
82 Vector2 vector4 = vector - canvasPositionOfIndex + new Vector2(0f, -0.1f);
83 vector4.X /= 0.3f;
84 vector4.Y /= 0.3f;
85 if (vector4.Y < 0f)
86 {
87 vector4.Y *= 2f;
88 }
89 float num6 = vector4.Length();
90 if (num6 < 1f)
91 {
92 float amount2 = 1f - MathHelper.Clamp((num6 - 1f + 0.2f) / 0.2f, 0f, 1f);
93 vector2 = Vector4.Lerp(vector2, _glassColor, amount2);
94 }
95 fragment.SetColor(i, vector2);
96 }
97 }
98}
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 Cos(double d)
static double Abs(double value)
static double Sin(double a)
const double PI
Definition Math.cs:16
static byte Max(byte val1, byte val2)
Definition Math.cs:738
void ProcessLowDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
MartianMadnessShader(Color metalColor, Color glassColor, Color beamColor, Color backgroundColor)
void ProcessHighDetail(RgbDevice device, Fragment fragment, EffectDetailLevel quality, float time)
static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
Definition Vector4.cs:277