Re: [osg-users] Problem setting a skydome

2008-07-17 Thread Alberto Luaces
Hi David,

El Miércoles 16 Julio 2008ES 21:41:49 David Spilling escribió:
 Alberto,

 I presume that your skydome has some sort of camera centred transform over
 it (as per osghangglide's example use); your code doesn't show it.

I haven't coded it yet, I wanted to have the near/far issue fixed first.

 osg::ClearNode* clearNode = new osg::ClearNode;
 
 clearNode-setRequiresClear(false);

 This is odd. If your camera is the first thing to draw (implied by
 PRE_RENDER) then something needs to be clearing the colour and depth
 buffer. In any case, you can use camera's setClearMask method to control
 this without needing a clearNode. For example
 camera-setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) clears
 everyhing, setClearMask(0) clears nothing.

Yes, you are right.

osg::TexEnv* te = new osg::TexEnv;

 te-setMode(osg::TexEnv::REPLACE);
 stateset-setTextureAttributeAndModes(0, te, osg::StateAttribute::ON);

 Slightly surprised to see this, but if your skydome needs it, then OK.

Well, I wanted to display texture real colour, not modified by any lighting 
calculation.

 stateset-setMode( GL_CULL_FACE, osg::StateAttribute::ON );
 
 osg::Depth* depth = new osg::Depth;
 depth-setFunction(osg::Depth::ALWAYS);
 depth-setRange(1.0,1.0);
 stateset-setAttributeAndModes(depth, osg::StateAttribute::ON );

 Again, not wrong (as the depth testing is always passed) but not really
 necessary, as you are ensuring that your skydome is drawn first. I would
 tend to prevent depth writing with
 osg::Depth* depth = new osg::Depth;
 depth-setWriteMask(false); // don't bother writing the depth buffer
 stateset-setAttributeAndModes(depth, osg::StateAttribute::ON );

 and also disable depth testing with
 stateSet-setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF)

Yes, I have deleted that block.

Finally and thanks to your valuable help, I have managed to get it working. 
Somehow I were mismatching ClearMask with ColorMask when I eliminated the 
ClearNode. Now I have the pre-render slave camera, which has its own near/far 
planes and then the real scene is rendered over it:

//Paint over the skydome
viewer.getCamera()-setClearMask(GL_DEPTH_BUFFER_BIT);

//Create the pre-render skydome camera
osg::Camera *camara = new osg::Camera;

camera-addChild(skydome.get());
camera-setRenderOrder(osg::Camera::PRE_RENDER);
camera-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

SceneRoot-addChild(camera);

osg::StateSet* stateset = n-getOrCreateStateSet();

osg::TexEnv* te = new osg::TexEnv;
te-setMode(osg::TexEnv::REPLACE);
stateset-setTextureAttributeAndModes(0, te, osg::StateAttribute::ON);

stateset-setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset-setMode( GL_CULL_FACE, osg::StateAttribute::ON );

Again, thank you very much for your advice :)

Regards,

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


Re: [osg-users] Problem setting a skydome

2008-07-16 Thread Alberto Luaces
David,

thank you very much for your help so far. What you say sounds sensible, 
however I think my implementation still has bugs, because it behaves 
differently on several computers (one works, the other don't). What I have so 
far is:

// root - camera - clearnode - skydome
//   |-- rest_of_scene

osg::Camera *camera = new osg::Camera;
osg::ClearNode* clearNode = new osg::ClearNode;

clearNode-setRequiresClear(false);
clearNode-addChild(SkydomeSubgraphNode.get());

camera-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera-addChild(clearNode);
camera-setRenderOrder(osg::Camera::PRE_RENDER);

root-addChild(camera);

osg::StateSet* stateset = SkydomeSubgraphNode-getOrCreateStateSet();
 
osg::TexEnv* te = new osg::TexEnv;
te-setMode(osg::TexEnv::REPLACE);
stateset-setTextureAttributeAndModes(0, te, osg::StateAttribute::ON);

stateset-setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset-setMode( GL_CULL_FACE, osg::StateAttribute::ON );

osg::Depth* depth = new osg::Depth;
depth-setFunction(osg::Depth::ALWAYS);
depth-setRange(1.0,1.0);   
stateset-setAttributeAndModes(depth, osg::StateAttribute::ON );

does something look weird to you?

Thank you,

Alberto

El Martes 15 Julio 2008ES 10:32:55 David Spilling escribió:
 Alberto,

  skydome-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR
 ).
 
   a class osg::Camera inherits from

 Sorry - missed a step. Put a Camera in above your skydome.

 A solution that comes to my mind is to use a pair of cameras, one rendering

  the skydome with the setting you said, DO_NOT_COMPUTE_NEAR_FAR, and the
  other
  rendering the rest of the scene.

 Exactly. That's what I do (although I control a bunch of other stuff in the
 camera, like projection matrix, in order to avoid the later issues).

 David


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


Re: [osg-users] Problem setting a skydome

2008-07-16 Thread David Spilling
Alberto,

I presume that your skydome has some sort of camera centred transform over
it (as per osghangglide's example use); your code doesn't show it.


osg::ClearNode* clearNode = new osg::ClearNode;

clearNode-setRequiresClear(false);


This is odd. If your camera is the first thing to draw (implied by
PRE_RENDER) then something needs to be clearing the colour and depth buffer.
In any case, you can use camera's setClearMask method to control this
without needing a clearNode. For example
camera-setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT) clears
everyhing, setClearMask(0) clears nothing.

   osg::TexEnv* te = new osg::TexEnv;
te-setMode(osg::TexEnv::REPLACE);
stateset-setTextureAttributeAndModes(0, te, osg::StateAttribute::ON);


Slightly surprised to see this, but if your skydome needs it, then OK.


stateset-setMode( GL_CULL_FACE, osg::StateAttribute::ON );

osg::Depth* depth = new osg::Depth;
depth-setFunction(osg::Depth::ALWAYS);
depth-setRange(1.0,1.0);
stateset-setAttributeAndModes(depth, osg::StateAttribute::ON );


Again, not wrong (as the depth testing is always passed) but not really
necessary, as you are ensuring that your skydome is drawn first. I would
tend to prevent depth writing with

osg::Depth* depth = new osg::Depth;
depth-setWriteMask(false); // don't bother writing the depth buffer
stateset-setAttributeAndModes(depth, osg::StateAttribute::ON );

and also disable depth testing with
stateSet-setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF)

I looked at my code and noticed that I also do
camera-setCullingMode(osg::CullSettings::NO_CULLING), but can't remember at
the moment whether it's relevant.

Lastly, what OSG version are you using?

Hope that helps,

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


Re: [osg-users] Problem setting a skydome

2008-07-15 Thread David Spilling
Alberto,



 skydome-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR).

  a class osg::Camera inherits from


Sorry - missed a step. Put a Camera in above your skydome.

A solution that comes to my mind is to use a pair of cameras, one rendering
 the skydome with the setting you said, DO_NOT_COMPUTE_NEAR_FAR, and the
 other
 rendering the rest of the scene.


Exactly. That's what I do (although I control a bunch of other stuff in the
camera, like projection matrix, in order to avoid the later issues).

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


Re: [osg-users] Problem setting a skydome

2008-07-14 Thread Alberto Luaces
David,

I appreciate your help a lot. However I have found a few problems:

El Domingo 13 Julio 2008ES 21:22:33 David Spilling escribió:
 Firstly, you need to prevent the CullVisitor from considering your skydome
 in it's autonear/far calculation. You can do this with
 skydome-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR).

I couldn't find any setComputeNearFarMode mode in osg::Node. I only found it 
in osg::CullSettings, a class that osg::Camera inherits from, so I'm unable 
to easily make OSG skip a certain node from the automatic near/far 
computation. Either I use it with all the scene or I disable it completely 
with DO_NOT_COMPUTE_NEAR_FAR.

I kept investigating and found that the code snippet I was perusing, the 
createSkyBox function at osgvertexprogram.cpp wasn't working at all. When I 
pasted that function directly into my program, the near clipping was still 
present. I think that the similar sizes of the osgvertexprogram.cpp program 
made that this behaviour went undetected for the example.

A solution that comes to my mind is to use a pair of cameras, one rendering 
the skydome with the setting you said, DO_NOT_COMPUTE_NEAR_FAR, and the other 
rendering the rest of the scene. However, I think having a pair of cameras 
just to skip the culling process for a node could be an overkill. Doesn't 
osg::Node::setCullingActive exists for this very reason?

Regards,

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


Re: [osg-users] Problem setting a skydome

2008-07-13 Thread David Spilling
Alberto,

Firstly, you need to prevent the CullVisitor from considering your skydome
in it's autonear/far calculation. You can do this with
skydome-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR).

You will also need to mimic being a long way away via, most simply by
drawing first (e.g. via a pre draw camera, or good control of your render
bins) with depth checking/writing disabled.

If you have expensive shaders on your skydome, you might want to draw last
to z depth = 1 (via stateset-setAttributeAndModes(new
osg::Depth(osg::Depth::ALWAYS, 1.0,1.0))). NB - you might need LEQUAL,
depending on how you cleared your zbuffer. Depending on what you are dong,
you might still also run into a problem in which your skydome is clipped, so
you'll need to control the projective camera; look at the DepthPartition
example if you need a way forward.

Hope that helps,

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


[osg-users] Problem setting a skydome

2008-07-11 Thread Alberto Luaces
Hello,

I'm having trouble setting a skydome into my scene. It is messing with the 
autocomputed near and far planes (the near plane goes too far, cutting near 
objects). In order to avoid it, I tried to disable culling for its subgraph 
and even giving it a ComputeBoundingSphereCallback that only generates 
invalid boundingSpheres, but the problem stays. Any ideas?

My invalid bounds generator:

class invalidBoundsCallback: public osg::Node::ComputeBoundingSphereCallback{
   public:
osg::BoundingSphere computeBound (const osg::Node ) const
{
   return osg::BoundingSphere();
 }
};

Setting of the subgraph containing the skydome (group-SkynodeGeode):

osg::ref_ptrosg::Node n = osgDB::readNodeFile( skydome);
n-setCullingActive(false);
n-setComputeBoundingSphereCallback(new invalidBoundsCallback);



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