Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BasicEffect.cs
Go to the documentation of this file.
2
4{
6
8
10
12
14
16
18
20
22
24
26
28
29 private bool lightingEnabled;
30
32
33 private bool oneLight;
34
35 private bool fogEnabled;
36
37 private bool textureEnabled;
38
39 private bool vertexColorEnabled;
40
42
44
46
48
50
52
54
55 private float alpha = 1f;
56
58
60
62
63 private float fogStart;
64
65 private float fogEnd = 1f;
66
68
70 {
71 get
72 {
73 return world;
74 }
75 set
76 {
77 world = value;
78 dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World | EffectDirtyFlags.Fog;
79 }
80 }
81
82 public Matrix View
83 {
84 get
85 {
86 return view;
87 }
88 set
89 {
90 view = value;
91 dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.EyePosition | EffectDirtyFlags.Fog;
92 }
93 }
94
96 {
97 get
98 {
99 return projection;
100 }
101 set
102 {
103 projection = value;
104 dirtyFlags |= EffectDirtyFlags.WorldViewProj;
105 }
106 }
107
109 {
110 get
111 {
112 return diffuseColor;
113 }
114 set
115 {
116 diffuseColor = value;
117 dirtyFlags |= EffectDirtyFlags.MaterialColor;
118 }
119 }
120
122 {
123 get
124 {
125 return emissiveColor;
126 }
127 set
128 {
129 emissiveColor = value;
130 dirtyFlags |= EffectDirtyFlags.MaterialColor;
131 }
132 }
133
135 {
136 get
137 {
139 }
140 set
141 {
143 }
144 }
145
146 public float SpecularPower
147 {
148 get
149 {
151 }
152 set
153 {
155 }
156 }
157
158 public float Alpha
159 {
160 get
161 {
162 return alpha;
163 }
164 set
165 {
166 alpha = value;
167 dirtyFlags |= EffectDirtyFlags.MaterialColor;
168 }
169 }
170
171 public bool LightingEnabled
172 {
173 get
174 {
175 return lightingEnabled;
176 }
177 set
178 {
179 if (lightingEnabled != value)
180 {
181 lightingEnabled = value;
182 dirtyFlags |= EffectDirtyFlags.MaterialColor | EffectDirtyFlags.ShaderIndex;
183 }
184 }
185 }
186
188 {
189 get
190 {
192 }
193 set
194 {
195 if (preferPerPixelLighting != value)
196 {
198 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
199 }
200 }
201 }
202
204 {
205 get
206 {
207 return ambientLightColor;
208 }
209 set
210 {
211 ambientLightColor = value;
212 dirtyFlags |= EffectDirtyFlags.MaterialColor;
213 }
214 }
215
217
219
221
222 public bool FogEnabled
223 {
224 get
225 {
226 return fogEnabled;
227 }
228 set
229 {
230 if (fogEnabled != value)
231 {
232 fogEnabled = value;
233 dirtyFlags |= EffectDirtyFlags.FogEnable | EffectDirtyFlags.ShaderIndex;
234 }
235 }
236 }
237
238 public float FogStart
239 {
240 get
241 {
242 return fogStart;
243 }
244 set
245 {
246 fogStart = value;
248 }
249 }
250
251 public float FogEnd
252 {
253 get
254 {
255 return fogEnd;
256 }
257 set
258 {
259 fogEnd = value;
261 }
262 }
263
265 {
266 get
267 {
269 }
270 set
271 {
272 fogColorParam.SetValue(value);
273 }
274 }
275
276 public bool TextureEnabled
277 {
278 get
279 {
280 return textureEnabled;
281 }
282 set
283 {
284 if (textureEnabled != value)
285 {
286 textureEnabled = value;
287 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
288 }
289 }
290 }
291
293 {
294 get
295 {
297 }
298 set
299 {
300 textureParam.SetValue(value);
301 }
302 }
303
305 {
306 get
307 {
308 return vertexColorEnabled;
309 }
310 set
311 {
312 if (vertexColorEnabled != value)
313 {
314 vertexColorEnabled = value;
315 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
316 }
317 }
318 }
319
321 : base(device, BasicEffectCode.Code)
322 {
324 DirectionalLight0.Enabled = true;
326 SpecularPower = 16f;
327 }
328
329 protected BasicEffect(BasicEffect cloneSource)
330 : base(cloneSource)
331 {
332 CacheEffectParameters(cloneSource);
333 lightingEnabled = cloneSource.lightingEnabled;
335 fogEnabled = cloneSource.fogEnabled;
336 textureEnabled = cloneSource.textureEnabled;
338 world = cloneSource.world;
339 view = cloneSource.view;
340 projection = cloneSource.projection;
341 diffuseColor = cloneSource.diffuseColor;
342 emissiveColor = cloneSource.emissiveColor;
344 alpha = cloneSource.alpha;
345 fogStart = cloneSource.fogStart;
346 fogEnd = cloneSource.fogEnd;
347 }
348
349 public override Effect Clone()
350 {
351 return new BasicEffect(this);
352 }
353
359
360 private void CacheEffectParameters(BasicEffect cloneSource)
361 {
362 textureParam = base.Parameters["Texture"];
363 diffuseColorParam = base.Parameters["DiffuseColor"];
364 emissiveColorParam = base.Parameters["EmissiveColor"];
365 specularColorParam = base.Parameters["SpecularColor"];
366 specularPowerParam = base.Parameters["SpecularPower"];
367 eyePositionParam = base.Parameters["EyePosition"];
368 fogColorParam = base.Parameters["FogColor"];
369 fogVectorParam = base.Parameters["FogVector"];
370 worldParam = base.Parameters["World"];
371 worldInverseTransposeParam = base.Parameters["WorldInverseTranspose"];
372 worldViewProjParam = base.Parameters["WorldViewProj"];
373 shaderIndexParam = base.Parameters["ShaderIndex"];
374 light0 = new DirectionalLight(base.Parameters["DirLight0Direction"], base.Parameters["DirLight0DiffuseColor"], base.Parameters["DirLight0SpecularColor"], cloneSource?.light0);
375 light1 = new DirectionalLight(base.Parameters["DirLight1Direction"], base.Parameters["DirLight1DiffuseColor"], base.Parameters["DirLight1SpecularColor"], cloneSource?.light1);
376 light2 = new DirectionalLight(base.Parameters["DirLight2Direction"], base.Parameters["DirLight2DiffuseColor"], base.Parameters["DirLight2SpecularColor"], cloneSource?.light2);
377 }
378
379 internal override bool WantParameter(EffectParameter parameter)
380 {
381 if (parameter.Name != "VSIndices")
382 {
383 return parameter.Name != "PSIndices";
384 }
385 return false;
386 }
387
388 protected internal override void OnApply()
389 {
391 if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0)
392 {
394 dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
395 }
396 if (lightingEnabled)
397 {
399 bool flag = !light1.Enabled && !light2.Enabled;
400 if (oneLight != flag)
401 {
402 oneLight = flag;
403 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
404 }
405 }
406 if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0)
407 {
408 int num = 0;
409 if (!fogEnabled)
410 {
411 num++;
412 }
414 {
415 num += 2;
416 }
417 if (textureEnabled)
418 {
419 num += 4;
420 }
421 if (lightingEnabled)
422 {
423 num = (preferPerPixelLighting ? (num + 24) : ((!oneLight) ? (num + 8) : (num + 16)));
424 }
426 dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
427 }
428 }
429}
void CacheEffectParameters(BasicEffect cloneSource)
override bool WantParameter(EffectParameter parameter)
static Vector3 EnableDefaultLighting(DirectionalLight light0, DirectionalLight light1, DirectionalLight light2)
static void SetMaterialColor(bool lightingEnabled, float alpha, ref Vector3 diffuseColor, ref Vector3 emissiveColor, ref Vector3 ambientLightColor, EffectParameter diffuseColorParam, EffectParameter emissiveColorParam)
static EffectDirtyFlags SetLightingMatrices(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view, EffectParameter worldParam, EffectParameter worldInverseTransposeParam, EffectParameter eyePositionParam)
static EffectDirtyFlags SetWorldViewProjAndFog(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view, ref Matrix projection, ref Matrix worldView, bool fogEnabled, float fogStart, float fogEnd, EffectParameter worldViewProjParam, EffectParameter fogVectorParam)