Inconsistent behaviour in generating DepthMaps

Hello Everyone,
So basically I am trying to generate depth map of high quality.
And I am using the RTTs …createDepthStencilTexture()

Requirement
Using internal texture is kind of a compulsion for me.
And I don’t want to use BABYLON’s depthRenderer …
as there are some restrictions on depthRenderer I don’t want to face

  • No Custom width, height of the depth map
  • No Custom near, far for multiple DepthMaps
    (as I might need multiple depth maps with different near, far)

The basic workflow goes like this…

The Problem…

  • Everything works fine…
  • The only problem is it is inconsistent in generating depthMap
  • Sometimes It generates correct depth Map…Sometimes a blank one…

PG

It would be great if you guys can help me with this…

  • maybe the issue is with RTT generation…
  • maybe the issue is with Internal texture
  • maybe the issue is with promises, await, async
  • maybe the issue is with download/read/base64 related APIs
  • And you can suggest any other reliable method which can give same result
  • The output should ideally be a base64 string of depthMap
  • Downloading depthMap .png is for debugging
    Thanks :slight_smile:

Hello,

Having a look at your playground, I didn’t read in details the proper depthmap generation, but still I think it’s kinda weird that you do :

for(let k = 0; k<nTry; k++) {
    console.log("####### DepthMap Try"+k+" ########");
    let promiseBase64 = depthMapObj.downloadDepthMapHDForum(scene,engine,{saveToDesktop:true,near:2,far:100,distributionScale:"linear",name:"depthMapPG"+k});
}

In the createScene function, without any hand on the timing between two captures.


I just gave a try that way :

let k:number = 0;
scene.onAfterRenderObservable.add(function(){
    if(k<nTry){
        k++;
        console.log("####### DepthMap Try"+k+" ########");
        let promiseBase64 = depthMapObj.downloadDepthMapHDForum(scene,engine,{saveToDesktop:true,near:2,far:100,distributionScale:"linear",name:"depthMapPG"+k});
    }
})

And went from 100% empty depth maps to 100% ok depth maps :grinning:

2 Likes