Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EnvironmentMapEffect.cs
Go to the documentation of this file.
1using System;
3
5
7{
9
11
13
15
17
19
21
23
25
27
29
31
33
35
36 private bool oneLight;
37
38 private bool fogEnabled;
39
40 private bool fresnelEnabled;
41
42 private bool specularEnabled;
43
45
47
49
51
53
55
57
58 private float alpha = 1f;
59
61
63
65
66 private float fogStart;
67
68 private float fogEnd = 1f;
69
71
73 {
74 get
75 {
76 return world;
77 }
78 set
79 {
80 world = value;
81 dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.World | EffectDirtyFlags.Fog;
82 }
83 }
84
85 public Matrix View
86 {
87 get
88 {
89 return view;
90 }
91 set
92 {
93 view = value;
94 dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.EyePosition | EffectDirtyFlags.Fog;
95 }
96 }
97
99 {
100 get
101 {
102 return projection;
103 }
104 set
105 {
107 dirtyFlags |= EffectDirtyFlags.WorldViewProj;
108 }
109 }
110
112 {
113 get
114 {
115 return diffuseColor;
116 }
117 set
118 {
120 dirtyFlags |= EffectDirtyFlags.MaterialColor;
121 }
122 }
123
125 {
126 get
127 {
128 return emissiveColor;
129 }
130 set
131 {
133 dirtyFlags |= EffectDirtyFlags.MaterialColor;
134 }
135 }
136
137 public float Alpha
138 {
139 get
140 {
141 return alpha;
142 }
143 set
144 {
145 alpha = value;
146 dirtyFlags |= EffectDirtyFlags.MaterialColor;
147 }
148 }
149
151 {
152 get
153 {
154 return ambientLightColor;
155 }
156 set
157 {
159 dirtyFlags |= EffectDirtyFlags.MaterialColor;
160 }
161 }
162
164
166
168
169 public bool FogEnabled
170 {
171 get
172 {
173 return fogEnabled;
174 }
175 set
176 {
177 if (fogEnabled != value)
178 {
180 dirtyFlags |= EffectDirtyFlags.FogEnable | EffectDirtyFlags.ShaderIndex;
181 }
182 }
183 }
184
185 public float FogStart
186 {
187 get
188 {
189 return fogStart;
190 }
191 set
192 {
193 fogStart = value;
195 }
196 }
197
198 public float FogEnd
199 {
200 get
201 {
202 return fogEnd;
203 }
204 set
205 {
206 fogEnd = value;
208 }
209 }
210
212 {
213 get
214 {
216 }
217 set
218 {
220 }
221 }
222
224 {
225 get
226 {
228 }
229 set
230 {
232 }
233 }
234
236 {
237 get
238 {
240 }
241 set
242 {
244 }
245 }
246
248 {
249 get
250 {
252 }
253 set
254 {
256 }
257 }
258
260 {
261 get
262 {
264 }
265 set
266 {
268 bool flag = value != Vector3.Zero;
269 if (specularEnabled != flag)
270 {
271 specularEnabled = flag;
272 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
273 }
274 }
275 }
276
277 public float FresnelFactor
278 {
279 get
280 {
282 }
283 set
284 {
286 bool flag = value != 0f;
287 if (fresnelEnabled != flag)
288 {
289 fresnelEnabled = flag;
290 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
291 }
292 }
293 }
294
295 bool IEffectLights.LightingEnabled
296 {
297 get
298 {
299 return true;
300 }
301 set
302 {
303 if (!value)
304 {
305 throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, FrameworkResources.CantDisableLighting, new object[1] { typeof(EnvironmentMapEffect).Name }));
306 }
307 }
308 }
309
311 : base(device, EnvironmentMapEffectCode.Code)
312 {
314 DirectionalLight0.Enabled = true;
317 FresnelFactor = 1f;
318 }
319
321 : base(cloneSource)
322 {
323 CacheEffectParameters(cloneSource);
324 fogEnabled = cloneSource.fogEnabled;
325 fresnelEnabled = cloneSource.fresnelEnabled;
326 specularEnabled = cloneSource.specularEnabled;
327 world = cloneSource.world;
328 view = cloneSource.view;
329 projection = cloneSource.projection;
330 diffuseColor = cloneSource.diffuseColor;
331 emissiveColor = cloneSource.emissiveColor;
333 alpha = cloneSource.alpha;
334 fogStart = cloneSource.fogStart;
335 fogEnd = cloneSource.fogEnd;
336 }
337
338 public override Effect Clone()
339 {
340 return new EnvironmentMapEffect(this);
341 }
342
347
349 {
350 textureParam = base.Parameters["Texture"];
351 environmentMapParam = base.Parameters["EnvironmentMap"];
352 environmentMapAmountParam = base.Parameters["EnvironmentMapAmount"];
353 environmentMapSpecularParam = base.Parameters["EnvironmentMapSpecular"];
354 fresnelFactorParam = base.Parameters["FresnelFactor"];
355 diffuseColorParam = base.Parameters["DiffuseColor"];
356 emissiveColorParam = base.Parameters["EmissiveColor"];
357 eyePositionParam = base.Parameters["EyePosition"];
358 fogColorParam = base.Parameters["FogColor"];
359 fogVectorParam = base.Parameters["FogVector"];
360 worldParam = base.Parameters["World"];
361 worldInverseTransposeParam = base.Parameters["WorldInverseTranspose"];
362 worldViewProjParam = base.Parameters["WorldViewProj"];
363 shaderIndexParam = base.Parameters["ShaderIndex"];
364 light0 = new DirectionalLight(base.Parameters["DirLight0Direction"], base.Parameters["DirLight0DiffuseColor"], null, cloneSource?.light0);
365 light1 = new DirectionalLight(base.Parameters["DirLight1Direction"], base.Parameters["DirLight1DiffuseColor"], null, cloneSource?.light1);
366 light2 = new DirectionalLight(base.Parameters["DirLight2Direction"], base.Parameters["DirLight2DiffuseColor"], null, cloneSource?.light2);
367 }
368
369 internal override bool WantParameter(EffectParameter parameter)
370 {
371 if (parameter.Name != "VSIndices")
372 {
373 return parameter.Name != "PSIndices";
374 }
375 return false;
376 }
377
378 protected internal override void OnApply()
379 {
382 if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0)
383 {
385 dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
386 }
387 bool flag = !light1.Enabled && !light2.Enabled;
388 if (oneLight != flag)
389 {
390 oneLight = flag;
391 dirtyFlags |= EffectDirtyFlags.ShaderIndex;
392 }
393 if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0)
394 {
395 int num = 0;
396 if (!fogEnabled)
397 {
398 num++;
399 }
400 if (fresnelEnabled)
401 {
402 num += 2;
403 }
404 if (specularEnabled)
405 {
406 num += 4;
407 }
408 if (oneLight)
409 {
410 num += 8;
411 }
413 dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
414 }
415 }
416}
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)
void CacheEffectParameters(EnvironmentMapEffect cloneSource)
override bool WantParameter(EffectParameter parameter)
static CultureInfo CurrentCulture