How to improve precision in a large scene with multi-cameras

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

How to improve precision in a large scene with multi-cameras

Post by Assaf Raman »

I am faced with the following issue:
I have a large terrain; it extends for 1000 kilometers by 1000 kilometers.
I have two cameras showing 2 entities on different sides of the terrain.
One entity position is {0,0,0} and the other entity position is {1000000, 0, 1000000}. (1 = meter).
My terrain has houses, trees and such.
My problem is that I get depth fights in the camera showing the object that is far from the scene center.
The problem is a float precision issue.

If I will compile OGRE with Ogre::Real as a double instead of a float – I will still have issue – because the rendering API uses floats for its matrix (Ex: D3DMATRIX in d3d9 is defined as float m[4][4]).

Mattan and I talked this issue over and he had a good idea that I want to share with you and get responses to.

The idea:
1. Change Ogre::Real to be double.(Set OGRE_DOUBLE_PRECISION to true).
2. Each time the view matrix is set – transform it to {0,0,0} and save the transpose Vec3d. Each time a world matrix is set – subtract the saved view matrix transpose from the matrix.

The result is that the rendering will always be as the camera is in {0,0,0} – maximum float precision when rendering.

The only price I see is the performance – so let's analyze it:
The view matrix gets updated once per camera render – so no hit here.
The hit for the world matrix transpose is only 3 more "add" operations – for each world matrix update – so this is not a bottle neck.
The biggest hit is working with double as Ogre::Real – if you are using a 32 bit system. But – if you are running such a big scene – you must use a double for your location, right?

If the idea is valid and will work in my tests and such (and doesn't exist is some other way) - I want to add this option as a new compile switch.

What do you think?
Watch out for my OGRE related tweets here.

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: How to improve precision in a large scene with multi-cameras

Post by Wolfmanfx »

SceneManager changes
Chaster's 'Portal Connected Zone' SceneManager added
'Camera relative rendering' option added so that in large scenes where you are far from the origin, precision issues on the GPU can be mitigated by only transforming objects relative to the camera. See SceneManager::setCameraRelativeRendering

sounds similar.

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: How to improve precision in a large scene with multi-cameras

Post by Assaf Raman »

setCameraRelativeRendering sounds exactly the same as this idea.
Thanks for the answer.
Sorry for your time.
Watch out for my OGRE related tweets here.

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: How to improve precision in a large scene with multi-cameras

Post by Wolfmanfx »

Np :)

Post Reply