Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ArmorShaderData.cs
Go to the documentation of this file.
5
7
9{
11
13
14 private float _uSaturation = 1f;
15
16 private float _uOpacity = 1f;
17
19
21
22 public ArmorShaderData(Ref<Effect> shader, string passName)
23 : base(shader, passName)
24 {
25 }
26
27 public virtual void Apply(Entity entity, DrawData? drawData = null)
28 {
29 base.Shader.Parameters["uColor"].SetValue(_uColor);
30 base.Shader.Parameters["uSaturation"].SetValue(_uSaturation);
31 base.Shader.Parameters["uSecondaryColor"].SetValue(_uSecondaryColor);
32 base.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
33 base.Shader.Parameters["uOpacity"].SetValue(_uOpacity);
34 base.Shader.Parameters["uTargetPosition"].SetValue(_uTargetPosition);
35 if (drawData.HasValue)
36 {
37 DrawData value = drawData.Value;
38 Vector4 value2 = ((!value.sourceRect.HasValue) ? new Vector4(0f, 0f, value.texture.Width, value.texture.Height) : new Vector4(value.sourceRect.Value.X, value.sourceRect.Value.Y, value.sourceRect.Value.Width, value.sourceRect.Value.Height));
39 base.Shader.Parameters["uSourceRect"].SetValue(value2);
40 base.Shader.Parameters["uLegacyArmorSourceRect"].SetValue(value2);
41 base.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + value.position);
42 base.Shader.Parameters["uImageSize0"].SetValue(new Vector2(value.texture.Width, value.texture.Height));
43 base.Shader.Parameters["uLegacyArmorSheetSize"].SetValue(new Vector2(value.texture.Width, value.texture.Height));
44 base.Shader.Parameters["uRotation"].SetValue(value.rotation * (value.effect.HasFlag(SpriteEffects.FlipHorizontally) ? (-1f) : 1f));
45 base.Shader.Parameters["uDirection"].SetValue((!value.effect.HasFlag(SpriteEffects.FlipHorizontally)) ? 1 : (-1));
46 }
47 else
48 {
49 Vector4 value3 = new Vector4(0f, 0f, 4f, 4f);
50 base.Shader.Parameters["uSourceRect"].SetValue(value3);
51 base.Shader.Parameters["uLegacyArmorSourceRect"].SetValue(value3);
52 base.Shader.Parameters["uRotation"].SetValue(0f);
53 }
54 if (_uImage != null)
55 {
56 Main.graphics.GraphicsDevice.Textures[1] = _uImage.Value;
57 base.Shader.Parameters["uImageSize1"].SetValue(new Vector2(_uImage.Width(), _uImage.Height()));
58 }
59 if (entity != null)
60 {
61 base.Shader.Parameters["uDirection"].SetValue((float)entity.direction);
62 }
63 if (entity is Player { bodyFrame: var bodyFrame })
64 {
65 base.Shader.Parameters["uLegacyArmorSourceRect"].SetValue(new Vector4(bodyFrame.X, bodyFrame.Y, bodyFrame.Width, bodyFrame.Height));
66 base.Shader.Parameters["uLegacyArmorSheetSize"].SetValue(new Vector2(40f, 1120f));
67 }
68 Apply();
69 }
70
71 public ArmorShaderData UseColor(float r, float g, float b)
72 {
73 return UseColor(new Vector3(r, g, b));
74 }
75
77 {
78 return UseColor(color.ToVector3());
79 }
80
82 {
83 _uColor = color;
84 return this;
85 }
86
87 public ArmorShaderData UseImage(string path)
88 {
89 _uImage = Main.Assets.Request<Texture2D>(path, (AssetRequestMode)1);
90 return this;
91 }
92
93 public ArmorShaderData UseOpacity(float alpha)
94 {
95 _uOpacity = alpha;
96 return this;
97 }
98
100 {
101 _uTargetPosition = position;
102 return this;
103 }
104
105 public ArmorShaderData UseSecondaryColor(float r, float g, float b)
106 {
107 return UseSecondaryColor(new Vector3(r, g, b));
108 }
109
111 {
112 return UseSecondaryColor(color.ToVector3());
113 }
114
116 {
117 _uSecondaryColor = color;
118 return this;
119 }
120
121 public ArmorShaderData UseSaturation(float saturation)
122 {
123 _uSaturation = saturation;
124 return this;
125 }
126
128 {
129 return this;
130 }
131}
ArmorShaderData(Ref< Effect > shader, string passName)
ArmorShaderData UseImage(string path)
ArmorShaderData UseTargetPosition(Vector2 position)
ArmorShaderData UseOpacity(float alpha)
ArmorShaderData UseSecondaryColor(Vector3 color)
ArmorShaderData UseColor(Vector3 color)
ArmorShaderData UseSecondaryColor(float r, float g, float b)
virtual ArmorShaderData GetSecondaryShader(Entity entity)
ArmorShaderData UseColor(float r, float g, float b)
ArmorShaderData UseSaturation(float saturation)
ArmorShaderData UseColor(Color color)
ArmorShaderData UseSecondaryColor(Color color)
virtual void Apply(Entity entity, DrawData? drawData=null)
static Vector2 screenPosition
Definition Main.cs:1715
static IAssetRepository Assets
Definition Main.cs:209
static float GlobalTimeWrappedHourly
Definition Main.cs:405
static GraphicsDeviceManager graphics
Definition Main.cs:972