Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

swift - iOS SceneKit Neon Glow

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...