Question

I am making a 3D space game in Stage3D and would like a field of stars drawn behind ALL other objects. I think the problem I'm encountering is that the distances involved are very high. If I have the stars genuinely much farther than other objects I have to scale them to such a degree that they do not render correctly - above a certain size the faces seem to flicker. This also happens on my planet meshes, when scaled to their necessary sizes (12000-100000 units across). I am rendering the stars on flat plane textures, pointed to face the camera. So long as they are not scaled up too much, they render fine, although obviously in front of other objects that are further away. I have tried all manner of depthTestModes (Context3DCompareMode.LESS, Context3DCompareMode.GREATER and all the others) combined with including and excluding the mesh in the z-buffer, to get the stars to render only if NO other pixels are present where the star would appear, without luck. Is anyone aware of how I could achieve this - or, even better, know why, above a certain size meshes do not render properly? Is there an arbitrary upper limit that I'm not aware of?

Was it helpful?

Solution

I don't know Stage3D, and I'm talking in OpenGL language here, but the usual way to draw a background/skybox is to draw the background close up, not far, draw the background first, and either disable depth buffer writing while the background is being drawn (if it does not require depth buffering itself) or clear the depth buffer after the background is drawn and before the regular scene is.

Your flickering of planets may be due to lack of depth buffer resolution; if this is so, you must choose between

  1. drawing the objects closer to the camera,
  2. moving the camera frustum near plane farther out or far plane closer (this will increase depth buffer resolution across the entire scene), or
  3. rendering the scene multiple times at mutually exclusive depth ranges (this is called depth peeling).

OTHER TIPS

You should use starling. It can work

http://www.adobe.com/devnet/flashplayer/articles/away3d-starling-interoperation.html http://www.flare3d.com/blog/2012/07/24/flare3d-2-5-starling-integration/

You have to look at how projection and vertex shader output is done. The vertex shader output has four components: x,y,z,w. From that, pixel coordinates are computed:

x' = x/w

y' = y/w

z' = z/w

z' is what ends up in the z buffer. So by simply putting z = w*value at the end of your vertex shader you can output any constant value. Just put value = .999 and there you are! Your regular depth less test will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top