Search Unity

Rendering thousands of 3D stars in permanent positions

Discussion in 'General Graphics' started by jackmott, Nov 6, 2015.

  1. jackmott

    jackmott

    Joined:
    Jan 5, 2014
    Posts:
    167
    I want to render a starfield, that you can actually fly though. Where the stars actually stay in their positions, so not just a random particle effect.

    I want there to be a few thousand stars.

    I've tried a couple of approaches:

    1. A bunch of game objects that are quads with a billboard texture. This can work, but makes a ton of draw calls. I've yet to be able to get dynamic batching to work with this and not screw something else up.

    2. A particle system, that is static, where I set the particles by hand. This works great in the editor. I can make particles arbitrary colors, it batches up all the draws. But when I build and run, all the particles are culled, likely because the particlesystem itself is not always in front of the camera. Setting the particle system as a child of the camera to keep it in front works ok, *but* I also make use of RenderToCubeMap, and when I use this approach, it only renders the front face!

    Getting kind of frustrating. Anyone else done this, are there other approaches I could try that aren't so...delicate?
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I briefly talk about this in my Unite2015 talk:



    But basically what you want to do is do the billboarding in the shader, essentially drawing one mesh with thousands of stars at once.. How you want to distribute those stars is up to you; you could prebake them into position and have them store an offset to their pivot in the vertex data, or just model them all at 0,0,0 and store a direction/distance to move them from 0 in the vertices..