Spheres with pixel shader?

Started by
5 comments, last by jollyjeffers 16 years, 9 months ago
Hello, Im wondering if any of you could help me with a little problem. I need to create a scene with lots of perfectly round spheres. Target platform is kind of old, so im thinking that polygon approach is out of the question. Could this be done with planes facing the camera and a pixel shader to make planes look like spheres? Could you maybe point me to direction where i can find an algorithm to map lit 3d sphere to 2d surface? And do you think this approach would be fast enough for some GeForce2 cards, when I need to render about 500 - 1000 spheres (taking about 20% of screen surface)? Thanks in advance.
Advertisement
Maybe look into 'imposters'. Basically you draw a complex object to a texture and use this cached texture to draw the object in the world. You therefore only need to update the imposter infrequently rather than drawing it every frame. Depending on your lighting setup, you might be able to reuse the same imposter for several spheres in the world.
It could be done, you could write a shader that used some parametric equation to draw and light a sphere (given only a quad).

Your best bet would be to draw a bunch of bump textures. A pre calculated normal map of a sphere. Draw a bunch of lit normal mapped quads all over the scene and *wahlah*.

The problem with this is if the spheres interesected they would simply over write each other. Unless you wrote the depth too.

Maybe you should use a hybrid system where spheres up close get drawn with geometry, and in the distance they are drawn with imposters.
Although since you mention a GF2, shaders won't be an option since it doesn't support anything other than some simple texture environment settings.
You can still do DOT3 texture mapping using the fixed function pipeline, though (if I remember correctly). Using that you can use the imposters approach.
Sorry, target platform is directx 8.1 compatible, so its comparable to GeForce 4 cards... things move so fast that it's hard to keep up with the card models :)

I'll look more closely to imposters and normal map approach and do some tests. Thank you very much for your time.
imposters are probably a good compromise here. The problem is that if quality is your primary concern you could still end up with resolution-dependent results. That is, if the texture mapped to the imposter is low resolution compared to the display it'll look blurry at best.

I doubt you'd get it for PS_1_4 or below, but ray-tracing would be perfectly feasible in later shader models and generate resolution-independent spheres. It's quite a cool trick, but you'll need some serious horsepower behind you [grin]

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement