Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Render Depth Image

Author
Message
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Feb 2016 18:20 Edited at: 11th Nov 2019 13:01
Hi,
I'm having problems when I try to Render the Depth of a 3D scene into an Image.
I set it up like so:

In the mainloop:

It crashes if i start the App.

Does someone have experiences in rendering the depth texture ?
What am I doing wrong ?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 28th Feb 2016 19:27
You don't have a colorImage. It MAY be required?
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Feb 2016 20:10 Edited at: 29th Feb 2016 18:01
@Mobiius thanks for your fast suggestion.

What Image should I take for that colorimage the same as the depthimage or one I rendered before as a normal colorimage ??
If I take the same image as colorimage and depthimage I get an Error message: GL_FRAMEBUFFER_INCOMPLETEATTACHMENT_EXT
And if i take a normal colorimage for the input, the result is a complete black renderimage.

I don't want to mix too much questions...
But does anybody know if we can use GL_ClipDistance[0] in a Vertex shader... so if it is enabled.
I want to clip things in the vertex shader rather than discard pixels in the fragment shader which is working for now but is much more computationally intensive.

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th Feb 2016 09:14 Edited at: 29th Feb 2016 09:14
Quote: "one I rendered before as a normal colorimage "


Check out the code in THIS post. I used it for my VR Zelda game, simply create a variable to hold the Depth image, and change these lines..

to


That's what I did, and it works fine. You can pull out all the vr code, and use only the rendering section, to make things easier.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 29th Feb 2016 18:10 Edited at: 29th Feb 2016 22:09
OK I don't get it.
I think I've tried everything but ...

Could someone do me a favor and hack the code for a depth image into an 3D example and paste it here. (just quick and dirty)
And it will be worth it, trust me

I need something like:

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Mar 2016 09:13 Edited at: 1st Mar 2016 09:14
Are you trying to render a depth image from the device camera, or do you just mean the 3d scene? As the link I posted above has a complete working example. (After adding the changes I suggest)

Also, you should be able to render a depth map via a shader to the screen. My knowledge of shaders is low, so cannot help with this myself unfortunately.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 1st Mar 2016 21:40 Edited at: 1st Mar 2016 21:42
Maybe the Image above confuses a bit but i just googled Depthimage and found a picture of Lee Bamber.
The image I need shows the z-buffer in image format, it is the distance of a fragment to the camera: black(far) white(near) or vice versa.
I need it for a shader and it should be possible with AppGameKit ..at least with OpenGL it is

Maybe I can do it with a shader using gl_FragCoord.z...? anyway I prefer the FBO(Frame Buffer Object) method.


Thank you Mobiius.. ill don't give up on that and will release, what i have done with it, to the community.

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Mar 2016 23:40

Just the depth buffer is this...
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 2nd Mar 2016 22:33 Edited at: 2nd Mar 2016 22:37
Please run this code


As i said above it crashes for me if i put a 0 as colorImage:

If i put a -1 as colorImage it runs fine but the image is all Black:

I understand that -1 is for: "There is no Image" as 0 could be an ImageID !?
But i don't get plausible results.

And presuming it gives me a non-linearized depth image, I should nevertheless see a minimal change in the gray scale, and not a black only image, as I get now.

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Mar 2016 23:39 Edited at: 2nd Mar 2016 23:39
you are correct, it should be -1, not 0 for the color image as it crashes for me too.

However, when I run your code without changes, I get this...

Attachments

Login to view attachments
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Mar 2016 00:08 Edited at: 3rd Mar 2016 00:18
At first, I can hardly belive that you still trying to answer my questions as i would have given up by now.
Thanks for staying with me ☺

I get this result too..but it is wrong ..I except a sprite, with the depthimage of the scene, in the top left corner.
Should I report it as a bug ?

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Mar 2016 08:23
Not yet, as I know depth images word, as I'm using them.

What happens when you uncomment the SetRenderToScreen command? (Not at an AppGameKit equiipped computer.)
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Mar 2016 12:47
Oh wasn't aware that I still had it commented but nothing changes.
So you are using them successfully ? ..hmmm

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Mar 2016 13:52
Yep, the screenshot provided is what I get when I run your code. (I changed only the resolution to fit it in the screenshot next to the code.)
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Mar 2016 15:30
Are you saying that the code in which you are using the depth image (succesfully) is my example code ?
Your screenshot shows me that it wasn't successfully as it's just a scene with a 3D box but no depth image in the corner ...

Maybe we must render the scene as a depth image into a color image ?

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Mar 2016 15:56
Quote: "Your screenshot shows me that it wasn't successfully as it's just a scene with a 3D box but no depth image in the corner ..."

This one, I got confused for a second! lol
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Mar 2016 16:40 Edited at: 20th Jul 2016 17:28
Quote: "This one, I got confused for a second! lol"
what do you mean ?

I expect a sprite in the top left corner showing the z-buffer/depth of the scene, if everything works with my example code.
No depth image no success

I don't know what else I can try.

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Mar 2016 19:42 Edited at: 3rd Mar 2016 19:43

Running the above code, I think is conclusive that you can't display the depth image to a sprite.

You'll have to use a shader if you want to see the depth image on screen.


(Change DepthMode = 1 to DepthMode = 0 to see an image on the sprite.)
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Mar 2016 21:53 Edited at: 4th Mar 2016 17:36
So why we have a depthimage parameter in SetRenderToImage ?

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Mar 2016 22:08
You pass it direct to the internal shader (via SetRenderToimage() ) to render the depth information to the back buffer. Without it (when rendering to images), objects are rendered in creation order, not in depth order, therefore will be displayed on top of other objects.

Perhaps people who know better than me can chime in if I'm wrong, or with more information.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Mar 2016 18:25 Edited at: 4th Mar 2016 18:39
Of-course, objects are drawn in creation order if you don't provide the depth information(z-buffer)
And there might be a shader involved in the process of getting the depth from the scene and passing it into some sort of buffer.. Idk.
I want to read that information from the buffer.

There is an command in fragment shaders that I can use for rendering the scenes depth information(gl_FragCoord.z)
but then I must set up the shader for every object in the scene and render the result in a colorimage then I would change the shader from the object as I don't want a black and white scene and use the depthimage in a new shader.


I thought AppGameKit Provides it with the second parameter in SetRenderToimage...
Quote: "You can also choose to render the depth information to an image that you can use later, or render without a depth buffer if your scene does not need one. You can also use a depth image ID of -1 to render a depth buffer without capturing it in an image"

SetRenderToImage

Are you thinking we are talking past each other ?

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 4th Mar 2016 18:45
No, I know what the command says. I believe that the command passes the depth data in a way that can't be displayed onscreen, as it's meant for a shader.

But that's just pure guesswork.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Mar 2016 20:43
If performance isn't a priority, then it would be possible to create a depth image by casting a ray from the camera position for every pixel in the image. Would be real slow, but you'd get a depth image.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 4th Mar 2016 21:16 Edited at: 4th Mar 2016 22:19
@CJB
Oooh performance is a priority
And then you have a raytracer engine ..ill don't need OpenGL(rasterizer) then.
but nice suggestion.

@Mobiius
Okay? must think about that.. and ill think about how i can test that ...
Do u mean transparency? ...or something.. if i render it into an image it must be R,G,B or Alpha ...or what kind of data do you think of?

Using AGKv2 Tier1
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 4th Mar 2016 23:34
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 6th Mar 2016 22:41
I have tried rendering depth images and passing it to a shader to no avail in the previous version of agk. I haven't had the time to test it with the latest one but I'm pretty sure it's still broken.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 7th Mar 2016 18:56
I had a look and found a bug in Windows meaning depth textures couldn't be used as render targets, they were always being replaced with internal depth buffers. Fixed for the next version. Android worked as expected with the current version (2.0.18)
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Mar 2016 21:04
That's great news, Paul!
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 7th Mar 2016 22:13
Knew it !

Thanks, hope the new version comes fast

Using AGKv2 Tier1
GolWofael
8
Years of Service
User Offline
Joined: 15th Mar 2016
Location:
Posted: 28th May 2016 22:23
Dear all

The Render Depth Image is working now (new version 2.0.19 ) ??
Anyone has example code for it ??

Login to post a reply

Server time is: 2024-09-29 15:17:38
Your offset time is: 2024-09-29 15:17:38