Author Topic: multiple worlds and clipping planes  (Read 2357 times)

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
multiple worlds and clipping planes
« on: September 24, 2011, 09:21:28 pm »
Hi all

Just a quick question about multiple worlds and clipping planes.

I've got 2 worlds, one is my terrain and skydome and has a large clipping plane (200000) and I have a second world for my scenery objects with a clipping plane of 5000. The terrain object is about 4000 polygons and is my entire playing world.

My objects sit on top of the scenery but when my objects get in range, they seem to slowly emerge from beneath the terrain and visa versa if I move away from them, they look like they sink beneath the terrain.
I am not sure what is happening, if i have all my terrain and objects in the same world, they are fine but putting them in the second world it looks like they are moving in the Y axis.

I know, I know, I probably shouldnt use a clipping plane that large but I need the world to be as big as possible. And I dont want to draw all my objects in the same world because they would all be drawn even if they're miles away.

If there is no solution to this, is there perhaps another way to cull objects when they are a certain distance from the camera without having to loop through all of them?


Thanks for any suggestion and help
Rich

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: multiple worlds and clipping planes
« Reply #1 on: September 25, 2011, 11:39:14 pm »
I'm not sure what the exact problem is...might be a zbuffer accuracy issue. IIRC, my own tried with such a far away clipping plane weren't very successful von Android either. Maybe a screen shot will help...

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: multiple worlds and clipping planes
« Reply #2 on: October 17, 2011, 12:12:06 am »
Sorry for the late reply. doing stupid overtime at work so had no time to work on my game.

And sorry for the poor screenshot but here it is:
http://www.richterdesigns.co.uk/stuff/clipping.jpg

The ground surface has a large clipping plane and the objects are in a different world with a much lower clipping plane.
The building on the left is nearby but when i move backwards, it looks like it's sinking into the surface object. (the right image)
If i put all objects into the surface world, it's all fine and visa versa if i put everything into the objects world.


Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: multiple worlds and clipping planes
« Reply #3 on: October 17, 2011, 01:14:15 am »
If you change the FOV does that make a difference?

Are you changing the origins of the objects or translating everything from 0,0,0?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: multiple worlds and clipping planes
« Reply #4 on: October 17, 2011, 07:25:31 am »
Honestly, i'm not really sure what i'm seeing in this screenshot... ??? Anyway, it might be related to different scalings of the zbuffer. If that's the case, there's no other option than using one clipping plane for both worlds. Does it work if you set them both equal?

Edit: If you want to cull objects on your own, there's no other way than looping through all of the. That's not a big deal though. I'm doing this for the terrain scene in An3DBenchXL too, where i'm only rendering tress in view and at a limited distance. At that visibility border, the trees fade in softly.
« Last Edit: October 17, 2011, 10:40:53 am by EgonOlsen »

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: multiple worlds and clipping planes
« Reply #5 on: January 27, 2012, 01:18:27 am »
Sorry to open an old thread but I found out some more info.
My helicopter has a model with a transparant texture for the rotor blades. When I don't draw the blades the drawing order is fine. But when I do draw them. The problem occurs. Its like the building sinks into the landscape the further it gets from the camera. But it happens quite nearby so its quite obvious.
Its the same on my nexus s and archoid tablet.

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: multiple worlds and clipping planes
« Reply #6 on: January 27, 2012, 04:08:33 am »
If you set the sort distance of the rotor blades to 100000 directly after loading the 3D file, does that make any difference?

myrotorblades.setSortOffset(100000);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: multiple worlds and clipping planes
« Reply #7 on: January 27, 2012, 07:50:01 am »
If the problem persists, i need a test case to see what's going on...i can't tell from that screen shot as i've no idea what it actually shows. Is the ground actually transparent (if that brown stuff is a ground texture...)?

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: multiple worlds and clipping planes
« Reply #8 on: January 27, 2012, 10:43:06 am »
Offset doesnt make a difference.

The brown stuff is the landscape and the dark grey box is a building. On this first screenshot it's sitting on top of the landscape. On the right screen, i've moved backwards so the building is further away and only the top half of the building is above ground. Nothing is transparant on the screenshots.


I'll get a test case done this weekend.


Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: multiple worlds and clipping planes
« Reply #9 on: January 28, 2012, 01:30:17 pm »
Well, its nothing to do with transparancies i think.
here is my testcase. had to adjust it a bit to set it up like my game.
Move up and down to move away from the object. further it gets, the more it 'sinks'

www.richterdesigns.co.uk/stuff/ModelViewer.zip

thanks for looking into this.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: multiple worlds and clipping planes
« Reply #10 on: January 28, 2012, 05:56:26 pm »
This comes from differences in the resolution of the zbuffer when using different far clipping planes. There's nothing you can do about this, except not to do it or, if the plane is always below the objects and doesn't interact with them in any way, you can change the render-calls to this:

Code: [Select]
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.clearZBufferOnly();
world_objects.renderScene(fb);
world_objects.draw(fb);
fb.display();

That will clear the depth buffer between rendering the two worlds.
« Last Edit: January 29, 2012, 12:25:33 pm by EgonOlsen »

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: multiple worlds and clipping planes
« Reply #11 on: January 29, 2012, 12:21:57 pm »
Cool! that works. (ofcourse)

thanks