Shadow on a transparent floor / plane in a scene

trying to figure out how I can make a shadow on an invisible plane, so the background of my sceneView shows.

THREE.js has a ShadowMaterial that does just that - only the shadow is displayed.

Modern thinking is to create a custom metal shader that looks simple, but I'm not sure how to get off the floor to show everything except the shadow.

Here is an example of a shadow trap: https://knowledge.autodesk.com/search-result/caas/sfdcarticles/sfdcarticles/Maya-2015-Shadow-Catching-with-Use-Background-material.html

+5
source share
1 answer

So check out this sample project on Github:

https://github.com/carolight/Metal-Shadow-Map/blob/master/Shadows/Shader.metal#L67

This link refers to a shader that performs shadow map testing. In principle, it normalizes the position of the Z fragment that is being visualized and compares it with the Z-map of the shadow map. If it is smaller than shadow-Z, the pixel is fully lit (line 67), otherwise it is slightly colored (line 69).

Instead, you should write (0,0,0, shadow_opacity) for line 69 and (0,0,0,0) for line 67. This should emit transparent pixels. Set shadow_opacity as the uniform from [0.0..1.0].

The rest of the setup is shown as an example . Tilt the plane / camera to the desired setting, skip the cube / vase / all pattern in the main pass if you really do not want it in the scene (line 279 ). (However, pay attention to the shadow pass and save it there).

+4
source

All Articles