I am working on a prototype app which would benefit from a simple shadow solution. A 2d decal-style shadow projected under objects. (Rather than true shadow map shadows)
Is there a SceneKit friendly solution?
I am working on a prototype app which would benefit from a simple shadow solution. A 2d decal-style shadow projected under objects. (Rather than true shadow map shadows)
Is there a SceneKit friendly solution?
Yes, but hard to find in the documentation.
Set the SCNLight.shadowMode to Modulated.
Yes, but hard to find in the documentation.
Set the SCNLight.shadowMode to Modulated.
Thank you! That's exactly what I needed.
Got this working.
WARNING - Make sure your shadow texture does not have alpha round the edges. This cost me some time. 😠
let lightNode = SCNNode()
let light = SCNLight()
light.type = SCNLightTypeDirectional
light.shadowMode = .Modulated
light.castsShadow = false
light.categoryBitMask = 0x2 //use this to restrict which objects receive the shadow
light.orthographicScale = 10;
if let gobo = light.gobo
{
gobo.contents = UIImage(named: "shadowSilhouette")
gobo.intensity = 0.5
}
light.zFar = 100;
light.zNear = 1.0;
light.shadowColor = UIColor.blackColor()
lightNode.position = SCNVector3Make(0 , 0.0 , 0.0);
lightNode.eulerAngles = SCNVector3(Scalar.halfPi, 0 , 0) //point the shadow downwards
lightNode.light = light
self._node.addChildNode(lightNode)