Dynamically generating a sphere texture

I am writing a space game that involves a ship flying around the Earth. I have placed the Earth inside another sphere which will act as a “star-dome”. I have managed to use a script to reverse the winding on the star-dome such that the texture is applied on the inside.

The stardome is black, and I wish to generate a simple texture for it based on data from a star catalog to accurately display stars for a given day and time. My idea is to just plot white dots, but I am struggling with what coordinates to use.

How can I plot spherical coordinates on a texture using a script? I have experimented with just creating a new texture and using a for-loop to split the texture into 4 colors (striped) which when applied makes the sphere look like a beachball, but am struggling with more refined and accurate point coordinates.

The sphere model would have a UV mapping that makes any point on the sphere map to a point on the texture. If stripes come out like a beach ball, it’s similar to the Mercator projection used for mapping the Earth. So if the star map can give you locations as latitude and longitude that will map easily to coordinates on the texture. Though you’ll also want to adjust the size of the stars so you don’t get tiny stars near the poles and big stars near the equator.

You need a function that converts a coordinate on the surface of the sphere to a coordinate on a flat rectangle.

Generally, spherical coordinates are written using angles. Every point on the surface can be written using the angle around one axis, and another angle around a different axis. This could be written as (Θ, Φ), where Θ is the angle around the x-axis, and Φ is the angle around the y-axis.

I’m sure you’re familiar with normal cartesian (x, y) coordinates.

If you’re setting UV coordinates on the mesh yourself, maybe you can just take your angles and divide by 2π to convert to UV coordinates, and multiply by 2π to go back to angles.

If something else is assigning UV coordinates… I’m sure there’s a “standard” way of assigning a flat UV texture to a sphere, but I have no idea what that might be. Maybe someone else can chime in and explain how UVs are normally wrapped around a sphere?

There must be something like these two functions.

public Vector2 GetUvFromSpherical(Vector2 sphericalCoordinates) { ... }
public Vector2 GetSphericalFromUv(Vector2 cartesianCoordinates) { .. }