5
votes

I made transparent object with scenekit and linked with arkit. I made a shadow with lightning material but can't see the shadow look through the transparent object. I made a plane and placed the object on it. And give the light to a transparent object. the shadow appears behind the object but can not see through the object.

enter image description here

Here's code that making the shadow.

          let light = SCNLight()
          light.type = .directional
          light.castsShadow = true
          light.shadowRadius = 200
          light.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
          light.shadowMode = .deferred
          let constraint = SCNLookAtConstraint(target: model)
          lightNode = SCNNode()
          lightNode!.light = light
          lightNode!.position = SCNVector3(model.position.x + 10, model.position.y + 30, model.position.z+30)
          lightNode!.eulerAngles = SCNVector3(45.0, 0, 0)
          lightNode!.constraints = [constraint]
          sceneView.scene.rootNode.addChildNode(lightNode!)

And the below code is for making a floor under the bottle.

 let floor = SCNFloor()
 floor.reflectivity = 0
 let material = SCNMaterial()
 material.diffuse.contents = UIColor.white
 material.colorBufferWriteMask = SCNColorMask(rawValue:0)
 floor.materials = [material]
 self.floorNode = SCNNode(geometry: floor)
 self.floorNode!.position = SCNVector3(x, y, z)
 self.sceneView.scene.rootNode.addChildNode(self.floorNode!)

I think it can be solved with simple property but I can't figure out.

How can I solve the problem?

1
Is there an “Alpha” setting in the node in question (that you’d like to make transparent)? If so, change it to “0.5” to be 50% transparent.Voltaire's Ghost
Of course it has got transparent alpha value(maybe 0.2). But although it has got alpha the shadow can't be seen through the transparent object.Fury

1 Answers

3
votes

A known issue with deferred shading is that it doesn’t work with transparency so you may have to remove that line and use the default forward shading again. That said, the “simple property” you are looking for is the .renderingOrder property on the SCNNode. Set it to 99 for example. Normally the rendering order doesn’t matter because the z buffer is used to determine what pixel is in front of others. For the shadow to show up through the transparant part of the object you need to make sure the object is rendered last.

enter image description here

On a different note, assuming you used some of the material settings I posted on your other question, try setting the shininess value to something like 0.4.

Note that this will still create a shadow as if the object was not transparent at all, so it won’t create a darker shadow for the label and cap. For additional realism you could opt to fake the shadow entirely, as in using a texture for the shadow and drop that on a plane which you rotate and skew as needed. For even more realism, you could fake the caustics that way too.

You may also want to add a reflection map to the reflective property of the material. Almost the same as texture map but in gray scale, where the label and cap are dark gray (not very reflective) and a lighter gray for the glass portion (else it will look like the label is on the inside of the glass). Last tip: use a Shell modifier (that’s what it’s called in 3Ds max anyway) to give the glass model some thickness.