I am looking to render a post-process in low resolution on top of a full resolution scene.
I tried using the ratio parameter of PostProcess but it instead rendered a full resolution post-process on top of a low resolution scene :
What is the best way of achieving this effect with Babylon? (I have been thinking about using a Procedural texture but maybe there is something better?)
The texture of the post-process will be used to render the scene, so you want the ratio to be 1 if you want the scene to be rendered at full resolution.
You can do what you want, but it’s not really straightforward.
At initialization:
creates the simpleRayTracer post-process outside of the normal chain of post-processes, that is don’t pass camera to the constructor but engine instead => this way, the post-process won’t be automatically run, we will do it manually
resizes simpleRayTracer to the size you want (we must do it manually because the post-process is not created inside the normal chain of post-processes)
creates a merge post-process, which will merge the scene with the raytraced scene. This post-process is created normally, that is by passing camera to its constructor. This way, its texture will be used to render the scene. So, this post-process must be created with a ratio of 1.
At runtime:
render the simpleRayTracer post-process in the scene.onAfterDrawPhaseObservable observable (at that time, the scene has already been rendered in the merge texture, but the merge post-process itself has not yet been run): scene.postProcessManager.directRender([simpleRayTracer], simpleRayTracer.inputTexture). This will generate the raytraced scene in the simpleRayTracer texture.
Now, when the frame is finalized and the merge post-process is run, the raytraced scene will be merged with the scene.
PG:
You will see there’s a problem with depth, though, because of the lower resolution of the raytraced scene…
You can fix this problem by quantizing the uv when you create the ray to trace in your first PG:
But if the goal of the lower resolution is to decrease the number of calculation, this is of no use…
My goal is indeed to decrease the number of calculations, but I guess I can write the depth inside the texture as well and do the occlusion test in the merge post-process instead