How to Get Shadows to Render in Realitykit When Loading Models Directly from Usdz Files Rather Than a Reality Composer File

Loading Entities from a file

Seems there's a bug when reading .reality file. Use .rcproject format instead. It works.

if let anchor = try? Entity.loadAnchor(named: "AR") {            
arView.scene.addAnchor(anchor)
print(anchor)
}

Sample Image

How to exclude model's shadows on itself?

Well, I find a simple way to achieve this but loss some material details.

Change the light model of material to SCNLightingModelConstant and exclude model from lighting calculation of your SCNLight.

1. set light model

SCNLightingModelConstant only consider ambient light to shading, so We need ambient lights to keep model visible.

model.geometry.materials.firstObject.lightingModelName = SCNLightingModelConstant;

2. set category bit mask of model and lights

model.categoryBitMask = 1;
directionalLight.categoryBitMask = ~1UL;

If results of bitwise AND of categoryBitMask is zero, node will not take consideration into light illumination, so there no self-shadows anymore. Shadows model casted will still remain in scene.



Related Topics



Leave a reply



Submit