3

I have used shader modifiers for Plane but its not working. Can anyone suggest me how to solve it?

let myShaderfragment = "#pragma transparent;\n" + "_output.color.a = 0.0;"
let myShaderSurface = "#pragma transparent;\n" + "_surface.diffuse.a = 0.0;"
 material.shaderModifiers = [SCNShaderModifierEntryPoint.fragment : myShaderfragment, SCNShaderModifierEntryPoint.surface : myShaderSurface]
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
Santosh
  • 41
  • 4
  • 3
    Possible duplicate of [SceneKit: Is it possible to cast an shadow on an Transparent Object?](https://stackoverflow.com/questions/30975695/scenekit-is-it-possible-to-cast-an-shadow-on-an-transparent-object) – James P Aug 04 '17 at 12:00
  • Yes Very Simple solution is here. https://stackoverflow.com/questions/46661670/drop-a-shadow-of-3d-object-on-the-plane-surface-using-arkit-scenekit/51450918#51450918 – Akhzar Nazir Jul 20 '18 at 22:19

2 Answers2

11

The SceneKit: What's New session from WWDC 2017 explains how to do that.

  1. For the plane, use a material with constant as its lightingModel. It's the cheapest one.
  2. This material will have writesToDepthBuffer set to true and colorBufferWriteMask set to [] (empty option set). That way the plane will write in the depth buffer, but won't draw anything on screen.
  3. Set the light's shadowMode to deferred so that shadows are not applied when rendering the objects themselves, but as a final post-process.
mnuages
  • 13,049
  • 2
  • 23
  • 40
  • I have a similar problem, but I need to draw shadows on transparent floor, but also set SceneView.backgroundColor to clear. For some reason if I do this, then shadow is not visible. More info here: https://stackoverflow.com/questions/52654624/scenekit-shadow-on-a-transparent-scnfloor I would appreciate if anyone could help resolve this – Damian Dudycz Oct 05 '18 at 10:56
1

There's a dedicated lighting model now (SCNLightingModelShadowOnly) to only render shadows

Toyos
  • 4,024
  • 15
  • 16
  • I'm unable to get this to show any shadows on iOS 13.x, though it seems to work in the SceneKit editor in Xcode. Do you have some sample code that works on iOS? – LenK Jun 05 '20 at 22:37