I created that white rectangle using Babylon GUI. What I would like to achieve is to take a screenshot of the viewport using CreateScreenshotUsingRenderTarget. Basically I want to take a screenshot of the parts which are inside that GUI element.
Not sure if possible at all. It would be nice if I could avoid some manual math calculations for deciding what to capture in the scene.
You can use the stencil buffer for this. However, you won’t be able to use a GUI element, only meshes.
Basically it works like this:
draw the shape you want to cut your meshes with by setting the stencil value to 1. You can use any mesh(es) you want, so the shape can be anything you want
draw all the meshes of your scene by configuring the stencil buffer to only draw a mesh when the stencil value is 1
Set disableStencil to true to see the setup with the cutting plane.
For step 1, you should draw the cutting shapes with disableDepthWrite = true and disableColorWrite = true so that it does not tamper with the scene.
Note that CreateScreenshotUsingRenderTarget does not work, the stencil is not taken into account (or the onBeforeDrawObservable observers, I don’t know). @sebavan should know what’s going on.
Yes, that border radius is not big of a issue for me. The issue is that I am not sure how to use camera viewport. Whichever value I try to use, the model is not in the camera view.
This PG does not work with CreateScreenshotUsingRenderTarget because I have used some observers from the scene to enable / disable the test.
To make it work with CreateScreenshotUsingRenderTarget, I think you need to enable the test before drawing the first mesh and disable it after drawing the last mesh:
I tried several things, at the end I figured out proper math for camera.viewport, and everything works fine. I am able to take snapshots as intended. Thank you for your answers. You were helpful as always. Appreciated