diff --git a/NewHorizons/Body/Geometry/CubeSphere.cs b/NewHorizons/Body/Geometry/CubeSphere.cs index 6593f361..05962a78 100644 --- a/NewHorizons/Body/Geometry/CubeSphere.cs +++ b/NewHorizons/Body/Geometry/CubeSphere.cs @@ -25,6 +25,9 @@ namespace NewHorizons.Body CreateVertices(mesh, resolution, heightMap, minHeight, maxHeight); CreateTriangles(mesh, resolution); + mesh.RecalculateNormals(); + mesh.RecalculateTangents(); + return mesh; } @@ -45,6 +48,10 @@ namespace NewHorizons.Body for (int x = 0; x <= resolution; x++) { SetVertex(vertices, normals, uvs, v++, x, y, 0, resolution, heightMap, minHeight, maxHeight); + if (x == resolution / 2 && y < resolution / 2) + { + Logger.Log($"{uvs[v - 1]}"); + } } for (int z = 1; z <= resolution; z++) { @@ -53,6 +60,10 @@ namespace NewHorizons.Body for (int x = resolution - 1; x >= 0; x--) { SetVertex(vertices, normals, uvs, v++, x, y, resolution, resolution, heightMap, minHeight, maxHeight); + if (x == resolution / 2 && y < resolution / 2) + { + Logger.Log($"{uvs[v - 1]}"); + } } for (int z = resolution - 1; z > 0; z--) { @@ -72,6 +83,10 @@ namespace NewHorizons.Body for (int x = 1; x < resolution; x++) { SetVertex(vertices, normals, uvs, v++, x, 0, z, resolution, heightMap, minHeight, maxHeight); + if (x == resolution / 2) + { + Logger.Log($"{uvs[v - 1]}"); + } } } @@ -92,8 +107,10 @@ namespace NewHorizons.Body v.y = v2.y * Mathf.Sqrt(1f - x2 / 2f - z2 / 2f + x2 * z2 / 3f); v.z = v2.z * Mathf.Sqrt(1f - x2 / 2f - y2 / 2f + x2 * y2 / 3f); - float latitude = (Mathf.Rad2Deg * Mathf.Acos(v.z / Mathf.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z))) % 180f; - float longitude = (Mathf.Rad2Deg * (v.x > 0 ? Mathf.Atan(v.y / v.x) : Mathf.Atan(v.y / v.x) + Mathf.PI) + 90f) % 360f; + float latitude = (Mathf.Rad2Deg * Mathf.Acos(v.z / Mathf.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z))); + float longitude = 180f; + if(v.x > 0) longitude = Mathf.Rad2Deg * Mathf.Atan(v.y / v.x) + 90f; + if(v.x < 0) longitude = Mathf.Rad2Deg * (Mathf.Atan(v.y / v.x) + Mathf.PI) + 90f; float sampleX = heightMap.width * longitude / 360f; float sampleY = heightMap.height * latitude / 180f; @@ -102,7 +119,10 @@ namespace NewHorizons.Body normals[i] = v.normalized; vertices[i] = normals[i] * (relativeHeight * (maxHeight - minHeight) + minHeight); - uvs[i] = new Vector2(sampleX / (float)heightMap.width, sampleY / (float)heightMap.height); + + var uvX = sampleX / (float)heightMap.width; + var uvY = sampleY / (float)heightMap.height; + uvs[i] = new Vector2(uvX, uvY); } private static void CreateTriangles(Mesh mesh, int resolution) diff --git a/NewHorizons/Body/Geometry/Icosphere.cs b/NewHorizons/Body/Geometry/Icosphere.cs index fd7334fd..5ea5cc2f 100644 --- a/NewHorizons/Body/Geometry/Icosphere.cs +++ b/NewHorizons/Body/Geometry/Icosphere.cs @@ -72,12 +72,14 @@ namespace NewHorizons.Body.Geometry Vector3[] normals = new Vector3[verticesToCopy.Length]; Vector2[] uvs = new Vector2[verticesToCopy.Length]; + Dictionary seamVertices = new Dictionary(); + for(int i = 0; i < verticesToCopy.Length; i++) { var v = verticesToCopy[i]; - float latitude = (Mathf.Rad2Deg * Mathf.Acos(v.z / Mathf.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z))) % 180f; - float longitude = (Mathf.Rad2Deg * (v.x > 0 ? Mathf.Atan(v.y / v.x) : Mathf.Atan(v.y / v.x) + Mathf.PI) + 90f) % 360f; + float latitude = Mathf.Repeat(Mathf.Rad2Deg * Mathf.Acos(v.z / Mathf.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z)), 180f); + float longitude = Mathf.Repeat(Mathf.Rad2Deg * (v.x > 0 ? Mathf.Atan(v.y / v.x) : Mathf.Atan(v.y / v.x) + Mathf.PI) + 90f, 360f); float sampleX = heightMap.width * longitude / 360f; float sampleY = heightMap.height * latitude / 180f; @@ -86,7 +88,14 @@ namespace NewHorizons.Body.Geometry newVertices[i] = verticesToCopy[i] * height; normals[i] = v.normalized; - uvs[i] = new Vector2(sampleX / (float)heightMap.width, sampleY / (float)heightMap.height); + + var x = longitude / 360f; + var y = latitude / 180f; + + if (x == 0) seamVertices.Add(y, i); + + + uvs[i] = new Vector2(x, y); } mesh.vertices = newVertices; diff --git a/NewHorizons/Body/HeightMapBuilder.cs b/NewHorizons/Body/HeightMapBuilder.cs index 82964176..246a1e42 100644 --- a/NewHorizons/Body/HeightMapBuilder.cs +++ b/NewHorizons/Body/HeightMapBuilder.cs @@ -12,6 +12,9 @@ namespace NewHorizons.Body { static class HeightMapBuilder { + public static AssetBundle ShaderBundle; + public static Shader PlanetShader; + public static void Make(GameObject go, HeightMapModule module) { Texture2D heightMap, textureMap; @@ -26,24 +29,28 @@ namespace NewHorizons.Body return; } - /* + GameObject cubeSphere = new GameObject("CubeSphere"); cubeSphere.transform.parent = go.transform; cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0); - Mesh mesh = CubeSphere.Build(100, heightMap, module.MinHeight, module.MaxHeight); + Mesh mesh = CubeSphere.Build(51, heightMap, module.MinHeight, module.MaxHeight); cubeSphere.AddComponent(); cubeSphere.GetComponent().mesh = mesh; + if(ShaderBundle == null) ShaderBundle = Main.Instance.ModHelper.Assets.LoadBundle("assets/shader"); + if(PlanetShader == null) PlanetShader = ShaderBundle.LoadAsset("Assets/SphereTextureWrapper.shader"); + var cubeSphereMR = cubeSphere.AddComponent(); - cubeSphereMR.material = new Material(Shader.Find("Standard")); + cubeSphereMR.material = new Material(PlanetShader); cubeSphereMR.material.mainTexture = textureMap; var cubeSphereMC = cubeSphere.AddComponent(); cubeSphereMC.sharedMesh = mesh; - */ + + /* GameObject icosphere = new GameObject("Icosphere"); icosphere.transform.parent = go.transform; icosphere.transform.rotation = Quaternion.Euler(90, 0, 0); @@ -59,6 +66,7 @@ namespace NewHorizons.Body var cubeSphereMC = icosphere.AddComponent(); cubeSphereMC.sharedMesh = mesh; + */ } } } diff --git a/NewHorizons/General/GravityBuilder.cs b/NewHorizons/General/GravityBuilder.cs index 1aa9f92a..d00a5039 100644 --- a/NewHorizons/General/GravityBuilder.cs +++ b/NewHorizons/General/GravityBuilder.cs @@ -25,7 +25,7 @@ namespace NewHorizons.General GravityVolume GV = gravityGO.AddComponent(); GV.SetValue("_cutoffAcceleration", 0.1f); - GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField("inverseSquared").GetValue(GV)); + GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField("linear").GetValue(GV)); GV.SetValue("_alignmentRadius", 0.75f * upperSurface); GV.SetValue("_upperSurfaceRadius", lowerSurface); GV.SetValue("_lowerSurfaceRadius", 0); diff --git a/NewHorizons/General/SpawnpointBuilder.cs b/NewHorizons/General/SpawnpointBuilder.cs index 03500a1f..e462586a 100644 --- a/NewHorizons/General/SpawnpointBuilder.cs +++ b/NewHorizons/General/SpawnpointBuilder.cs @@ -20,6 +20,9 @@ namespace NewHorizons.General spawnGO.transform.localPosition = module.PlayerSpawnPoint; + // Move it up a bit more + spawnGO.transform.position = spawnGO.transform.position + spawnGO.transform.TransformDirection(Vector3.up) * 1f; + playerSpawn = spawnGO.AddComponent(); GameObject.FindObjectOfType().SetInitialSpawnPoint(playerSpawn); } diff --git a/NewHorizons/assets/shader b/NewHorizons/assets/shader new file mode 100644 index 00000000..2340d65c Binary files /dev/null and b/NewHorizons/assets/shader differ diff --git a/NewHorizons/assets/shader.manifest b/NewHorizons/assets/shader.manifest new file mode 100644 index 00000000..b5c4697c --- /dev/null +++ b/NewHorizons/assets/shader.manifest @@ -0,0 +1,16 @@ +ManifestFileVersion: 0 +CRC: 3655445632 +Hashes: + AssetFileHash: + serializedVersion: 2 + Hash: 160438a2f12bb2f4bd67ddfa0e6f2f3f + TypeTreeHash: + serializedVersion: 2 + Hash: 6370d3f9de9eca57f523bce048404a46 +HashAppended: 0 +ClassTypes: +- Class: 48 + Script: {instanceID: 0} +Assets: +- Assets/SphereTextureWrapper.shader +Dependencies: []