iOS SceneKit Neon Glow
Asked Answered
B

2

9

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.

Baeyer answered 16/12, 2014 at 15:1 Comment(3)
Are you talking about having a material that is bright, even when there are no light sources, or are you talking about rendering a "halo" around an object that is bright?Oversell
Either would suit, but the effect I'm looking for would probably be a combination of both. If you imagine a similar effect to having a light mounted on a surface. When its switched on, it would be casting light onto other objects around it.Baeyer
In the past I'd used gimp for 2D images, increased the size of a bright element and blured. Effect like thisBaeyer
B
17

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.
Birecree answered 16/12, 2014 at 21:5 Comment(1)
Sounds like a couple of good options. I'll have a look at the emission settings and see what I can make work. I'll mark as answer once I've tested it and post my final result.Baeyer
A
5

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 inexpensive 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.

Astatic answered 16/12, 2014 at 21:15 Comment(3)
Heh, I'd meant to address filters and techniques in my initial answer, but I started to lose track of it after writing so much... figured that was a good place to stop. :)Birecree
BTW, you can indeed restrict an SCNTechnique rendering pass to specific nodes — see includeCategoryMask/excludeCategoryMask in the technique definition dictionary.Birecree
I was talking about restricting to a channel, not a node as a glow should only apply to the emission channel, not the color, reflections etc. But thanks for the heads up!Astatic

© 2022 - 2024 — McMap. All rights reserved.