Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MiscShaderData.cs
Go to the documentation of this file.
1using System;
6
8
10{
12
14
15 private float _uSaturation = 1f;
16
17 private float _uOpacity = 1f;
18
20
22
24
26
28
30
31 public MiscShaderData(Ref<Effect> shader, string passName)
32 : base(shader, passName)
33 {
34 }
35
36 public virtual void Apply(DrawData? drawData = null)
37 {
38 base.Shader.Parameters["uColor"].SetValue(_uColor);
39 base.Shader.Parameters["uSaturation"].SetValue(_uSaturation);
40 base.Shader.Parameters["uSecondaryColor"].SetValue(_uSecondaryColor);
41 base.Shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly);
42 base.Shader.Parameters["uOpacity"].SetValue(_uOpacity);
43 base.Shader.Parameters["uShaderSpecificData"].SetValue(_shaderSpecificData);
44 if (drawData.HasValue)
45 {
46 DrawData value = drawData.Value;
47 Vector4 value2 = Vector4.Zero;
48 if (drawData.Value.sourceRect.HasValue)
49 {
50 value2 = new Vector4(value.sourceRect.Value.X, value.sourceRect.Value.Y, value.sourceRect.Value.Width, value.sourceRect.Value.Height);
51 }
52 base.Shader.Parameters["uSourceRect"].SetValue(value2);
53 base.Shader.Parameters["uWorldPosition"].SetValue(Main.screenPosition + value.position);
54 base.Shader.Parameters["uImageSize0"].SetValue(new Vector2(value.texture.Width, value.texture.Height));
55 }
56 else
57 {
58 base.Shader.Parameters["uSourceRect"].SetValue(new Vector4(0f, 0f, 4f, 4f));
59 }
61 if (_customSamplerState != null)
62 {
63 value3 = _customSamplerState;
64 }
65 if (_uImage0 != null)
66 {
67 Main.graphics.GraphicsDevice.Textures[0] = _uImage0.Value;
68 Main.graphics.GraphicsDevice.SamplerStates[0] = value3;
69 base.Shader.Parameters["uImageSize0"].SetValue(new Vector2(_uImage0.Width(), _uImage0.Height()));
70 }
71 if (_uImage1 != null)
72 {
73 Main.graphics.GraphicsDevice.Textures[1] = _uImage1.Value;
74 Main.graphics.GraphicsDevice.SamplerStates[1] = value3;
75 base.Shader.Parameters["uImageSize1"].SetValue(new Vector2(_uImage1.Width(), _uImage1.Height()));
76 }
77 if (_uImage2 != null)
78 {
79 Main.graphics.GraphicsDevice.Textures[2] = _uImage2.Value;
80 Main.graphics.GraphicsDevice.SamplerStates[2] = value3;
81 base.Shader.Parameters["uImageSize2"].SetValue(new Vector2(_uImage2.Width(), _uImage2.Height()));
82 }
84 base.Apply();
85 }
86
87 public MiscShaderData UseColor(float r, float g, float b)
88 {
89 return UseColor(new Vector3(r, g, b));
90 }
91
93 {
94 return UseColor(color.ToVector3());
95 }
96
98 {
99 _uColor = color;
100 return this;
101 }
102
104 {
106 return this;
107 }
108
109 public MiscShaderData UseImage0(string path)
110 {
111 _uImage0 = Main.Assets.Request<Texture2D>(path, (AssetRequestMode)1);
112 return this;
113 }
114
115 public MiscShaderData UseImage1(string path)
116 {
117 _uImage1 = Main.Assets.Request<Texture2D>(path, (AssetRequestMode)1);
118 return this;
119 }
120
121 public MiscShaderData UseImage2(string path)
122 {
123 _uImage2 = Main.Assets.Request<Texture2D>(path, (AssetRequestMode)1);
124 return this;
125 }
126
127 private static bool IsPowerOfTwo(int n)
128 {
129 return (int)Math.Ceiling(Math.Log(n) / Math.Log(2.0)) == (int)Math.Floor(Math.Log(n) / Math.Log(2.0));
130 }
131
132 public MiscShaderData UseOpacity(float alpha)
133 {
134 _uOpacity = alpha;
135 return this;
136 }
137
138 public MiscShaderData UseSecondaryColor(float r, float g, float b)
139 {
140 return UseSecondaryColor(new Vector3(r, g, b));
141 }
142
144 {
145 return UseSecondaryColor(color.ToVector3());
146 }
147
149 {
150 _uSecondaryColor = color;
151 return this;
152 }
153
155 {
156 _useProjectionMatrix = doUse;
157 return this;
158 }
159
160 public MiscShaderData UseSaturation(float saturation)
161 {
162 _uSaturation = saturation;
163 return this;
164 }
165
167 {
168 return this;
169 }
170
172 {
173 _shaderSpecificData = specificData;
174 return this;
175 }
176}
static readonly SamplerState LinearWrap
static double Ceiling(double a)
static double Log(double d)
static double Floor(double d)
MiscShaderData UseSecondaryColor(Vector3 color)
MiscShaderData UseImage1(string path)
MiscShaderData UseColor(Vector3 color)
MiscShaderData UseImage2(string path)
MiscShaderData UseProjectionMatrix(bool doUse)
MiscShaderData UseSecondaryColor(float r, float g, float b)
MiscShaderData UseSecondaryColor(Color color)
virtual void Apply(DrawData? drawData=null)
virtual MiscShaderData GetSecondaryShader(Entity entity)
MiscShaderData UseColor(Color color)
MiscShaderData UseSaturation(float saturation)
MiscShaderData UseShaderSpecificData(Vector4 specificData)
MiscShaderData UseColor(float r, float g, float b)
MiscShaderData UseSamplerState(SamplerState state)
MiscShaderData UseOpacity(float alpha)
MiscShaderData(Ref< Effect > shader, string passName)
MiscShaderData UseImage0(string path)
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