Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EffectHelpers.cs
Go to the documentation of this file.
2
3internal static class EffectHelpers
4{
6 {
7 light0.Direction = new Vector3(-0.5265408f, -0.5735765f, -0.6275069f);
8 light0.DiffuseColor = new Vector3(1f, 0.9607844f, 0.8078432f);
9 light0.SpecularColor = new Vector3(1f, 0.9607844f, 0.8078432f);
10 light0.Enabled = true;
11 light1.Direction = new Vector3(0.7198464f, 0.3420201f, 0.6040227f);
12 light1.DiffuseColor = new Vector3(82f / 85f, 0.7607844f, 0.4078432f);
13 light1.SpecularColor = Vector3.Zero;
14 light1.Enabled = true;
15 light2.Direction = new Vector3(0.4545195f, -0.7660444f, 0.4545195f);
16 light2.DiffuseColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
17 light2.SpecularColor = new Vector3(0.3231373f, 0.3607844f, 0.3937255f);
18 light2.Enabled = true;
19 return new Vector3(0.05333332f, 0.09882354f, 0.1819608f);
20 }
21
22 internal 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)
23 {
24 if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
25 {
26 Matrix.Multiply(ref world, ref view, out worldView);
27 Matrix.Multiply(ref worldView, ref projection, out var result);
28 worldViewProjParam.SetValue(result);
29 dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
30 }
31 if (fogEnabled)
32 {
33 if ((dirtyFlags & (EffectDirtyFlags.Fog | EffectDirtyFlags.FogEnable)) != 0)
34 {
35 SetFogVector(ref worldView, fogStart, fogEnd, fogVectorParam);
36 dirtyFlags &= ~(EffectDirtyFlags.Fog | EffectDirtyFlags.FogEnable);
37 }
38 }
39 else if ((dirtyFlags & EffectDirtyFlags.FogEnable) != 0)
40 {
41 fogVectorParam.SetValue(Vector4.Zero);
42 dirtyFlags &= ~EffectDirtyFlags.FogEnable;
43 }
44 return dirtyFlags;
45 }
46
47 private static void SetFogVector(ref Matrix worldView, float fogStart, float fogEnd, EffectParameter fogVectorParam)
48 {
49 if (fogStart == fogEnd)
50 {
51 fogVectorParam.SetValue(new Vector4(0f, 0f, 0f, 1f));
52 return;
53 }
54 float num = 1f / (fogStart - fogEnd);
55 Vector4 value = default(Vector4);
56 value.X = worldView.M13 * num;
57 value.Y = worldView.M23 * num;
58 value.Z = worldView.M33 * num;
59 value.W = (worldView.M43 + fogStart) * num;
60 fogVectorParam.SetValue(value);
61 }
62
63 internal static EffectDirtyFlags SetLightingMatrices(EffectDirtyFlags dirtyFlags, ref Matrix world, ref Matrix view, EffectParameter worldParam, EffectParameter worldInverseTransposeParam, EffectParameter eyePositionParam)
64 {
65 if ((dirtyFlags & EffectDirtyFlags.World) != 0)
66 {
67 Matrix.Invert(ref world, out var result);
68 Matrix.Transpose(ref result, out var result2);
69 worldParam.SetValue(world);
70 worldInverseTransposeParam.SetValue(result2);
71 dirtyFlags &= ~EffectDirtyFlags.World;
72 }
73 if ((dirtyFlags & EffectDirtyFlags.EyePosition) != 0)
74 {
75 Matrix.Invert(ref view, out var result3);
76 eyePositionParam.SetValue(result3.Translation);
77 dirtyFlags &= ~EffectDirtyFlags.EyePosition;
78 }
79 return dirtyFlags;
80 }
81
82 internal static void SetMaterialColor(bool lightingEnabled, float alpha, ref Vector3 diffuseColor, ref Vector3 emissiveColor, ref Vector3 ambientLightColor, EffectParameter diffuseColorParam, EffectParameter emissiveColorParam)
83 {
84 if (lightingEnabled)
85 {
86 Vector4 value = default(Vector4);
87 value.X = diffuseColor.X * alpha;
88 value.Y = diffuseColor.Y * alpha;
89 value.Z = diffuseColor.Z * alpha;
90 value.W = alpha;
91 Vector3 value2 = default(Vector3);
92 value2.X = (emissiveColor.X + ambientLightColor.X * diffuseColor.X) * alpha;
93 value2.Y = (emissiveColor.Y + ambientLightColor.Y * diffuseColor.Y) * alpha;
94 value2.Z = (emissiveColor.Z + ambientLightColor.Z * diffuseColor.Z) * alpha;
95 diffuseColorParam.SetValue(value);
96 emissiveColorParam.SetValue(value2);
97 }
98 else
99 {
100 Vector4 value3 = default(Vector4);
101 value3.X = (diffuseColor.X + emissiveColor.X) * alpha;
102 value3.Y = (diffuseColor.Y + emissiveColor.Y) * alpha;
103 value3.Z = (diffuseColor.Z + emissiveColor.Z) * alpha;
104 value3.W = alpha;
105 diffuseColorParam.SetValue(value3);
106 }
107 }
108}
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 void SetFogVector(ref Matrix worldView, float fogStart, float fogEnd, EffectParameter fogVectorParam)
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)
static Matrix Invert(Matrix matrix)
Definition Matrix.cs:1694
static Matrix Multiply(Matrix matrix1, Matrix matrix2)
Definition Matrix.cs:1982
static Matrix Transpose(Matrix matrix)
Definition Matrix.cs:1609