I have a Geometry Node that pictures a human body. The material for the object is transparent
let node = newScene.rootNode.childNode(withName: "man_mesh", recursively: true)
let nodeMaterial = node?.geometry?.firstMaterial
nodeMaterial?.emission.contents = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0)
nodeMaterial?.transparencyMode = .rgbZero
nodeMaterial?.transparent.contents = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
The effect I'm trying to get is for the object to be fully transparent in areas facing the camera, but become more opaque as the polygons face sideways... this creates a sort of a shiny blue rim. something like this:
Any idea how to create this effect?
Thanks
EDIT: Another interesting point: it appears the SceneKit does support the fresnel effect. The effect affects the Reflectance map - as should be, however, once you apply transparency to your object, it also affects the reflectance (full transparency will make reflectance disappear as well)- I believe this is a conceptual mistake by Apple - a material can be transparent and still reflect light!
I've done some research and found an answer. To achieve this effect, you can use following code.
func ghostEffect(scene: SCNScene) {
let sphere = SCNSphere(radius: 3)
let material = SCNMaterial()
material.diffuse.contents = UIColor.black
material.reflective.contents = UIColor(red: 0, green: 0.764, blue: 1, alpha: 1)
material.reflective.intensity = 3
material.transparent.contents = UIColor.black.withAlphaComponent(0.3)
material.transparencyMode = .default
material.fresnelExponent = 4
sphere.materials = [material]
let node = SCNNode(geometry: sphere)
scene.rootNode.addChildNode(node)
}
Explanation from: SCNMaterial.
transparent - An object that determines the opacity of each point in a material
reflective - An object that defines the reflected color for each point on a surface
fresnselExponent - A factor affecting the material’s reflectivity
This approach can be applied to any 3D object.
P.S. Hope it will be useful.
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