[SOLVED] How to make a render pass to skip render specific meshInstances(drawCalls)?

I want to write a custom render pass like planar reflection. As the PlanarRenderer says:

Objects that use the reflected texture cannot be in the layers the reflection camera renders.

My render pass needs to skip render those meshInstances used reflection texture.
Those meshInstances will have meshInstance.reflection = false flag.

I found a suitable place to do this is hack the ForwardRenderer#renderForwardInternal

renderForwardInternal(camera, preparedCalls, sortedLights, pass, drawCallback, flipFaces) {
// ...
-  drawCallback?.(drawCall, i);
+  const result = drawCallback?.(drawCall, i);
+  if (result === false) return;
// ...
}

and pass the onDrawCall callback

layer.onDrawCall = (meshInstance) => {
  if (meshInstance.reflection === false);
    return false;
}

Is this a good way to skip render meshInstance in PlayCanvas ?

Calling @mvaligursky

You should see how this is done in the example using the planar renderer here: PlayCanvas Examples

Objects you do not want reflected are in a new layer you create (called excludedLayer in the example) and this layer is not added to the camera rendering the reflection.

You mean separate meshes into different layers, main camera can see everything, reflection camera can not see the meshInstances with meshInstance.reflection = false flag ?

Does it work with the legacy model component ? I am still using it…

Yes, separate meshes into different layers and set up cameras as you mentioned, both Render and Model component support this.

1 Like

Does it work with the legacy model component ? I am still using it…

I mean, skip some meshInstances in model component. I notice ModelComponent has layers, it seems I can only skip all meshInstances in model component, not some meshInstances ?

Correct, layer affects all mesh instances of a model component, not just some.

You could probably use

and set MeshInstance.visible to false for the reflection camera, and to true for the main camera to do what you need here.

1 Like