Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HairShaderData.cs
Go to the documentation of this file.
5
7
9{
11
13
14 protected float _uSaturation = 1f;
15
16 protected float _uOpacity = 1f;
17
19
20 protected bool _shaderDisabled;
21
23
25
26 public HairShaderData(Ref<Effect> shader, string passName)
27 : base(shader, passName)
28 {
29 }
30
31 public virtual void Apply(Player player, DrawData? drawData = null)
32 {
33 if (!_shaderDisabled)
34 {
35 base.Shader.Parameters["uColor"].SetValue(_uColor);
36 base.Shader.Parameters["uSaturation"].SetValue(_uSaturation);
37 base.Shader.Parameters["uSecondaryColor"].SetValue(_uSecondaryColor);
38 base.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
39 base.Shader.Parameters["uOpacity"].SetValue(_uOpacity);
40 base.Shader.Parameters["uTargetPosition"].SetValue(_uTargetPosition);
41 if (drawData.HasValue)
42 {
43 DrawData value = drawData.Value;
44 Vector4 value2 = new Vector4(value.sourceRect.Value.X, value.sourceRect.Value.Y, value.sourceRect.Value.Width, value.sourceRect.Value.Height);
45 base.Shader.Parameters["uSourceRect"].SetValue(value2);
46 base.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + value.position);
47 base.Shader.Parameters["uImageSize0"].SetValue(new Vector2(value.texture.Width, value.texture.Height));
48 }
49 else
50 {
51 base.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0f, 0f, 4f, 4f));
52 }
53 if (_uImage != null)
54 {
55 Main.graphics.GraphicsDevice.Textures[1] = _uImage.Value;
56 base.Shader.Parameters["uImageSize1"].SetValue(new Vector2(_uImage.Width(), _uImage.Height()));
57 }
58 if (player != null)
59 {
60 base.Shader.Parameters["uDirection"].SetValue((float)player.direction);
61 }
62 Apply();
63 }
64 }
65
66 public virtual Color GetColor(Player player, Color lightColor)
67 {
68 return new Color(lightColor.ToVector4() * player.hairColor.ToVector4());
69 }
70
71 public HairShaderData 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 HairShaderData UseImage(string path)
88 {
89 _uImage = Main.Assets.Request<Texture2D>(path, (AssetRequestMode)1);
90 return this;
91 }
92
93 public HairShaderData UseOpacity(float alpha)
94 {
95 _uOpacity = alpha;
96 return this;
97 }
98
99 public HairShaderData UseSecondaryColor(float r, float g, float b)
100 {
101 return UseSecondaryColor(new Vector3(r, g, b));
102 }
103
105 {
106 return UseSecondaryColor(color.ToVector3());
107 }
108
110 {
111 _uSecondaryColor = color;
112 return this;
113 }
114
115 public HairShaderData UseSaturation(float saturation)
116 {
117 _uSaturation = saturation;
118 return this;
119 }
120
122 {
123 _uTargetPosition = position;
124 return this;
125 }
126}
virtual Color GetColor(Player player, Color lightColor)
HairShaderData UseColor(Color color)
HairShaderData UseSaturation(float saturation)
virtual void Apply(Player player, DrawData? drawData=null)
HairShaderData UseSecondaryColor(float r, float g, float b)
HairShaderData UseColor(float r, float g, float b)
HairShaderData UseSecondaryColor(Vector3 color)
HairShaderData UseSecondaryColor(Color color)
HairShaderData(Ref< Effect > shader, string passName)
HairShaderData UseImage(string path)
HairShaderData UseOpacity(float alpha)
HairShaderData UseColor(Vector3 color)
HairShaderData UseTargetPosition(Vector2 position)
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
Color hairColor
Definition Player.cs:2133