- Home /
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!
Answer by skovacs1 · Nov 22, 2010 at 04:57 PM
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.
thanx, sounds good. i started to play around with the particle emitter, butt I'm not shure how many candles the iphone would run. I also thought about fil$$anonymous$$g a candle and then animate a texture. maybe this would be the fastest?
your baked candle sounds interesting but I never worked with lightmaps before.
As far as the particle emitters, it would depend on how you set them up, what the particles are, etc. There are some standard assets for things like fire, explosions, etc. Perhaps you might consider giving them a try. They shouldn't be too bad though. Fil$$anonymous$$g a candle sounds like a bad idea because trying to key out the alpha on live video is a pain and it doesn't usually composite beautifully into 3D space. A better approach would be to generate your candle video in another program and in there you can render it out with alpha as well.
Lightmaps are fun, easy and can make your life so much better because they are cheaper than real-time lighting and can look much better. Essentially a lightmap is a texture mapping your lighting and is applied on top of the appearance of your material to give the illusion of being lit. It is a representation of what your light is doing to your object, stored in a texture. Because it is a texture, it doesn't do anything fancy like real-time dynamic shadows, etc. and it doesn't really change. It's generally for lighting that doesn't move and doesn't interact with anything that does move.
i now tried the iphone with 15 candles and 15 particle emitter flames. works quite well. thanx! is there a goor tutorial about using animated lightmaps? i thought dynamic shadows doesn't work with iphone in the first place (is this correct english?)
Indeed, dynamic shadows do not work with iphone and are apparently a pro-only feature. Unity's Beast lightmapping can be done as directed here (http://unity3d.com/support/documentation/$$anonymous$$anual/Lightmapping.html). Lightmaps are generally treated as emissive and you can get something tunable by changing one of the built-in legacy lightmap shaders (Diffuse for example) to take in a Range(0,1) that you multiply the lightmap by. You would change this value in code and you have just animated your lightmap.
Your answer
Follow this Question
Related Questions
How many lights could affect at an object at the same time 1 Answer
Light not showing after iPhone build 1 Answer
How to turn on camera light (make a flashlight) on iPhone/iPad? 2 Answers
Unity iPhone - Do we get access to the iPhone's light sensor? 2 Answers
How to turn on camera light on iPhone? 0 Answers