4

I have a node (just a simple node with an SCNCapsule geometry, just to be more specific) and I want it to glow just like a Star Wars lightsaber:

image

I have tried to add a child node with same geometry, just a little bigger, opacity of 0.5 and different colour, but it's not exactly what I want. Is there another way to do it?

vacawama
  • 150,663
  • 30
  • 266
  • 294
Alec Firtulescu
  • 543
  • 6
  • 18

2 Answers2

6

I've found using cifilters in scenekit mostly useless. Unless the scene is extremely simple the performance will be garbage.

If you plan to be animating this, the easiest way is make it white. Id use two animated particle emitters. One red, additive, smoke texture just to give it some red/white coverage and let the particles live 15-30 seconds in local space. A second one spitting out smaller ones constantly to give it a pulsating effect, but keeping the life span short.

If you look at the apple ship demo, the reactor particle system of the engine is like a very short light saber. You just want to make it longer and and different colors. By using a smoke/cloud system to give you coverage you don't need as many particles from the main emitter. Once it's glowing, moving it around is easy because all the particles are in local space. You just move the node. While this isn't the most performance friendly way to do it, it is the best looking way. You can have particle sparks, particles emitted during movement to give a trail effect, and the pulsing, alive look will be better then any filter/emission/reflection/shader you can whip up. As with the reactor system in the apple demo it looks great. I'd be surprised if you could make something that looks as good in a 3d scene with lights/emission/shaders.

Sig Fawn
  • 186
  • 1
  • 3
1

Glowing is a pretty hard thing to achieve in 3D. We talked about this on Stackoverflow before and a few good things came out.

I think that for your specific use case, duplicating the node is a good start. Make it the color you want, then add a Core Image Filter to the duplicate node. The filter should probably be CIGaussian Blur (documentation). That way, you'll have a glow around the node itself.

A quick tip, to avoid having the glow on top of the white part of the lightsaber, change the material of the glow node to have the cullMode set to back. You'll only see the inside of the polygons, that are behind the white part.

Disclaimer: this might not compile, but the overall idea is there . My Swift isn't great so feel free to correct me.

let filter = CIFilter(name: "CIGaussianBlur")
filter.setValue(0.5, forKey: kCIInputRadiusKey)
glowNode.filters = [filter]
Community
  • 1
  • 1
Moustach
  • 2,904
  • 1
  • 13
  • 23
  • Kinda confused how to use those filters. Can you give me a little example in how to use it? – Alec Firtulescu Jul 05 '15 at 14:50
  • Hey, I added a code sample. Tell me if it works, or if any error arises! – Moustach Jul 05 '15 at 15:40
  • Umm, kinda weird, I get a big back box instead of my node. However, if I replace 0.5 value with a value smaller than 0.1, it works, I get my node, but with no transformation. Also, if I just append 'filter' to filters (`glowNode.filters.append(filter)`), I get no black box, but nothing happen, not even if I replace 0.5 with greater/smaller values – Alec Firtulescu Jul 05 '15 at 15:54
  • Interesting... Would you mind creating a Swift Playground that recreates the problem? That way i can experiment with it – Moustach Jul 05 '15 at 16:01
  • I can do that with no problem, but I can also send you the file where class is written. How do you like it? – Alec Firtulescu Jul 05 '15 at 16:32
  • The smallest code you can have to reproduce the problem the easiest it'll be to debug! – Moustach Jul 05 '15 at 18:57
  • This is the [code](https://github.com/AlecFirtulescu/SceneKitTests/tree/master/SceneKitTests). It's just Bullet. swift file – Alec Firtulescu Jul 06 '15 at 06:16