Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
LightingManager.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
4 public static class LightingManager {
5 public static readonly float LightAmbient = 0.5f;
6
7 public static readonly Vector3 DirectionToLight1 = new(0.12f, 0.25f, 0.34f);
8
9 public static readonly Vector3 DirectionToLight2 = new(-0.12f, 0.25f, -0.34f);
10
11 public static readonly float[] LightIntensityByLightValue = new float[16];
12
13 public static readonly float[] LightIntensityByLightValueAndFace = new float[96];
14
15 public static bool Loaded;
16
17 public static void Initialize() {
18 if (Loaded) {
19 return;
20 }
21 SettingsManager.SettingChanged += delegate(string name) {
22 if (name == "Brightness") {
24 }
25 };
27 Loaded = true;
28 }
29
30 public static float CalculateLighting(Vector3 normal) => LightAmbient
33
34 public static float? CalculateSmoothLight(SubsystemTerrain subsystemTerrain, Vector3 p) {
35 p -= new Vector3(0.5f);
36 int num = (int)MathF.Floor(p.X);
37 int num2 = (int)MathF.Floor(p.Y);
38 int num3 = (int)MathF.Floor(p.Z);
39 int x = (int)MathF.Ceiling(p.X);
40 int num4 = (int)MathF.Ceiling(p.Y);
41 int z = (int)MathF.Ceiling(p.Z);
42 Terrain terrain = subsystemTerrain.Terrain;
43 if (num2 >= 0
44 && num4 <= TerrainChunk.HeightMinusOne) {
45 TerrainChunk chunkAtCell = terrain.GetChunkAtCell(num, num3);
46 TerrainChunk chunkAtCell2 = terrain.GetChunkAtCell(x, num3);
47 TerrainChunk chunkAtCell3 = terrain.GetChunkAtCell(num, z);
48 TerrainChunk chunkAtCell4 = terrain.GetChunkAtCell(x, z);
49 if (chunkAtCell != null
50 && chunkAtCell.State >= TerrainChunkState.InvalidVertices1
51 && chunkAtCell2 != null
52 && chunkAtCell2.State >= TerrainChunkState.InvalidVertices1
53 && chunkAtCell3 != null
54 && chunkAtCell3.State >= TerrainChunkState.InvalidVertices1
55 && chunkAtCell4 != null
56 && chunkAtCell4.State >= TerrainChunkState.InvalidVertices1) {
57 float f = p.X - num;
58 float f2 = p.Y - num2;
59 float f3 = p.Z - num3;
60 float x2 = terrain.GetCellLightFast(num, num2, num3);
61 float x3 = terrain.GetCellLightFast(num, num2, z);
62 float x4 = terrain.GetCellLightFast(num, num4, num3);
63 float x5 = terrain.GetCellLightFast(num, num4, z);
64 float x6 = terrain.GetCellLightFast(x, num2, num3);
65 float x7 = terrain.GetCellLightFast(x, num2, z);
66 float x8 = terrain.GetCellLightFast(x, num4, num3);
67 float x9 = terrain.GetCellLightFast(x, num4, z);
68 float x10 = MathUtils.Lerp(x2, x6, f);
69 float x11 = MathUtils.Lerp(x3, x7, f);
70 float x12 = MathUtils.Lerp(x4, x8, f);
71 float x13 = MathUtils.Lerp(x5, x9, f);
72 float x14 = MathUtils.Lerp(x10, x12, f2);
73 float x15 = MathUtils.Lerp(x11, x13, f2);
74 float num5 = MathUtils.Lerp(x14, x15, f3);
75 int num6 = (int)MathF.Floor(num5);
76 int num7 = (int)MathF.Ceiling(num5);
77 float f4 = num5 - num6;
79 "CalculateSmoothLight",
80 l => {
81 l.CalculateSmoothLight(subsystemTerrain, p, ref f4);
82 return false;
83 }
84 );
86 }
87 }
88 return null;
89 }
90
91 public static void CalculateLightingTables() {
92 float brightness = SettingsManager.Brightness;
94 "CalculateLighting",
95 modLoader => {
96 modLoader.CalculateLighting(ref brightness);
97 return false;
98 }
99 );
100 float x = MathUtils.Lerp(0f, 0.1f, brightness);
101 for (int i = 0; i < 16; i++) {
102 LightIntensityByLightValue[i] = MathUtils.Saturate(MathUtils.Lerp(x, 1f, MathF.Pow(i / 15f, 1.25f)));
103 }
104 for (int j = 0; j < 6; j++) {
106 for (int k = 0; k < 16; k++) {
108 }
109 }
110 }
111 }
112}
Engine.Vector3 Vector3
static float Saturate(float x)
static int Max(int x1, int x2)
static float Lerp(float x1, float x2, float f)
static readonly float[] LightIntensityByLightValue
static readonly Vector3 DirectionToLight2
static void CalculateLightingTables()
static readonly float LightAmbient
static float CalculateLighting(Vector3 normal)
static readonly float[] LightIntensityByLightValueAndFace
static ? float CalculateSmoothLight(SubsystemTerrain subsystemTerrain, Vector3 p)
static readonly Vector3 DirectionToLight1
static Action< string > SettingChanged
TerrainChunkState State
virtual int GetCellLightFast(int x, int y, int z)
virtual TerrainChunk GetChunkAtCell(int x, int z)
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static float Dot(Vector3 v1, Vector3 v2)
static Vector3 FaceToVector3(int face)