Hello everyone, I have been studying performance issues recently, and I found that the render method is called differently in different scenarios. I want to understand the difference between the two methods. I look forward to your reply!
Welcome aboard!
_renderToTarget
is the main method used to render meshes in a render target texture:
private _renderToTarget(faceIndex: number, useCameraPostProcess: boolean, dumpForDebug: boolean, layer = 0, camera: Nullable<Camera> = null): void {
const scene = this.getScene();
if (!scene) {
return;
}
const engine = scene.getEngine();
engine._debugPushGroup?.(`render to face #${faceIndex} layer #${layer}`, 1);
// Bind
this._prepareFrame(scene, faceIndex, layer, useCameraPostProcess);
if (this.is2DArray) {
engine.currentRenderPassId = this._renderPassIds[layer];
this.onBeforeRenderObservable.notifyObservers(layer);
} else {
engine.currentRenderPassId = this._renderPassIds[faceIndex];
this.onBeforeRenderObservable.notifyObservers(faceIndex);
This file has been truncated. show original
_renderOpaqueSorted
is used to render the opaque subset of some (sub) meshes (either for a render target texture or for the main pass):
private static _RenderSorted(
subMeshes: SmartArray<SubMesh>,
sortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>,
camera: Nullable<Camera>,
transparent: boolean
): void {
let subIndex = 0;
let subMesh: SubMesh;
const cameraPosition = camera ? camera.globalPosition : RenderingGroup._ZeroVector;
if (transparent) {
for (; subIndex < subMeshes.length; subIndex++) {
subMesh = subMeshes.data[subIndex];
subMesh._alphaIndex = subMesh.getMesh().alphaIndex;
subMesh._distanceToCamera = Vector3.Distance(subMesh.getBoundingInfo().boundingSphere.centerWorld, cameraPosition);
}
}
const sortedArray = subMeshes.length === subMeshes.data.length ? subMeshes.data : subMeshes.data.slice(0, subMeshes.length);
This file has been truncated. show original
At some point, _renderToTarget
will call _renderOpaqueSorted
(through the rendering manager).
4 Likes
Thank you very much for your reply. Can you give some examples of only calling _renderOpaqueSorted without calling _renderToTarget?
Yes, if you don’t use any RenderTargetTexture
, _renderToTarget
won’t be called. So, the default Playground is a good example of this!
Here’s a subset of a performance snapshot for the default PG:
Ok, I get it, thank you very much for your detailed reply!