how to simulate candle light on iphone

hi there!

i want to simulate a candle on iphone (no pro version) and I wonder if anybody just did this before. any hints?

thnx!

I cannot say that I have done this before nor am I sure that I have truly accounted for the nuances and restrictions of iphone development in this answer, but here is how I would approach the problem:

Dynamic candle:

  • The light of the candle is represented by a point light. If you want shadows that react to this light, then you're stuck with Deferred Rendering.
  • If you need a visual representation of the flame itself, you could do this with particles, a flare or an animated texture.
  • The color of the light would be something of your choosing (green, purple, blue, orange) as best suits your use case.
  • You will want to vary the intensity of the light. This can be done by lerping between some random values or more effectively by doing some texture lookups to some noise texture that can provide you with smooth and more tweakable transitions, etc.
  • If using a visual representation of the light, you may want them to coincide. With particles, using the number of particles, their size or something to that effect could be directly proportional to your light intensity. With some customized sprite, etc. for a GUITexture or Flare, you would share control parameters for these as you would for particles. With a fixed animation of some sort, then you would be best off making an animation clip for your light and setting it up to sync with the other animation(s).

Baked candle:

This is the same thing, but a lot simpler for the engine and you aren't restricted to a given render mode. Since your light doesn't move, you can create lightmaps for the the light (and it's shadows) and then animate the lightmap(s) in stead of the light. The visual representation stuff would be about the same. If you needed the animation(s) to sync, the animation of the lightmap should sync with that of the visual representations in the same way light intensity would above.

It should be noted that to do this would involve controlling the lightmapping, which means that you might not be able to leverage Unity's built-in lightmapping as you typically would, but may have to roll your own and possibly even leverage a legacy lightmap shader.