Tuesday, December 13, 2016

unity - How can I model a star?


I'm trying to model a star in Unity, and it, sort of works, but it's not ideal. Currently, I'm using a large sphere with a self-illuminating material containing a star texture applied to it's surface, and a spotlight to create the effect of starlight, like this:


enter image description here


While it works, it doesn't look the greatest. I'm looking for an effect more along the lines of how Kerbal Space Program models a star:


enter image description here


How can I achieve this effect?



Answer




  • Use an animated texture.* There are some good ones in the store for < $10.


  • Add a Halo. You can use the particle system, or just a transparent glow texture on a billboard in front of the sun with a script to re-position the texture when the camera moves. This hides the aliased edges of the sphere model, allowing you to use a lower poly model, and looks nice.

  • Rotate the sun, slowly.

  • Use particle system for eruptions.

  • Use a custom shader to make the edges match well with the halo(multiply normal with camera vector to find edges).


The animated gif shows a static texture first, followed by a number of additions, in order:



  1. Animated Texture

  2. Brighten the edges of the sphere based on normals

  3. Add camera-facing transparent billboard with white/yellow halo


  4. Particles, moving from the center to the outside, then fading

  5. Add 2 transparent "ray" billboards, facing the camera and rotating along the camera axis in opposite directions.


Building a Sun


With the animated texture, be sure to use mipmaps, or it will look horrible at some distances. Slow framerates in the texture (10 fps) are fine when looking at a sun from far away, but when you get close, you may also want to use a higher framerate. If you don't have a high framerate texture or can't waste the video memory for one, you can use a custom shader to interpolate every other pixel based on the previous and next image.


By changing use of Hue/Saturation/Value inside the shader, you can get results like these, without ever having to modify the texture:


enter image description here enter image description here enter image description here enter image description here [enter image description here enter image description here


I started with a cheap model from the store so I didn't have to do the animated texture. On the other hand it means I can't share the current prefab, because the texture is purchased.




*Alternatively, you can look into mapping 2D noise on a sphere and use 3D noise for the time dimension, or use 4D noise if you don't want to do the mapping and can spare the performance.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...