Author Topic: Depth buffer texture  (Read 19788 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Depth buffer texture
« on: June 30, 2012, 01:58:21 am »
What is the best solution for render zbuffer? shader is not problem, but if I have screen resolution 1280*720, do I need texture resolution 2048*1024? I don't know how exactly working GPU with texture, but when I understand correctly power of 2 is needed for mip-mapping?

edit: and what is the best way to implement depth of field? I need three rendering, normal, zbuffer and plane, but how this does intelligently? :D
« Last Edit: June 30, 2012, 02:22:34 am by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #1 on: June 30, 2012, 10:01:46 pm »
You have to render the depth buffer into a texture. The actual screen resolution isn't important. To render a depth map into a texture, you can use this method: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html#setAsShadowMap(boolean) and make this texture a render target of your frame buffer. However, the resulting texture doesn't contain the depth values directly but packed into ARGB format. The reason is, that i couldn't get depth textures to work on Android at least on my device. So you have to unpack the values before using them.
You can can find the code for this if you unzip the jpct_ae.jar and look at the file defaultFragmentShaderDepth.src. It contains the code to unpack the values within some comments.

About how to do depth of field...i have absolutely no clue how to do this because it never interested me in the slightest... :(


Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #2 on: June 30, 2012, 10:15:55 pm »
Ok, I'll try to implement depth of field. Probably I'll have to switch IRenderHook several times on one object in one frame.

edit: And what you mean "The actual screen resolution isn't importan."? how it's working?
« Last Edit: June 30, 2012, 10:23:17 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #3 on: June 30, 2012, 10:30:20 pm »
I've no idea how it is working, because i don't know how to do depth of field. What i meant was that for rendering into a texture, the screen resolution isn't important because the target texture has a resolution of its own.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #4 on: June 30, 2012, 10:44:00 pm »
So, if I understood correctly, I can use texture 16x16, but when I'll use it as render target, doesn't matter on it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #5 on: July 01, 2012, 09:19:57 am »
You will be rendering into a 16*16 texture then. All i was trying to say is that the texture resolution has nothing to do with the screen resolution....

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #6 on: July 03, 2012, 04:25:08 pm »
How can I calculate FOV to degree?

edit: solved, in java doc is formula
« Last Edit: July 03, 2012, 04:37:44 pm by Thomas. »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #7 on: July 03, 2012, 08:43:10 pm »
Could you add method for create texture with any dimension, please? I have "out of memory error" with two texture with size 2048*1024. Or no storing copies in main memory.
« Last Edit: July 03, 2012, 09:29:34 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #8 on: July 03, 2012, 09:43:01 pm »
Just create one with a color of null.

Edit: 2048*1024 is insane on a mobile device anyway IMHO...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #9 on: July 03, 2012, 09:52:38 pm »
NullPointerException... I agree, but I can not create texture with size 1280*720. I need two textures, first with zbuffer, second with image buffer and in third render is applied effect.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #10 on: July 03, 2012, 09:58:27 pm »
Oops...that used to work. I'll fix it...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #11 on: July 03, 2012, 10:11:53 pm »
omg, I'm very complicated counted size of plane, that has same size like the screen and I forgot on model view projection matrix in shader :D ok, thanks :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #12 on: July 03, 2012, 10:13:51 pm »
Anyway, the null pointer might be fixed in the version that i've just uploaded (look the other thread for more info).

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #13 on: July 03, 2012, 10:29:38 pm »
NullPointerException still bother... did you mean "new Texture(512, 256, null);"?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11771
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #14 on: July 03, 2012, 10:32:46 pm »
Yes...can you post the exception?