Aurelien Albert | 1 Oct 2011 11:25
Picon
Favicon

[osgPPU] Very basic example ?

Hi,

After 2 days playing with osgPPU exmaples, I stil did not succeed to do a very basic PPU unit...

Is there any very basic example for osgPPU ?

Something like :

* create PPU
* add PPU unit which use a shader for a very basic operation (like switch red and green color components)
* attach PPU to camera

So with that, anybody could start coding PPU units easily.

Regards,
Aurelien

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

paul graham | 1 Oct 2011 12:34
Picon
Favicon

Re: getOrCreateStateSet called from outside the main thread

Hi, I've been away for two weeks, and now returning to this issue. Just wanted to update in case my findings
are useful to others.

On further investigation, I realised that calling getOrCreateStateSet on a newly created text node will
return a pointer to a 'singleton' instance of a stateset. I had assumed that after creating the text node,
the above call would 'Create' a new stateset rather than 'Get' an existing one - so I think some of our
crashes are due to the same stateset pointer being written to on different threads.

We're in the process of rationalising how we use statesets in our app. so we can reusing a singleset - this
should resolve our issue.

Thanks again

Paul

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

Wojciech Lewandowski | 1 Oct 2011 16:36
Picon

Re: OSG Shadow debugging

Hi,

This looks like you are using  LispSM vraiant based on computation of Draw 
Bounds around rendered scene. Draw Bounds means that result of Draw phase ie 
prerenderd depths of the scene is used to compute volume of scene which will 
receive shadows. Debug HUD in lower left corner displays two squares: 
shadow map and prererenderd  depth map of the scene. First square also 
contains projected silhouette of the initial rough bounds of scene volume 
(pink wireframe area) and final optimized draw bounds computed by scanning 
prerendered image (orange wireframe afar). Look at osgShadow example 
with --lispsm --debugHUD options to see how this debug outputs may look like 
when all goes well.
Since both debug squares in your screenshot are completely transparent and 
there is no orange wireframe, it looks like both shadow map and depth 
prerender map were not drawn at all.
Usually there are problems with  applying shadow map but in your case shadow 
map seems to be not rendered. Its hard to say by looking at screenshot what 
could be wrong here.  Have you tried other shadow techniques ? Maybe they 
are giving  better results ?

Cheers,
Wojtek Lewandowski

-----Oryginalna wiadomość----- 
From: Jaap van den Bosch
Sent: Friday, September 30, 2011 12:35 PM
To: osg-users <at> lists.openscenegraph.org
Subject: [osg-users] OSG Shadow debugging

Hi,
(Continue reading)

Joshua Cook | 1 Oct 2011 20:50
Picon

Re: osgText::Text heap corruption when using setText()

Ok, that sucked.  I got timed out while writing my reply and lost the entire post.  Lets try again.

Anyhow, got around to trying the code with the DYNAMIC enum and still had a crash.  It still looks like it is a
threading issue when updating the osgText object in a thread.  I can't give all of the code but it should be
easy enough to reproduce with the following snippet of code.  Please pretend I did a very excellent job
initializing everything.

Code:

class foo : public OpenThreads::Thread
{
public:
  void addText(std::string text);
  void run();
private:
  OpenThreads::Mutex mMutex;
  std::queue{osg::Geode*} mOutputHistoryQueue;
};

void foo::addText(std::string text)
{
  static unsigned int horizTextOffset = 20;
  static unsigned int lineSpacing = 5;
  static unsigned int vertTextOffset = 20;

  OpenThreads::ScopedLock<OpenThreads::Mutex>
          lock(mRenderMutex);

  // Get the first geode from the queue
  osg::Geode* textGeode = mOutputHistoryQueue.front();
(Continue reading)

Jean-Sébastien Guay | 1 Oct 2011 22:57
Gravatar

Re: osgText::Text heap corruption when using setText()

Hi Joshua,

> I hacked a fix into the code and found that it works quite well if there is a mutex locker blocking anything
that might change the text in osgText.cpp.

This has been discussed a lot in the past. You can't just run threads 
that will go call stuff in OSG at any time. You need to modify most 
things during the update traversal (which is essentially what your mutex 
ensures). This is indeed a hack.

What I would suggest instead, to prevent threads waiting for one another 
and to prevent you setting the text on your osgText object multiple 
times between two frames (which can be expensive in my experience, for 
something the user will never see) is to have a simple buffering scheme.

1. Your thread can put the text values you want to display in some 
holding area (which you would lock to ensure writing to it is threadsafe).
2. An update callback on your osgText object would go get the latest 
value in your holding area, compare it with the last value that was set, 
and only if it's different will set it on the osgText object.

Your osgText object still has to have DYNAMIC data variance, so that the 
viewer knows to hold back the next frame until that object's update is 
done. But the advantage of the above suggestion is really that two 
threads won't wait for each other, they will really hold the mutex (for 
your holding area) a minimum of time. Plus it's less intrusive on your 
main loop - you can encapsulate all that in a simple class, and if you 
need to add more text objects later, you don't need to add other mutexes 
or modify your main loop in any way.

(Continue reading)

Joshua Cook | 1 Oct 2011 23:36
Picon

Re: osgText::Text heap corruption when using setText()

Thanks for the reply.  As you can see in the code snippet, the text is changed in the render loop before I call
the frame() function.  I would have thought that all of the processing to update the text position and ready
the text to be rendered would complete before the updateText function completed.

This is the same as in my code here.  I take user input via a GUIEventHandler subclass and hold that until the
render loop calls for the user input.  So, all user input is considered before the frame() function is
called including the call to change text.  I guess this is what is confusing me; if I call
setText(std::string) before I call frame() shouldn't the osgText::Text object have all of its data
primed and ready before the drawing update occurs?

I apologize if the first sentence seems boorish but it was the best way I could put it without writing a
paragraph or two.

Josh

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

Jean-Sébastien Guay | 2 Oct 2011 01:48
Gravatar

Re: osgText::Text heap corruption when using setText()

Hi Joshua,

> So, all user input is considered before the frame() function is called including the call to change text.  I
guess this is what is confusing me; if I call setText(std::string) before I call frame() shouldn't the
osgText::Text object have all of its data primed and ready before the drawing update occurs?

Actually, it's the other way around. If you're running your viewer 
multithreaded, the draw for frame n-1 might still be running when the 
update for frame n starts. So you might be calling setText() right 
before the frame() for frame n, but the draw for frame n-1 is still 
running and so still trying to access the text object.

This is what setting the data variance to DYNAMIC prevents. Essentially, 
it holds back starting the next update (actually returning from the 
frame() function, indirectly) until all drawables flagged DYNAMIC have 
been dispatched, which means that once you get to updating your text 
object in frame n, frame n-1 will already have drawn your text, so it 
won't be trying to access the same object you're updating.

That's one problem, which you can fix by updating in your frame loop or 
having a mutex there, or by using an update callback as I described in 
my previous message. But the fact of trying to update your text from 
another thread (without any control over when that update happens) can't 
ever work, and using a mutex between that and the frame loop is IMHO a 
bad idea, which is why I suggesting using an intermediate data hold 
between your thread and an update callback that would do the actual 
updating. But that's up to you as to how you want to design your code... 
Once I've given you the technical reasons for why you were getting a 
crash, it's up to you to decide how to do things to avoid it.

(Continue reading)

Jaap van den Bosch | 3 Oct 2011 11:31
Picon

Re: OSG Shadow debugging

I already was suspicious of the empty right square. Looks like the shaders are not functioning somehow.
Here are some more results:

ShadowMap: Overall dimming, empty DebugHUD camera. See picture below
PSSM: Application crash...
ShadowVolume: Shadow pointing down: Blank screen. Other light direction: overblown colors. See picture below
SoftShadowMap: Light from above: no change. Light from an angle: Noise pattern as shadow. See picture below
Shadowtexture: blank screen. Primitives amount: 0 (somehow they have disappeared).

Wojciech, do you suspect a culprit responsible for these problems?

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

Attachments: 
http://forum.openscenegraph.org//files/softshadowmap_770.jpg
http://forum.openscenegraph.org//files/shadowvolume_532.jpg
http://forum.openscenegraph.org//files/shadowmap_183.jpg

Aurelien Albert | 3 Oct 2011 12:10
Picon
Favicon

Re: [osgPPU] Very basic example ?

Currently, I have this code.

I try to do a simple operation : invert Red and Green color components, but I get only a black screen.

Could anyone help me ?

Thanks.

Code:
// Configure Camera
p_osgCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
p_osgCamera->setViewport(new osg::Viewport(0,0,800,600));

// Create render texture
osg::Texture2D* textureColor = new osg::Texture2D();
textureColor->setDataVariance(osg::Object::DYNAMIC); 
textureColor->setNumMipmapLevels(0);
textureColor->setUseHardwareMipMapGeneration(false);
textureColor->setResizeNonPowerOfTwoHint(false);
textureColor->setTextureSize(800, 600);
textureColor->setInternalFormat(GL_RGBA);
textureColor->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
textureColor->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
textureColor->setInternalFormat(GL_RGBA16F_ARB);
textureColor->setSourceFormat(GL_RGBA);
textureColor->setSourceType(GL_FLOAT);

// Attach the texture and use it as the color buffer.
p_osgCamera->attach(osg::Camera::COLOR_BUFFER, textureColor);

(Continue reading)

Luca Vezzadini | 3 Oct 2011 12:13
Picon

Re: [osgPPU] Fix picture freeze for certain camera perspectives.

You're right, I've just tried a clean checkout from the trunk with OSG 3.0.1 and everything compiles files,
including Alexander's fix.
Thanks,
Luca

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


Gmane