How to generate a spherical starfied texture?

For my Java 4k game entry I am in need of generating a starfield texture which which will be the texture for a sphere.

Due to the restrictive space requirement I am unable to include a pre-rendered spherical starfield (e.g. ones found on the net) and will have to generate it on the fly.

I have wracked my brain attempting to google for a “normal” texture to “spherical” texture convervion algorithm or a direct spherical starfield texture generation algortithm without any luck.

Does any one have any Ideas on how to implement this or knows of the correct search term i should use on google?

Hmm, it seems that texturing the star field sphere will not be an ideal solution due to the loss of resolution near the “poles” of the sphere.

This has lead me to think of another method however i am not sure if this will work or be fast enough…

My idea:

  1. generate random points in a cube.

  2. remove points which are not in a sphere which “just” fits inside this cube

  3. normalize vectors formed from the centre of the sphere to each point lets call these star vectors

  4. associate a star size and star intensity to each star vectors

  5. Now in the game when a ray hits the star field sphere a normalized vector from the point of intersection to the centre of the sphere is “added” to each of the star vectors and the resultant vector’s distance and associated star vector are recored.

  6. if this distance is smaller than the associated star vector’s star’size then the ray should show the star.

  7. I can probably interpolate the ray intensity using the distance and the star’s size and the star’s intensity.

I think it should work, however My concern is that it will be far too slow for a real time ray tracer… what are peoples thoughts?

Just use a “skybox”.

I might have to use a sky box, however I have avoided using it as it would contribute a signifcant overhead as it would need a new geometric primitive (i.e. a cube) and the associated intersection code and texture generation.

The more i am thinking, the more i believe i might have to just have a fake flat star field generated by points which will be rotated and translated on a 2d background plane. That or i might have to remove the star field altogther depending on that 4k limit :frowning: