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:
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?
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.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With