Re: [osg-users] Jitter problem - OSG Nvidia Physx

2011-01-27 Thread Arif Yetkin Sarı
Hi again
I got what you meant hybr. As i said, When my fps is the same with physx freq, 
it all works well. However,
The thing is my slowest fps is like 20 - 25 on simulation, so i cannot cap OSG 
to always work at that slow rates. 

So, i implemented an interpolation mechanism to get a generated frame for a 
requested timestamp. I thought, in this way:
whatever freq physics and OSG run at, OSG will get a correct frame with 
interpolation. But somehow, when
interpolation is active, it causes additional jittering! I think interpolation 
between frames takes more time
than i think, and delays the frame() call.

Additionally,

I implemented a test bed. In my test bed, i just read a physx log file, and 
created 
the same scene of our driving simulation with OSG. Then I updated the cars' pos 
and 
ori at each frame with regards to physx data. There is still jitter if fps 
changes. 
But, there is almost no jitter when both physx and osg works in perfectly 60Hz. 

In the test bed, before the rendering starts, each frame on the physx log is 
placed 
in a queue. *What i mean by frame: it is a snapshot of physics world (all 
entities) 
at every 16.6 ms (60Hz) timestamps. And since my osg works with 60 fps in my 
test bed, 
and since after every time viewer-frame() function is called OSG dequeued 
another 
frame and updated the entity matrices, there is no jittering. However if the 
fps drops 
somehow, there is a slow down in motions, it is completely comprehensable 
because it consumes a 
60Hz physics output in a slower Hz, when fps drops. 

In our simulation I implemented the same queue to store the incoming frames, 
and consume them 
when the frame() ends. My strategy is, if the queue is empty, i simply do not 
update the scene. 
If the queue is filled more than 4 frames, i delete some of the old frames and 
shrink the queue so that 
we dont get a delay. However, this poses some little teleportations due to 
frame drops when 
OSG cannot consume the data, as expected. Thus i cannot use this method either.

After your comments and my experiments, I think, there are two problems why i 
get lots 
of jitter in our simulation. First of all, simulation fps fluctuates more than 
the test bed, 
that is between 25 - 60. This converts the occasional slow down of car motion 
into a jitter. 
Second problem, sometimes our queue contains no frames and this means a freeze, 
on the contrary sometimes our queue is filled with too many frames, which means 
we teleport in time and dequeue some of them to prevent delay.

In summary only perfect smoothness i get during my experiments is: 
when the queue is filled with tooo many 60Hz generated frames beforehand and my 
test bed runs at 60 fps,
it consumes the already generated(read from file) physics frames at the correct 
time stamp. And everything is smooth.

Still, anything I assume may prove wrong, so I am waiting for your feedback 
guys.

By the way, is the way I update my scenegraph ok ? (after each frame(), i call 
matrixtransform-setmatrix(matrix) for all
entities.). These calls are out of the frame(), so i thought i would be safe. 
Do you suggest me to use nodeupdatecallbacks ?
Does it make any difference ?

Thanks.


http://www.youtube.com/watch?v=naX3hOkDx8w

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=36033#36033





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Jitter problem - OSG Nvidia Physx

2011-01-26 Thread Arif Yetkin Sarı
Tomlinson, you are right, so i uploaded a video.
http://www.youtube.com/watch?v=hmqevNbXzy0
you can see that the movement is likely to freeze every few moments. Simply the 
simulation is not smooth. One may think its due to fps drop or performance 
issues. Nope, i still get this jittering effect for example at 50fps. 

Buckley, we are around origin. Example x y z h p r values :
-252.750 385.134 0.100 0.000 0.000 0.000
If you are talking about precision problem, that is not the type of issue we 
got in my opinion. 

Chuck, even if the camera is still, i can see the cars jittering on the road. 
So, i am sure the entities jitter, but not sure if cam is jittering. But, we 
attach our camera to cars, then i am sure camera jitters too, since the car is 
jittering.

Here is a very simplified draft of our system:

THREAD1 : Of course we have a class where the osg is initialized, and utility 
functions are provided like : addEntity, updateEntityPosAndOri, 
camFollowEntity, camAttachEntity, deleteEntity, updateCamPosAndOri, enableRain, 
setTextOverlayOnScreen, . etc.

THREAD2 : and we have an osg render loop thread : 

Code:
while (!mViewer-done())
{
mLib-frame();
microSleep(1000);
}



THREAD3 : and we have yet another thread that physx is running on. It produces 
x y z h p r values, and uses functions like updateEntityPosAndOri and 
updateCamPosAndOri to alter the scenegraph.

(again)Here what we tried: 

1-we called the utility functions (updateEntityPosAndOri) directly whenever 
THREAD3 produced a physx output  (every 16.6 ms or so - 60Hz): there is jitter. 

2-we accumulated x y z h p r information (produced per ~16.6 ms) that comes 
from THREAD3 on a queue on THREAD1. And we updated the entities of the scene 
after each frame() function is called in THREAD2 - in other words, we 
serialized our asyncrhonious mechanism. : there is jitter.

3-we implemented a sampling mechanism on this queue, where OSG requests the 
interpolated frame from the queue for the current timestamp. - in other words, 
we act like that we have a continous input signal, and we sample it according 
to current time, whenever a frame() is completed : there is jitter. 
4-we saved a few minutes long log of the physx to a file (that means many 
frames). Started a dummy thread (instead of THREAD3), and fed OSG from this 
log. : there is jitter.

But, whenever the fps is 60, and physx thread works in 60Hz, there is 
relatively low jitter (or unnoticeable)

Thanks for your comments.
Arif Yetkin
Thanks for the advices.


http://www.youtube.com/watch?v=naX3hOkDx8w

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35982#35982





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Jitter problem - OSG Nvidia Physx

2011-01-26 Thread Arif Yetkin Sarı
J.P. Delport : I got what you meant. Yes, I believe the THREAD3 output is 
robust. When we call physics.simulate() in THREAD3, for all entities in the 
physics scene (which are bounding boxes of the real entities in OSG), we get 
their positions and orientations at that exact time slice. Meaning that we 
produce a set of x y z h p r values at a particular timestamp where all 
entities' x y z h p rs are consistent with each other. Then we send this x y 
z h p r set to our frameQueue, and these frames are comsumed one at a time 
(or sampled whenever needed).


http://www.youtube.com/watch?v=naX3hOkDx8w

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35985#35985





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Jitter problem - OSG Nvidia Physx

2011-01-24 Thread Arif Yetkin Sarı
Hello everyone.

We have been using OSG with nvidia physx for a driving simulation and we have 
jitter problem, where the cars and other objects in the scene (controlled by 
the physics) jitter annoyingly :). We believe that we update the scenegraph in 
a wrong way.

In our code : 
There is a physx thread.
There is an OSG library thread where we can add new entities, remove them, 
start rain effects, call an animation of a skeleton character etc. 
There is an OSG render loop thread, where osgviewer::...frame() is called.

Our Nvidia physx thread produces new x y z pitch head roll values for the 
scene entities at 60Hz (or any other frequency we want). 
Physx thread calls the updateEntity() function of our OSG library thread.
This function simply updates scene entities with matrixtransform::void 
setMatrix(const Matrix mat).

In other words, we move an object with this chunk of code:

Code:
osg::Matrixd mxT = createTransformMatrix(x,y,z,h,p,r);
mt-setMatrix(mx);



Here what we tried:
1-we fed OSG lib directly whenever a physx output is produced (every 16.6 ms or 
so - 60Hz): there is jitter.
2-we maintained a queue of frames on OSG lib, fed OSG at the end of each 
frame() : there is jitter.
3-we implemented a sampling mechanism on this queue, where OSG requests the 
interpolated frame from the queue for the current timestamp : there is jitter.
4-we saved a few minutes long log of the physx to a file  (many frames). 
Started a dummy thread, and fed OSG from this log. : there is jitter.

When OSG works with 60FPS, and physx thread is running at 60Hz, there seems to 
be quite low jitter (sometimes unnoticeable) .

Thanks in advance for any hints or advices.
Arif Yetkin


http://www.youtube.com/watch?v=naX3hOkDx8w

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35912#35912





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Cached switch nodes : switch one of them - all of them gets switched!!!

2010-12-24 Thread Arif Yetkin Sarı
Hi all

I am trying to use osgDB::Registry cache to avoid loading the same models 
multiple times.

Caching works ok, reduces the memory usage as expected.

I enable caching with :


Code:
osgDB::Options* opt = osgDB::Registry::instance()-getOptions();
if (opt == NULL) 
{ 
opt = new osgDB::Options(); 
} 
opt-setObjectCacheHint(osgDB::Options::CACHE_ALL); 
osgDB::Registry::instance()-setOptions(opt);



I read an ive file with : 


Code:
osg::ref_ptrosg::Node node = osgDB::readNodeFile(f);



(a quick question : if i enable caching globally like the above chunk of code, 
do i have to pass options parameter to the overloaded readNodeFile function ?)

But whenever i read an ive file with switch ability more than once; a switching 
action during runtime alters all of the models.

For eg. when i load two traffic lights, the second one is retrieved from cache. 
And if i change the switch on any of them, the other one gets affected too!

Any hints guys ?

PS : I was trying to read osgCal animated meshes in my OSG code a while ago. 
And i implemented a map to not to load the same animated mesh from file more 
than once. But at the time, i had the same problem : when an animation was 
triggered, all of the animated mesh instances got affected. I overcame this 
problem by caching osgCal::CoreModel instead of osgCal::Model

Thanks in advance
Arif Yetkin


http://www.youtube.com/watch?v=naX3hOkDx8w

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35156#35156





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] rain/snow accumulation on the screen

2010-12-10 Thread Arif Yetkin Sarı
Hi all, I am also looking into this issue like Nik.

the needs are:
1.Rain drops must appear on the screen when in fps (car driving) camera mode
2.They dont need to move, but their numbers will increase in time and make it 
difficult to see the environment.
3.When activated a wiper will rotate on the screen, clearing the raindrops as 
it touches them.

similarly snow will accumulate on the windshield and wiper will clean them too.

Can this be done with osg particle classes? What kind of new functionality may 
be needed if particle system is not enough to handle these tasks ?
Or what specific features of osg can accomplish such tasks?

Thanks in advance for any hints.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=34695#34695





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgCal animated mesh, possible overlit problem

2010-11-22 Thread Arif Yetkin Sarı
Hello again.

First of all thanks for the advices. 

The models look ok in cal3D openGL based viewers. 
Though I couldn't setup independent cal3d properly and run its viewer. (I work 
on a simulation project, which uses osgCal to load animated meshes, thats where 
i code, and see the bug mentioned in this topic)

Also I checked if specular exponent is used anywhere.  it is a part of 
osgFX::SpecularHighlights , and it is not used in my project. 


But i did manage to overcome the problem by setting my light

mSun = new osg::LightSource;
mSun-getLight()-setLightNum(0);

to 

mSun = new osg::LightSource;
mSun-getLight()-setLightNum(1);

I am curious  and have a few questions :
(I am new to OSG, and maintaining someone else's project, so sorry for the noob 
questions :)

Why light slot 0 is problematic ? 
When i completely delete my light, i still get visual (not complete darkness in 
the scene). So it means i have another light source ? Probably my sun and the 
other light is both assigned as light0, so this may be the cause of the overlit 
problem ?

I dont have any lights other then mSun, but i see that in the code osgEphemeris 
is used. It has internal moon and sun light, so they are probably overlapping 
with my manual sun light ?

And also, i heard that Silverlining can illuminate your scene like 
osgEphemeris, if so, it has also internal lights too ? How can i understand 
which light slots ephemeris and silverlining is using ?

Did I understand the light slot concept correct ? : U can use 8 lights, and u 
need to assign them properly to make it work as expected ?

Thank you for your patience.

Arif

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=33927#33927





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgCal animated mesh, possible overlit problem

2010-11-22 Thread Arif Yetkin Sarı
Hi, ty for the fix Nick.

For those that need/will need help in a similar situation, (as far as I can 
tell) osgUtil::SmoothingVisitor added to osgCal models solved the overlit 
problem. (And a little bit material adjustment for the mesh made it lit at a 
normal level)

Arif

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=33967#33967





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] osgCal animated mesh, possible overlit problem

2010-11-12 Thread Arif Yetkin Sarı
Hello guys,

I have been trying to import animated charater meshes to OSG via osgCal. I can 
add example cal3D animated meshes and call their animations in my application. 
However there is a possible problem regarding (probably) lighting. The surfaces 
that are exposed to my (directional) light are pure white as you can see on the 
screenshot. I already tried to use GL_NORMALIZE or 
GL_RESCALE_NORMAL that i saw on this topic : 
viewtopic.php?t=3402 
, but it didnt work. I also used Cal3D converter to convert binary mesh files 
to xml, and checked their normals. they all seem ok and their magnitude seems 
to be 1, as expected for a Normal vector.

I will appreciate any hints to solve my issue.

Thanks in advance.

Arif

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=33720#33720




Attachments: 
http://forum.openscenegraph.org//files/cal3d_3dsmax_exported_animated_mesh_possible_overlit_problem_867.png


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org