top of page
  • Writer's pictureDan

Polygon Planet: Post 9 - Hiding stars!

Updated: Feb 27, 2023

In the last post i detailed how I made a custom MoonShader ShaderGraph that would render the unlit areas of the moon as transparent so that the SkyBox would show through.

This was to simulate the effect in real-life where the refracted blue light of the atmosphere overpowers the low intensity light reflected from those areas of the moon that are in shadow.

It works well but suffers from the problem that any item beyond the moon will also show through the transparent area just like the skybox does. At the moment there is nothing beyond the moon except the Sun and the Stars and I don't anticipate this to change. The Sun light is so intense that I've not noticed any issue so far.

The twinkling stars orbiting the terrain much further away than the moon show up when they are behind the transparent areas of the moon and this is not true to life.

So after messing with camera stacking and all sorts of other ideas i have resorted to creating my own custom StarShader ShaderGraph to resolve this problem.

Each star is a particle in a ParticleSystem. The ParticleSystem allows you to specify a material that it's renderer component should use to render the particles so it behaves pretty similar to any other GameObject in this respect.

So the strategy I have taken was to create a ShaderGraph that takes the Moon's position, Moon's radius and MainCamera position as inputs. The Position node provides the vertex position of the particle (star) being rendered and thus I can calculate the relative offset of the star from the camera and of the moon from the camera. I take the normal (unit vector) of the CameraToStar vector and multiply by the length of the CameraToMoon vector to get a point where the star would appear if it was orbiting at the same radius from the player as the moon is. I then deduct the distance from the moon's centre to this point to determine if it is within the radius of the moon and therefore should be occluded.

This works nicely and hopefully is clear in the linked video.

1 view0 comments

Recent Posts

See All
bottom of page