Shadows ignore clipping planes

Hello everyone,

for one of our projects, we were facing the already documented issue #6261, Shadows ignore clipping planes. Our goal is to clip holes in photogrammetric models, replace them with our own models and do shadow analysis. We are using the latest Cesium version. I already took a deeper look into the source code, but so far I couldn‘t find a solution on my own. Do you have any hints, how to address this issue.

Thank you for your help.

Hey Richard,

How far did you get inspecting this in the source code? I wonder if it’s an order of operations issue. If the shadow code is running at a render pass before the clipping planes are applied (or if the shadow pass simply ignores the clipping planes).

Hello Omar,

thank you for your reply. An order of operations issue was also the first thing that came in my mind. But as far as I understood it looks quiet good. At first the primitives get updated, which goes all the way down to update the primitive/model shaders, including the clipping regions. Then the shadowmap castcommands get executed and after that the commands for globe and 3D-Tiles.
As the shadowmaps castcommands use the same shader programs, the clipping planes should be available here. Please correct me, if I am wrong.

Hey Omar,

after quite a long time I picked this topic up again lately and made some progress. I figured out that it is probably not an order of operations issue. So I tried to modify the castFragmentShader of the shadowmap for clippingplanes, similar to the clipping done in the model.js.
I could access the clippingPlaneCollection of the tilesets through the commands.

Using the modifyShaderForClippingPlanes function of model.js, I could make an first effort of clipping the shadow. But it completely depends on the position of the camera how the result ends up. This picture shows one of the better result.

Similar to the model.js function I use the gltf_clippingPlanesMatrix to transform the clippingplanes before clipping. I think I either need to use another transformation matrix or modify the getClippingFunction.js. But I kind of got stuck here and could need some advice.

function modifyShaderForClippingPlanes(
  castFragmentShader,
  clippingPlaneCollection,
  context
) {
  castFragmentShader = ShaderSource.replaceMain(castFragmentShader, "shadow_clip_main");
  castFragmentShader += getClippingFunction(clippingPlaneCollection, context) + "\n";
  castFragmentShader +=
    "uniform highp sampler2D gltf_clippingPlanes; \n" +
    "uniform mat4 gltf_clippingPlanesMatrix; \n" +
    "uniform vec4 gltf_clippingPlanesEdgeStyle; \n" +
    "void main() \n" +
    "{ \n" +
    "    shadow_clip_main(); \n" +
    getClipAndStyleCode(
      "gltf_clippingPlanes",
      "gltf_clippingPlanesMatrix",
      "gltf_clippingPlanesEdgeStyle"
    ) +
    "} \n";
  return castFragmentShader;
}