Author Topic: Depth buffer texture  (Read 49728 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #15 on: July 03, 2012, 10:36:59 pm »
Code: [Select]
07-03 22:36:12.791: E/AndroidRuntime(14034): FATAL EXCEPTION: GLThread 8591
07-03 22:36:12.791: E/AndroidRuntime(14034): java.lang.NullPointerException
07-03 22:36:12.791: E/AndroidRuntime(14034): at com.threed.jpct.Texture.<init>(Texture.java:273)
07-03 22:36:12.791: E/AndroidRuntime(14034): at cz.chladek.mygame.util.DOFHelper.<init>(DOFHelper.java:30)
07-03 22:36:12.791: E/AndroidRuntime(14034): at cz.chladek.mygame.AppActivity$MyRenderer.onSurfaceChanged(AppActivity.java:471)
07-03 22:36:12.791: E/AndroidRuntime(14034): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1455)
07-03 22:36:12.791: E/AndroidRuntime(14034): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #16 on: July 03, 2012, 10:40:54 pm »
Thanks. Looks like i forgot to deploy the fixed version. Please download again.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #17 on: July 03, 2012, 10:46:08 pm »
NullPointerException is gone, but I can not confirm the functionality, I have bug in my code

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #18 on: July 03, 2012, 11:19:14 pm »
Oh, maybe I get it. I need to send plane to GPU with the same size like the screen size. First problem was frustum culling, because coordinates are in another coordinate system, I didn't realize, that will be discard (and probably if is camera position in 0 and object position in 0, will be also discard). And probably second problem is in building object and merge the vertices? Could you confirm it? If yes, how can I fix it?

Code: [Select]
plane.addTriangle(new SimpleVector(-1, -1, -1), 0, 1, new SimpleVector(-1, 1, 1), 1, 0, new SimpleVector(-1, -1, 1), 0, 0);
plane.addTriangle(new SimpleVector(-1, -1, -1), 0, 1, new SimpleVector(-1, 1, -1), 1, 1, new SimpleVector(-1, -1, 1), 1, 0);
plane.translate(1, 0, 1);
worldDOF.getCamera().lookAt(new SimpleVector(-1,0,0));

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #19 on: July 03, 2012, 11:36:40 pm »
Confirm what? That it will be clipped away if it's behind the front plane? Yes, it will...and it has to, because it would be impossible to render it. But you can give it any depth you like as long as you adjust the xy-coordinates accordingly. The Overlay-class does exactly that and you can get the Object3D from it...maybe that helps?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #20 on: July 04, 2012, 01:11:44 am »
Yes, it's exactly what I need. But I have problem with rendering into texture. If I render normal scene into texture and apply it on a object, object is black. We've deal with rendering into texture, but it must works. I have some demos, that running on SGS1 and SGS3 and game Nova3 uses deep of field effect, which running uses rendering into texture.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #21 on: July 04, 2012, 08:58:53 am »
The fact that some app based on the NDK works fine doesn't say much about the SDK. They should behave similar, but there are differences.
The last time i checked, render targets worked fine on my Nexus S. Make sure that your texture is square. Non-square textures will be rendered all black in OpenGL ES2.0 on some devices. Also try to play around with http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Config.html#renderTargetsAsSubImages in case you haven't already. If it still doesn't work: Do you have a SDK(!) based example with source code that works on your device?
And have i mentioned that i hate render-to-texture? This code works on the desktop with all chips that i've tried, it works on my device...it even works on BlackBerry. Why can't it just work on f!"&"&/!'## Mali chipsets? Why does somebody use Mali-GPUs in the first place?
« Last Edit: July 04, 2012, 09:35:58 am by EgonOlsen »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #22 on: July 04, 2012, 10:05:10 am »
Problem solved, null parameter in texture constructor.

edit: and I need constructor, that will ignore power of 2, please. I can't render into larger texture than is screen.
edit2: replace "defaultFragmentShaderDepth.src" shader probably doesn't work
« Last Edit: July 04, 2012, 11:02:32 am by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #23 on: July 04, 2012, 12:19:03 pm »
edit: and I need constructor, that will ignore power of 2, please. I can't render into larger texture than is screen.
It's not that easy. Supporting non-power of two textures puts some heavy restrictions on filter modes, clamping and doesn't work in ES1.x. I can't add a simple contructor for this and all will be fine. I have to modify the whole texture pipeline...it will take some time to add this.

edit2: replace "defaultFragmentShaderDepth.src" shader probably doesn't work
The log should tell you, if the replacement took place or not. Albeit that shader's name isn't mentioned in the docs, there's no restriction on the name. It either works for no shader or for all...and i currently don't see a reason why it shouldn't work. It hasn't changed for ages.

About the "problem solved"...does that mean that render targets are now working?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #24 on: July 04, 2012, 12:42:33 pm »
Render to targets working if I don't use null as color in texture constructor. On mali is fine, on adreno seems like mip-mapping texture (I think that this happened also on powervr, but I can't test it now).
For replace the shader I used this. Is it right? No output log and also no in debug mode.
Code: [Select]
GLSLShader.addReplacement("defaultFragmentShaderDepth.src","");

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #25 on: July 04, 2012, 12:55:58 pm »
You have to add the replacement at the beginning. After creating the FrameBuffer, it'll be too late. However, replacing it with nothing makes no sense anyway. I'll try to find the reason why it doesn't work with the null-color.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #26 on: July 04, 2012, 03:41:22 pm »
Depth of field working :) for now in 1024*512. But... rendering normal scene without any effects takes 7ms (strange, doesn't matter on count of per-pixel lights :) but even stranger, that also 7 ms takes rendering without any lights (super fast fragment processors?)). When I render exactly same scene to texture (in lower resolution, about 55% of original) and don't use them (so just render, nothing else), render zbuffer takes 20ms, render scene 28ms. If they are also used, rendering scene takes about 60ms... where is problem? textures are copied into internal memory?
« Last Edit: July 04, 2012, 06:12:47 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #27 on: July 04, 2012, 04:13:16 pm »
No. Nobody copies anything from or into main memory when using render targets. Render to texture is solely done on the GPU. No idea why it's so much slower. I guess the hardware just isn't optimized that much for this application. Or your shaders are not as optimized as they could be.

Screen shot of the result?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Depth buffer texture
« Reply #28 on: July 04, 2012, 04:19:28 pm »
No. Nobody copies anything from or into main memory when using render targets.
No, wait...this might not be entirely true. I think i'm not using FBOs for render targets in jPCT-AE...most likely because there is no support for it in ES 1.x. I'll look into ES 2.0 again to see if it's supported there...

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Depth buffer texture
« Reply #29 on: July 04, 2012, 06:12:35 pm »
So far it is not ideal, resolution, aspect ratio, I can not control distance, bias,... from application. Support mobile OGL something similar like desktop version for creating depth texture? It can be faster, than user shaders...

Code: [Select]
depthTexture = Utils::CreateTexture(width, height, NULL, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT);