Time of flight camera simulation with z buffer

General discussion area.
Post Reply
ted
Posts: 57
Joined: Wed 25. Jul 2012, 22:53

Time of flight camera simulation with z buffer

Post by ted » Sun 26. Aug 2012, 08:15

Is it possible to get the Z buffer of an image to be used as a simulation of time-of-flight camera or for simulating laser range finder or sonar? These would all be great for robotic simulations...

benjamin.kutschan
Posts: 48
Joined: Mon 16. May 2011, 16:29

Re: Time of flight camera simulation with z buffer

Post by benjamin.kutschan » Mon 3. Sep 2012, 21:53

Hi ted,
I'm currently developing the new opengl-3.3-backend. With this new backend it will be rather easy to write a shader in GLSL that writes the z-buffer of every pixel.
The backend might be ready by the end of the year. If you remind me then, I'll write you a tutorial:

http://page.math.tu-berlin.de/~kutschan/

However this probably doesn't help you now...

ted
Posts: 57
Joined: Wed 25. Jul 2012, 22:53

Re: Time of flight camera simulation with z buffer

Post by ted » Thu 13. Sep 2012, 05:23

Thanks, that's very encouraging. You're right. I'm trying to get a paper out this week, so that will be awhile, but I have to say the support for JReality is amazingly responsive. Kudos to you all!

benjamin.kutschan
Posts: 48
Joined: Mon 16. May 2011, 16:29

Re: Time of flight camera simulation with z buffer

Post by benjamin.kutschan » Sat 12. Jan 2013, 11:03

Even though the new backend isn't finished yet (no tubes for the edges, no Sphere Geometry type, some attributes not working) you could implement your depth buffer drawing like this:

Code: Select all

String[] source = new String[2];
source[0] = "poly.v";
source[1] = "poly.f";
a.setAttribute("polygonShader::glsl330-source", source);
This code can be found in test-backends-share/light/Test.java
It makes the vertex/fragment shaders in the specified files to be used for the object to which the Appearance a belongs.
Then in the fragment shader you need something like

Code: Select all

out vec4 gl_FragColor;
uniform vec4 diffuseColor;
//in vec2 gl_PointCoord;
void main(void)
{
	//you have to play around with getting the right shade of grey out of the fragment depth.
	gl_FragColor = 0.5*gl_FragCoord.z*vec4(1, 1, 1, 1);
}
And don't forget to enable the opengl3 backend as is described in the article
"Switching between Rendering-backends broken" in
Foren-Übersicht » Bugs and Feature Requests » Bugs
You have to press F3 or choose from the Viewer menu in the top menu bar of the jReality-Window to switch to opengl3.3

Post Reply