View Full Version : How to approach rendering lots of lights on a model using point sprites
Droozle
01-04-2007, 05:57 AM
Hi all,
I could use some help with a project I am working on and need your input. I am creating a fairground ride simulation and succeeded in creating the 3D model, importing, drawing and animating it, using Microsoft XNA Game Studio. I have been working as a programmer for 15 years but 3D is relatively new for me.
Anyway, I want this fairground ride to have hundreds, maybe thousands of light bulbs so it will look spectacular at night. Using real light sources is out of the question, so I would like to use point sprites for them. But how can I best generate the list of vertices from the animated model? Is there a way to define the location of each bulb in the model and extract it so I can send it as a vertex buffer to the point sprite engine? If you have experience with this, let me know how you would approach this problem. Any help is greatly appreciated.
dave_
01-04-2007, 06:58 AM
But how can I best generate the list of vertices from the animated model?
You can't, you need to place the light bulbs yourself, then process the positions when you load/display the animated model.
Once you have a position you then need to create a quad for each, look up XNA billboarding, XNA particles systems or similar and you should see how to do this.
Droozle
01-04-2007, 07:08 AM
Thanks for your reply, Dave. I did not assume I could magically get the bulb positions from the model, ofcourse, so this is the way I am thinking it should be done now:
1. add dummy vertices on the model, 1 vertex for each bulb, and give each dummy a proper name (e.g. "bulb")
2. load the model into XNA using the content manager
3. draw the model using the standard "foreach mesh in model" approach
4. if the name of the mesh equals "bulb", skip drawing but add its position to a vertex buffer
5. after the model has been drawn, the vertex buffer contains the position of all the bulbs in world coordinates
6. define the texture to use for the light bulbs, make the necessary DirectX calls to setup point sprite rendering and send the vertex buffer to the point sprite renderer
7. yay, done!
Would that be a practical approach? I already noticed the name of each mesh in my model is empty, even though I gave each mesh a proper name in the 3D modeller application and the names show up in the DirectX Viewer utility, but that is another problem I have to solve.
Any comments would be most welcome! Thanks in advance.
dave_
01-04-2007, 08:37 AM
You could do, I don't know how XNA works exactly, but I guess you probably want to use something like a bone, so that when your model animates the lights animate with it. You'll have to get the position of the bone every frame, but it should animate correctly
TheNut
01-04-2007, 08:42 PM
Some performance considerations for you:
1) You should only use the point sprites for generating a corona effect, not to simulate lighting. Use a lightmap on the meshes to simulate light.
2) Corona's have a simple property. The closer you are, the smaller the effect. The further away you are, the larger the effect (up until a certain distance). This is practically a freebee with vertex shaders as you can easily adjust the size of the quad based on the distance from the view matrix.
3) Store all your points sprites in a single buffer and do only one render call. Avoid any comparisons at run-time.
4) There's no need to glue your point sprites to the model. Treat them as a separate entity that is enabled only at night. Once you set them up, get them to share the same transformation matrix as their parent.
Droozle
01-05-2007, 02:22 AM
Thank you for your ideas and comments!
ad 1: I indeed attempt to create a "corona" effect using the point sprites. I hope I do not need lightmaps for the model, a few directional point lights should be able to light the scene appropriately, together with shadow maps (or even stencil shadows).
ad 2: thanks for pointing out that the corona becomes larger when further away. I would have thought it to be the other way around. I will experiment with it to get the desired effect.
ad 3: that was my intention. It is the way point sprites work. My idea of dynamically generating the buffer containing the world coordinates of each bulb as a vertex, however, might not perform well and may even be impossible on Xbox360 (I read that somewhere. The Xbox360 is not one of my target platforms, though).
ad 4: the problem with my model is that it is a complex hierarchical system of meshes. There is a central core that can rotate, lift and tilt and there are 6 arms with gondolas. I animate the model on-the-fly by calculating the transformation matrices using constraint solvers. To treat the point sprites as a separate entity I would have to somehow duplicate the bone structure and I don't know if that would yield better results compared to glueing the bulb vertices on the actual model of the ride.
I will experiment a bit more and keep you up to date on the progress.
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.