ios - 软阴影,SceneKit 中的阴影模糊

标签 ios scenekit

我添加一个节点并尝试使用 SceneKit 设置阴影模糊

这是我的灯光配置,我确实尝试设置了 shadowRadius

light = [SCNLight light];
light.type = SCNLightTypeDirectional;
light.castsShadow = true;
light.shadowMode = SCNShadowModeForward;
light.shadowRadius = 5;
light.shadowMapSize=CGSizeMake(4000, 4000);
light.orthographicScale=25;
light.zNear=1;
light.zFar=1000;

但结果并不比我未设置 shadowRadius 时更柔和 在这里: enter image description here

我确实尝试添加样本数

light = [SCNLight light];
light.type = SCNLightTypeDirectional;
light.castsShadow = true;
light.shadowMode = SCNShadowModeForward;
light.shadowRadius = 5;
// add samplecount
light.shadowSampleCount = 5;
light.shadowMapSize=CGSizeMake(4000, 4000);
light.orthographicScale=25;
light.zNear=1;
light.zFar=1000;

结果如下 enter image description here

阴影看起来很柔和,但这个阴影从节点的底部开始(z 坐标为 0)。我花了很多时间只在节点的边缘设置软阴影,而不是从底部设置。但没有结果。

添加两个节点交叉时也会出现此问题(不仅是节点和几何体作为SCNFloor)

我的问题是如何使用方向光获得阴影模糊(软阴影)。

如有任何帮助,我们将不胜感激!

最佳答案

swift 4/Xcode 9.2

我用这些设置得到了很好的结果:

light2.castsShadow = true
light2.automaticallyAdjustsShadowProjection = true
light2.maximumShadowDistance = 20.0
light2.orthographicScale = 1

light2.shadowMapSize = CGSize(width: 2048, height: 2048)
light2.shadowMode = .forward
light2.shadowSampleCount = 128
light2.shadowRadius = 3
light2.shadowBias  = 32

shadowRadius 增加到 12 对我的模型有很大帮助,但随后我需要增加 shadowSampleCountshadowBias 以避免出现伪影。

关于ios - 软阴影,SceneKit 中的阴影模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44568165/

相关文章:

swift - 在哪些情况下 ARSCNView.raycastQuery 返回 nil?

ios - SceneKit——在 SCNNode 面对的方向上施加力

ios - iOS 中设置 CAGradient UIButton 的选中状态

ios - 无法访问 UICollectionViewCell 中的 UITextField

iOS 开发 : Get private IP and port from NSReadStream

objective-c - 使用 SceneKit 渲染一个 CVOpenGLTextureRef

swift - 如何使用 Swift 处理 Scenekit 中的碰撞检测?

ios - swift 3 : URLSession/URLRequest Not Working

ios - 如何在iOS8中将通知类型从横幅更改为警报?

swift - SceneKit Swift 2.0 碰撞检测(SCNPhysicsContactDelegate)