iOS SceneKit Neon Glow

2019-01-15 09:02发布

问题:

Have been looking at lighting on Scenekit, and while I can now apply a lighting node to light something I'm looking for a way to light from within an object.

As an example imagine a neon glow, or a lightbulb that casts light on other objects.

Any ideas how to achieve this?

Many thanks.

回答1:

As @DavidRönnqvist hints in comments, there are multiple ways to make an object appear to glow. You can do these together or individually — you'll probably need to tweak how you combine them to get the effect you want.

  1. For an object that emits light, you probably don't want shading from other light sources in the scene. Work with the emission channel of your material to give the object a color or texture that overrides shading from other light sources. (If you use a texture, the brighter parts will appear to glow, as seen in the example from the aforelinked documentation.)

  2. You might want other elements in your scene to be lit by the glowing object. The emission material property just keeps the object from being darkened by lighting/shading, it doesn't make it a light source. To get a light source, you'll need to add at least one SCNLight to the node tree containing your object.

    Depending on your scene, you might be able to get away with just one light source; e.g. if the object is a light bulb, you can place a light at its center and be done with it. (Well, you might also need to play with the category bit masks of the node and the light to make sure the light shines out through the light bulb instead of being occluded by it.) If you have a large, complicated neon sign, you might need to create multiple light sources — otherwise, the lighting on objects near the sign will betray that it's a single point light. (If there isn't anything close to the sign being lit by it, a single point light might be good enough.)

  3. If you're looking to have a glowing halo around the light source, things get a bit harder. That's volumetric lighting, and it's not something that SceneKit can do for you out of the box. But there are a few ways you might fake it:

    • For a point light like a light bulb, a 2D billboard with a glowy texture may suffice. (See @MatthewBaker's comment.)
    • For a larger light like a neon sign, you could try several billboards placed along its length. A good way to implement that might be with SCNParticleSystem, since that can spawn particles all along the surface of a geometry.
    • Another good option for lights with complex shapes might be shader modifiers. A GLSL shader might simulate volumetric lighting by varying alpha based on the angle between the view and surface normal vectors.
    • If the glow only needs to appear on a surface very near the light — e.g. the solid sign right behind a neon light tube — you can fake it by baking the glow into a texture and using that texture on said surface. (Again, emission to the rescue.)
    • Attach Core Image filters to the node containing the light (or a duplicate of its geometry) so you can brighten, expand, and blur the rendered image.
    • Use techniques to do multipass rendering with some fancy GLSL tricks to create the halo, as mentioned in @Moustach's answer.


回答2:

EDIT: woops, I may have misunderstod the question... Rickster's answer is more adapted to your needs.

Glowy 3D is my domain!

There are a few ways you can make an object glow in Scenekit.

The most straightforward way is to set it up in GLSL using SCNTechnique. You will need multiple passes, to render the illumination then blur it on succesively X and Y (faster than both at once). There is a great article about it on GPU Gems. However this one is quite heavy if you overuse it, and I'm not quite sure if you can target the illumination only in SCNTechnique.

The second way is using CI filters. Simply add a Gaussian Blur and composite it on top. You may need additional effects to select/boost the glowing elements. If you're looking for a glow around the object this question might help you as well.

Third way is to fake the glow using billboards. Make a stencil in photoshop or your 3D software, put it on a plane that always faces the camera. Change its blending mode to Screen and you have a very innexpensive glow!

Finally, for your light shining effect, you might want to look into godrays. They're pretty easy to set up using GLSL as well, so SCNTechnique should do the trick. Here is an article about it.