Depth buffer texture

Started by Thomas., June 30, 2012, 01:58:21 AM

Previous topic - Next topic

Thomas.

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)

EgonOlsen

Thanks. Looks like i forgot to deploy the fixed version. Please download again.

Thomas.

NullPointerException is gone, but I can not confirm the functionality, I have bug in my code

Thomas.

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?

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));

EgonOlsen

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?

Thomas.

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.

EgonOlsen

#21
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?

Thomas.

#22
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

EgonOlsen

Quote from: Thomas. on July 04, 2012, 10:05:10 AM
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.

Quote from: Thomas. on July 04, 2012, 10:05:10 AM
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?

Thomas.

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.
GLSLShader.addReplacement("defaultFragmentShaderDepth.src","");

EgonOlsen

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.

Thomas.

#26
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?

EgonOlsen

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?

EgonOlsen

Quote from: EgonOlsen on July 04, 2012, 04:13:16 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...

Thomas.

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...

depthTexture = Utils::CreateTexture(width, height, NULL, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT);