Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemShadows.cs
浏览该文件的文档.
1using Engine;
5
6namespace Game {
9
11
13
15
16 public static int[] m_drawOrders = [200];
17
18 public int[] DrawOrders => m_drawOrders;
19
20 public virtual void QueueShadow(Camera camera, Vector3 shadowPosition, float shadowDiameter, float alpha) {
22 return;
23 }
24 float num = Vector3.DistanceSquared(camera.ViewPosition, shadowPosition);
25 if (!(num <= 2304f)) {
26 return;
27 }
28 float num2 = MathF.Sqrt(num);
29 float num3 = MathUtils.Saturate(4f * (1f - num2 / 48f));
30 float num0 = 1f - m_subsystemSky.CalculateFog(camera.ViewPosition, shadowPosition);
31 float num4 = shadowDiameter / 2f;
32 int num5 = Terrain.ToCell(shadowPosition.X - num4);
33 int num6 = Terrain.ToCell(shadowPosition.Z - num4);
34 int num7 = Terrain.ToCell(shadowPosition.X + num4);
35 int num8 = Terrain.ToCell(shadowPosition.Z + num4);
36 for (int i = num5; i <= num7; i++) {
37 for (int j = num6; j <= num8; j++) {
38 int num9 = MathUtils.Min(Terrain.ToCell(shadowPosition.Y), 255);
39 int num10 = MathUtils.Max(num9 - 2, 0);
40 for (int num11 = num9; num11 >= num10; num11--) {
41 int cellValueFast = m_subsystemTerrain.Terrain.GetCellValueFast(i, num11, j);
42 int num12 = Terrain.ExtractContents(cellValueFast);
43 Block block = BlocksManager.Blocks[num12];
44 if (block.GetObjectShadowStrength(cellValueFast) > 0f) {
45 BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, cellValueFast);
46 for (int k = 0; k < customCollisionBoxes.Length; k++) {
47 BoundingBox boundingBox = customCollisionBoxes[k];
48 float num13 = boundingBox.Max.Y + num11;
49 if (shadowPosition.Y - num13 > -0.5f) {
50 float num14 = camera.ViewPosition.Y - num13;
51 if (num14 > 0f) {
52 float num15 = MathUtils.Max(num14 * 0.01f, 0.005f);
53 float num16 = MathUtils.Saturate(1f - (shadowPosition.Y - num13) / 2f);
54 Vector3 p = new(boundingBox.Min.X + i, num13 + num15, boundingBox.Min.Z + j);
55 Vector3 p2 = new(boundingBox.Max.X + i, num13 + num15, boundingBox.Min.Z + j);
56 Vector3 p3 = new(boundingBox.Max.X + i, num13 + num15, boundingBox.Max.Z + j);
57 Vector3 p4 = new(boundingBox.Min.X + i, num13 + num15, boundingBox.Max.Z + j);
59 p,
60 p2,
61 p3,
62 p4,
63 shadowPosition,
64 shadowDiameter,
65 0.45f * block.GetObjectShadowStrength(cellValueFast) * alpha * num3 * num0 * num16
66 );
67 }
68 }
69 }
70 break;
71 }
72 if (num12 == 18) {
73 break;
74 }
75 }
76 }
77 }
78 }
79
80 public virtual void Draw(Camera camera, int drawOrder) {
82 }
83
84 public override void Load(ValuesDictionary valuesDictionary) {
85 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
86 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
87 m_batch = m_primitivesRenderer.TexturedBatch(
88 ContentManager.Get<Texture2D>("Textures/Shadow"),
89 false,
90 0,
95 );
96 }
97
98 public virtual void DrawShadowOverQuad(Vector3 p1,
99 Vector3 p2,
100 Vector3 p3,
101 Vector3 p4,
102 Vector3 shadowPosition,
103 float shadowDiameter,
104 float alpha) {
105 if (alpha > 0.02f) {
106 Vector2 texCoord = CalculateShadowTextureCoordinate(p1, shadowPosition, shadowDiameter);
107 Vector2 texCoord2 = CalculateShadowTextureCoordinate(p2, shadowPosition, shadowDiameter);
108 Vector2 texCoord3 = CalculateShadowTextureCoordinate(p3, shadowPosition, shadowDiameter);
109 Vector2 texCoord4 = CalculateShadowTextureCoordinate(p4, shadowPosition, shadowDiameter);
110 m_batch.QueueQuad(
111 p1,
112 p2,
113 p3,
114 p4,
115 texCoord,
116 texCoord2,
117 texCoord3,
118 texCoord4,
119 new Color(0f, 0f, 0f, alpha)
120 );
121 }
122 }
123
124 public static Vector2 CalculateShadowTextureCoordinate(Vector3 p, Vector3 shadowPosition, float shadowDiameter) => new(
125 0.5f + (p.X - shadowPosition.X) / shadowDiameter,
126 0.5f + (p.Z - shadowPosition.Z) / shadowDiameter
127 );
128 }
129}
Engine.Color Color
static readonly BlendState AlphaBlend
static readonly DepthStencilState DepthRead
static readonly RasterizerState CullCounterClockwiseScissor
static int Min(int x1, int x2)
static float Saturate(float x)
static int Max(int x1, int x2)
virtual float GetObjectShadowStrength(int value)
virtual BoundingBox[] GetCustomCollisionBoxes(SubsystemTerrain terrain, int value)
Vector3 ViewPosition
Matrix ViewProjectionMatrix
static object Get(Type type, string name)
virtual void QueueShadow(Camera camera, Vector3 shadowPosition, float shadowDiameter, float alpha)
SubsystemTerrain m_subsystemTerrain
override void Load(ValuesDictionary valuesDictionary)
PrimitivesRenderer3D m_primitivesRenderer
virtual void DrawShadowOverQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 shadowPosition, float shadowDiameter, float alpha)
static Vector2 CalculateShadowTextureCoordinate(Vector3 p, Vector3 shadowPosition, float shadowDiameter)
virtual void Draw(Camera camera, int drawOrder)
static int ExtractContents(int value)
static int ToCell(float x)
ValuesDictionary ValuesDictionary
static float DistanceSquared(Vector3 v1, Vector3 v2)