Re: [osg-users] starting with stencil buffer to achieve ray tracing

2012-01-06 Thread Robert Osfield
Hi Andrey,

The OSG's intersection routines test the bounding spheres on the nodes
in the scene graph and will automatically stop traversing if the
intersector doesn't intersect with the subgraph.  This means there is
nothing to gain from trying avoid doing tests as the intersection
visitor will already do it for you.

Robert.

On 30 November 2011 17:53, Andrey Ibe xry...@gmail.com wrote:
 hello good people!

 i need a bit of advice ragarding some more advanced rendering techniques. 
 advanced for me, anyway.

 i am trying to build a simple ray tracing application on top of the basic 
 osgviewer program.

 to start off, i am trying to look at the loaded model and decide where to 
 cast rays, e.g. i don't want to cast any rays where the model would be 
 missed. i was thinking of using the stencil buffer and the first thing i need 
 is to draw say white pixels where the model is and say black pixels where the 
 model is not. then display this buffer as the frame buffer, you know what i 
 mean. is this possible? i remember doing something similar with GLUT long, 
 long time ago. //if i was able to do this kind of evaluation on the per-pixel 
 basis, i think, i could add some more advanced features like the color of the 
 first hit object (instead of white) and then maybe continue with some real 
 ray tracing, as i mention in the following lines.//

 later on, according to where the model would be hit (the white pixels), i 
 would cast rays using line intersectors. haven't thought about details here 
 yet.

 it would be kind of any of you if you could give me some pointers, especially 
 for the first part with the buffers that i am currently dealing with - is it 
 even possible? is my concept good? - for my knowledge in this area has gotten 
 very poor :( and i am also new to the osg.

 thank you very much in advance.

 Andrey

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





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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2012-01-06 Thread Andrey Ibe
Thank you, Robert.

I won't implement this then. i realized later that this might be just a minor 
optimization, if the Kd-Trees were working properly.

Cheers,
Andrey

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





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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2011-12-02 Thread Andrey Ibe
thank you filip! this might just be what i was looking for :)

but i'm getting OpenGL errors here ...

Code:

Warning: detected OpenGL error 'invalid operation' at end of SceneView::draw()
Warning: detected OpenGL error 'invalid operation' at start of State::apply()



the letter one keeps piling up as the app runs.

i wrote this code into the main function just before calling the optimizer and 
viewer.run();

Code:

osg::ref_ptrosg::Group rootNode = new osg::Group;
{
osg::Stencil* stencil = new osg::Stencil;
stencil-setFunction(osg::Stencil::ALWAYS, 1, ~0u);
stencil-setOperation(osg::Stencil::ZERO, osg::Stencil::ZERO, 
osg::Stencil::REPLACE);

osg::StateSet* ssb1 = new osg::StateSet();
ssb1-setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
ssb1-setAttributeAndModes(stencil, osg::StateAttribute::ON);

rootNode-setStateSet(ssb1);
}
rootNode-addChild(loadedModel.get());

viewer.getCamera()-setPostDrawCallback(new PostDrawCallback());



and then the callback

Code:


class PostDrawCallback : public osg::Camera::DrawCallback {

virtual void operator () (osg::RenderInfo renderInfo) const {
osg::ref_ptrosg::Image img = new osg::Image;

osg::View *view = renderInfo.getView();
int width = view-getCamera()-getViewport()-width();
int height = view-getCamera()-getViewport()-height();

img-readPixels(0, 0, width, height, GL_STENCIL_INDEX, 
GL_UNSIGNED_BYTE);
}
};



if i comment out the readpixels method, the errors do not apear.
what am i missing  [Question] 

 [Arrow]

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





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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2011-12-02 Thread Filip Arlet
Hi,
The most simple thing that could it be is this:
did you set up stencil buffer by calling 
osg::DisplaySettings::instance()-setMinimumNumStencilBits(); or creating 
context with stencil buffer?

Cheers,
Filip

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





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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2011-12-02 Thread Andrey Ibe
filip, that line of code solved the problem!  thank you so much!

now i have to bend the code i have a bit for my purpose.

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





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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2011-12-01 Thread Filip Arlet
Hi,

Use osg::Stencil on root node and set 1 where you draw (stencil func GL_ALWAYS).
Use post draw callback on your camera.
In callback save content of stencil buffer in osg::Image with readPixels() ... 
format GL_STENCIL_INDEX
Inspect image.

Cheers,
Filip

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





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


[osg-users] starting with stencil buffer to achieve ray tracing

2011-11-30 Thread Andrey Ibe
hello good people!

i need a bit of advice ragarding some more advanced rendering techniques. 
advanced for me, anyway.

i am trying to build a simple ray tracing application on top of the basic 
osgviewer program.

to start off, i am trying to look at the loaded model and decide where to 
cast rays, e.g. i don't want to cast any rays where the model would be missed. 
i was thinking of using the stencil buffer and the first thing i need is to 
draw say white pixels where the model is and say black pixels where the model 
is not. then display this buffer as the frame buffer, you know what i mean. is 
this possible? i remember doing something similar with GLUT long, long time 
ago. //if i was able to do this kind of evaluation on the per-pixel basis, i 
think, i could add some more advanced features like the color of the first hit 
object (instead of white) and then maybe continue with some real ray tracing, 
as i mention in the following lines.//

later on, according to where the model would be hit (the white pixels), i would 
cast rays using line intersectors. haven't thought about details here yet.

it would be kind of any of you if you could give me some pointers, especially 
for the first part with the buffers that i am currently dealing with - is it 
even possible? is my concept good? - for my knowledge in this area has gotten 
very poor :( and i am also new to the osg.

thank you very much in advance.

Andrey

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





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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2011-11-30 Thread Kim Bale
Hi Andrey,

Just a thought, but wouldn't this only work for orthographic projections?

I believe the traditional ray tracing approach to this problem is to use an
octree.

Kim.


On 30 November 2011 17:53, Andrey Ibe xry...@gmail.com wrote:

 hello good people!

 i need a bit of advice ragarding some more advanced rendering techniques.
 advanced for me, anyway.

 i am trying to build a simple ray tracing application on top of the basic
 osgviewer program.

 to start off, i am trying to look at the loaded model and decide where
 to cast rays, e.g. i don't want to cast any rays where the model would be
 missed. i was thinking of using the stencil buffer and the first thing i
 need is to draw say white pixels where the model is and say black pixels
 where the model is not. then display this buffer as the frame buffer, you
 know what i mean. is this possible? i remember doing something similar with
 GLUT long, long time ago. //if i was able to do this kind of evaluation on
 the per-pixel basis, i think, i could add some more advanced features like
 the color of the first hit object (instead of white) and then maybe
 continue with some real ray tracing, as i mention in the following lines.//

 later on, according to where the model would be hit (the white pixels), i
 would cast rays using line intersectors. haven't thought about details here
 yet.

 it would be kind of any of you if you could give me some pointers,
 especially for the first part with the buffers that i am currently dealing
 with - is it even possible? is my concept good? - for my knowledge in this
 area has gotten very poor :( and i am also new to the osg.

 thank you very much in advance.

 Andrey

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





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

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


Re: [osg-users] starting with stencil buffer to achieve ray tracing

2011-11-30 Thread Andrey Ibe
basically, what i want to do is to cast primary rays from the camera (for each 
pixel on the screen) into the scene using line intersectors. then i want to 
retrieve normal of the intersection to be able to compute the direction of the 
secondary ray and then to cast it the way i cast the primary rays. i want to 
continue recursively until a certain point. with the buffer i want to optimize 
the number of the primary rays casted.

ultimately, my goal is to render the scene normally using opengl pipeline 
into FBO,  then turn on ray tracing for certain objects/materials in the scene. 
i need to know whether this is possible and in what ways can osg help. what i 
see as the greatest advantage are the intersetors and the osg's ability to 
compute the intersections automatically.

i don't get the connection between the octree, which if i am not mistaken is a 
way of organizing the data or the scene, and my goal.
neither i get the reason why this buffer thing would not work on perspective 
projection, if that's what you meant.

thanks

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





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