Peter2 Posted December 19, 2016 Share Posted December 19, 2016 I'm looking for the depth information (per pixel) of a camera's view on the scene: distance position: x,y,z Currently I'm using the scene pick functionality for each pixel: for x = 0 to maxX for y = 0 to maxY scene.pick(x,y,null,false,camera) Then use the returned PickingInfo's distance and pickedPoint. Is there a better/faster way to get the depth information, because the above mentioned code takes several seconds. Maybe via a shader? Quote Link to comment Share on other sites More sharing options...
Sebavan Posted December 19, 2016 Share Posted December 19, 2016 You can use the depth renderer for this: https://doc.babylonjs.com/tutorials/How_to_use_DepthRenderer_to_get_depth_values Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 20, 2016 Author Share Posted December 20, 2016 Yes, but it does not give me the position. Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted December 21, 2016 Share Posted December 21, 2016 good question, do you want to use the positions in js side ? Or want to use in a shader like a post-process ? Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 21, 2016 Author Share Posted December 21, 2016 I like to have the information in JS code. Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 28, 2016 Author Share Posted December 28, 2016 I got the depth (via a shader) on a RenderTargetTexture visible on the screen. But how can I retrieve the depth data from the texture (in JS code)? Is there a way the walk from 0 to 1 for u and v and get the rgba data? Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted December 28, 2016 Share Posted December 28, 2016 hi i use this solution before why you need this data @Peter2 Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 28, 2016 Author Share Posted December 28, 2016 I like to output the following data to a file: distance, x, y, z That is, for each frame of a camera. Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted December 29, 2016 Share Posted December 29, 2016 An example function (not tested for depth values, only rgb): renderTargetTexture.onAfterRenderObservable.add(function () { var pixels = self.engine.readPixels( 0, 0, xsize, ysize ); //pixels is now a byte array of RGBA values? } Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 30, 2016 Author Share Posted December 30, 2016 Yep, that well do it. Thx. Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 30, 2016 Author Share Posted December 30, 2016 Next step is to get the position (the pickedPoint). How to convert the vertex position into gl_FragColor? Quote Link to comment Share on other sites More sharing options...
Peter2 Posted December 30, 2016 Author Share Posted December 30, 2016 I got something like: VertexShader: varying vec4 vPosition; void main(void) { vec4 pos = vec4(position, 1.0); vPosition = world * pos; gl_Position = worldViewProjection * pos; } PixelShader: varying vec4 vPosition; void main(void) { gl_FragColor = vec4(vPosition.xyz / 255.0 + 0.5, 1.0); } Is this correct? I'm losing precision this way I think. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted December 31, 2016 Share Posted December 31, 2016 you wanna do this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.