Compare commits
	
		
			No commits in common. "50c4d06f192d75d6cc36d88832d7c5a8388d1823" and "e8b77b42bb0354e9b6480344e2ca13df05e6f5f9" have entirely different histories.
		
	
	
		
			50c4d06f19
			...
			e8b77b42bb
		
	
		|  | @ -118,26 +118,42 @@ public class WorldRep : IChunk | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             public readonly Vector4 GetPixel(uint layer, uint x, uint y) |             public readonly Vector4[] AsRgba(uint layer) | ||||||
|             { |             { | ||||||
|                 if (layer >= Pixels.GetLength(0) || x >= Pixels.GetLength(2) || y >= Pixels.GetLength(1)) |                 if (layer >= Pixels.GetLength(0)) | ||||||
|                 { |                 { | ||||||
|                     return Vector4.Zero; | 
 | ||||||
|  |                     return System.Array.Empty<Vector4>(); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 switch (Pixels.GetLength(3)) |                 var height = Pixels.GetLength(1); | ||||||
|  |                 var width = Pixels.GetLength(2); | ||||||
|  |                 var bpp = Pixels.GetLength(3); | ||||||
|  |                 var colours = new Vector4[height * width]; | ||||||
|  |                 for (var y = 0; y < height; y++) | ||||||
|                 { |                 { | ||||||
|                     case 1: |                     for (var x = 0; x < width; x++) | ||||||
|                         var raw1 = Pixels[layer, y, x, 0]; |                     { | ||||||
|                         return new Vector4(raw1, raw1, raw1, 255) / 255.0f; |                         var idx = x + y * width; | ||||||
|                     case 2: | 
 | ||||||
|                         var raw2 = Pixels[layer, y, x, 0] + (Pixels[layer, y, x, 1] << 8); |                         switch (bpp) | ||||||
|                         return new Vector4(raw2 & 31, (raw2 >> 5) & 31, (raw2 >> 10) & 31, 32) / 32.0f; |                         { | ||||||
|                     case 4: |                             case 1: | ||||||
|                         return new Vector4(Pixels[layer, y, x, 0], Pixels[layer, y, x, 1], Pixels[layer, y, x, 2], Pixels[layer, y, x, 3]) / 255.0f; |                                 var raw1 = Pixels[layer, y, x, 0]; | ||||||
|                     default: |                                 colours[idx] = new Vector4(raw1, raw1, raw1, 255) / 255.0f; | ||||||
|                         return Vector4.Zero; |                                 break; | ||||||
|  |                             case 2: | ||||||
|  |                                 var raw2 = Pixels[layer, y, x, 0] + (Pixels[layer, y, x, 1] << 8); | ||||||
|  |                                 colours[idx] = new Vector4(raw2 & 31, (raw2 >> 5) & 31, (raw2 >> 10) & 31, 32) / 32.0f; | ||||||
|  |                                 break; | ||||||
|  |                             case 4: | ||||||
|  |                                 colours[idx] = new Vector4(Pixels[layer, y, x, 0], Pixels[layer, y, x, 1], Pixels[layer, y, x, 2], Pixels[layer, y, x, 3]) / 255.0f; | ||||||
|  |                                 break; | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|  | 
 | ||||||
|  |                 return colours; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,9 +5,8 @@ namespace KeepersCompound.LGS; | ||||||
| 
 | 
 | ||||||
| public static class Utils | public static class Utils | ||||||
| { | { | ||||||
|     const float InverseScale = 4.0f; |     public static Godot.Vector3 ToGodotVec3(this Vector3 vec, float inverseScale) | ||||||
|     public static Godot.Vector3 ToGodotVec3(this Vector3 vec) |  | ||||||
|     { |     { | ||||||
|         return new Godot.Vector3(vec.Y, vec.Z, vec.X) / InverseScale; |         return new Godot.Vector3(vec.Y, vec.Z, vec.X) / inverseScale; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -103,12 +103,12 @@ public partial class Mission : Node3D | ||||||
| 			var poly = cell.Polys[i]; | 			var poly = cell.Polys[i]; | ||||||
| 			var meshIdxOffset = vertices.Count; | 			var meshIdxOffset = vertices.Count; | ||||||
| 
 | 
 | ||||||
| 			var normal = cell.Planes[poly.PlaneId].Normal.ToGodotVec3(); | 			var normal = cell.Planes[poly.PlaneId].Normal.ToGodotVec3(4.0f); | ||||||
| 			var numPolyVertices = poly.VertexCount; | 			var numPolyVertices = poly.VertexCount; | ||||||
| 			for (var j = 0; j < numPolyVertices; j++) | 			for (var j = 0; j < numPolyVertices; j++) | ||||||
| 			{ | 			{ | ||||||
| 				var vertex = cell.Vertices[cell.Indices[cellIdxOffset + j]]; | 				var vertex = cell.Vertices[cell.Indices[cellIdxOffset + j]]; | ||||||
| 				vertices.Add(vertex.ToGodotVec3()); | 				vertices.Add(vertex.ToGodotVec3(4.0f)); | ||||||
| 				normals.Add(normal); | 				normals.Add(normal); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -137,20 +137,15 @@ public partial class Mission : Node3D | ||||||
| 			// Build lightmap | 			// Build lightmap | ||||||
| 			var lightmap = cell.Lightmaps[rect.Id]; | 			var lightmap = cell.Lightmaps[rect.Id]; | ||||||
| 			// TODO: Handle animlight layers | 			// TODO: Handle animlight layers | ||||||
| 			var layers = (uint)lightmap.Pixels.GetLength(0); | 			var colours = lightmap.AsRgba(0); | ||||||
| 			var height = (uint)lightmap.Pixels.GetLength(1); | 			var height = lightmap.Pixels.GetLength(1); | ||||||
| 			var width = (uint)lightmap.Pixels.GetLength(2); | 			var width = lightmap.Pixels.GetLength(2); | ||||||
| 			for (uint y = 0; y < height; y++) | 			for (var y = 0; y < height; y++) | ||||||
| 			{ | 			{ | ||||||
| 				for (uint x = 0; x < width; x++) | 				for (var x = 0; x < width; x++) | ||||||
| 				{ | 				{ | ||||||
| 					var rawColour = System.Numerics.Vector4.Zero; | 					var rawColour = colours[x + y * width]; | ||||||
| 					for (uint l = 0; l < layers; l++) | 					image.SetPixel((int)rect.X + x, (int)rect.Y + y, new Color(rawColour.X, rawColour.Y, rawColour.Z, rawColour.W)); | ||||||
| 					{ |  | ||||||
| 						rawColour += lightmap.GetPixel(l, x, y); |  | ||||||
| 					} |  | ||||||
| 					var colour = new Color(MathF.Min(rawColour.X, 1.0f), MathF.Min(rawColour.Y, 1.0f), MathF.Min(rawColour.Z, 1.0f), MathF.Min(rawColour.W, 1.0f)); |  | ||||||
| 					image.SetPixel((int)(rect.X + x), (int)(rect.Y + y), colour); |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | @ -216,7 +211,7 @@ public partial class Mission : Node3D | ||||||
| 		{ | 		{ | ||||||
| 			var light = new OmniLight3D | 			var light = new OmniLight3D | ||||||
| 			{ | 			{ | ||||||
| 				Position = cell.SphereCenter.ToGodotVec3(), | 				Position = cell.SphereCenter.ToGodotVec3(4.0f), | ||||||
| 				OmniRange = cell.SphereRadius * (r.NextSingle() + 1.0f) * 0.5f, | 				OmniRange = cell.SphereRadius * (r.NextSingle() + 1.0f) * 0.5f, | ||||||
| 			}; | 			}; | ||||||
| 			// cellNode.AddChild(light); | 			// cellNode.AddChild(light); | ||||||
|  | @ -235,8 +230,8 @@ public partial class Mission : Node3D | ||||||
| 	{ | 	{ | ||||||
| 		// TODO: This is slightly hardcoded for ND. Check other stuff at some point. Should be handled in LG side imo | 		// TODO: This is slightly hardcoded for ND. Check other stuff at some point. Should be handled in LG side imo | ||||||
| 		// TODO: This is a mess lol | 		// TODO: This is a mess lol | ||||||
| 		var texU = renderPoly.TextureVectors.Item1.ToGodotVec3(); | 		var texU = renderPoly.TextureVectors.Item1.ToGodotVec3(4.0f); | ||||||
| 		var texV = renderPoly.TextureVectors.Item2.ToGodotVec3(); | 		var texV = renderPoly.TextureVectors.Item2.ToGodotVec3(4.0f); | ||||||
| 
 | 
 | ||||||
| 		var uu = texU.Dot(texU); | 		var uu = texU.Dot(texU); | ||||||
| 		var vv = texV.Dot(texV); | 		var vv = texV.Dot(texV); | ||||||
|  | @ -248,7 +243,7 @@ public partial class Mission : Node3D | ||||||
| 		var baseV = renderPoly.TextureBases.Item2; | 		var baseV = renderPoly.TextureBases.Item2; | ||||||
| 		var lmUBase = lmUScale * (baseU + (0.5f - light.Bases.Item1) / 4.0f); | 		var lmUBase = lmUScale * (baseU + (0.5f - light.Bases.Item1) / 4.0f); | ||||||
| 		var lmVBase = lmVScale * (baseV + (0.5f - light.Bases.Item2) / 4.0f); | 		var lmVBase = lmVScale * (baseV + (0.5f - light.Bases.Item2) / 4.0f); | ||||||
| 		var anchor = cell.Vertices[cell.Indices[cellIdxOffset + 0]].ToGodotVec3(); // TODO: This probably shouldn't be hardcoded idx 0 | 		var anchor = cell.Vertices[cell.Indices[cellIdxOffset + 0]].ToGodotVec3(4.0f); // TODO: This probably shouldn't be hardcoded idx 0 | ||||||
| 
 | 
 | ||||||
| 		var uvIdxs = new int[poly.VertexCount]; | 		var uvIdxs = new int[poly.VertexCount]; | ||||||
| 		if (uv == 0.0) | 		if (uv == 0.0) | ||||||
|  | @ -259,7 +254,7 @@ public partial class Mission : Node3D | ||||||
| 			{ | 			{ | ||||||
| 				uvIdxs[i] = lightmapUvs.Count; | 				uvIdxs[i] = lightmapUvs.Count; | ||||||
| 
 | 
 | ||||||
| 				var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(); | 				var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(4.0f); | ||||||
| 				var delta = new Vector3(v.X - anchor.X, v.Y - anchor.Y, v.Z - anchor.Z); | 				var delta = new Vector3(v.X - anchor.X, v.Y - anchor.Y, v.Z - anchor.Z); | ||||||
| 				var lmUV = new Vector2(delta.Dot(lmUVec) + lmUBase, delta.Dot(lmVVec) + lmVBase); | 				var lmUV = new Vector2(delta.Dot(lmUVec) + lmUBase, delta.Dot(lmVVec) + lmVBase); | ||||||
| 				lightmapUvs.Add(lmUV); | 				lightmapUvs.Add(lmUV); | ||||||
|  | @ -276,7 +271,7 @@ public partial class Mission : Node3D | ||||||
| 			{ | 			{ | ||||||
| 				uvIdxs[i] = lightmapUvs.Count; | 				uvIdxs[i] = lightmapUvs.Count; | ||||||
| 
 | 
 | ||||||
| 				var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(); | 				var v = cell.Vertices[cell.Indices[cellIdxOffset + i]].ToGodotVec3(4.0f); | ||||||
| 				var delta = new Vector3(v.X - anchor.X, v.Y - anchor.Y, v.Z - anchor.Z); | 				var delta = new Vector3(v.X - anchor.X, v.Y - anchor.Y, v.Z - anchor.Z); | ||||||
| 				var du = delta.Dot(texU); | 				var du = delta.Dot(texU); | ||||||
| 				var dv = delta.Dot(texV); | 				var dv = delta.Dot(texV); | ||||||
|  |  | ||||||
|  | @ -4,9 +4,6 @@ | ||||||
| [ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"] | [ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"] | ||||||
| 
 | 
 | ||||||
| [sub_resource type="Environment" id="Environment_oxkvl"] | [sub_resource type="Environment" id="Environment_oxkvl"] | ||||||
| ambient_light_source = 2 |  | ||||||
| ambient_light_color = Color(1, 1, 1, 1) |  | ||||||
| ssao_enabled = true |  | ||||||
| 
 | 
 | ||||||
| [node name="Main" type="Node3D"] | [node name="Main" type="Node3D"] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue