Re: [osg-users] Resizing FBO camera while rendering

2018-10-02 Thread Rômulo Cerqueira


> Is it only the FBO that is forcing you to do this?


Yes.

Do you have any tip how can I solve this issue?

I found similar problems into links below, but I could not have the same 
success.

https://groups.google.com/forum/#!topic/osg-users/Oxb9QF8Myyo
https://groups.google.com/forum/#!topic/osg-users/ScUN5VSj6W8

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





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


Re: [osg-users] Resizing FBO camera while rendering

2018-10-02 Thread Rômulo Cerqueira
Hi,


> So you are setting a whole new graphics context and associated data on
> each resize?


Yes, Robert.

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Resizing FBO camera while rendering

2018-10-02 Thread Rômulo Cerqueira
Hi Robert,

I use the method setupViewer() "to resize" the FBO as well (by instantiating 
the viewer, camera, texture and callback again). This approach was the best way 
so far to minimize this problem.
 
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Resizing FBO camera while rendering

2018-10-02 Thread Rômulo Cerqueira
Hi Robert,

I use the method setupViewer() "to resize" the FBO as well (by instantiating 
the viewer, camera, texture and callback again). This approach was the best way 
so far to minimize this problem.
 
... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Resizing FBO camera while rendering

2018-10-01 Thread Rômulo Cerqueira
Hi,

I have rendered a FBO camera to image by using a callback (as seen in the code 
below), however some OpenGL warnings/erros are raised when I resize at runtime 
by setupViewer() method. I debugged the code by using 


Code:
export OSG_GL_ERROR_CHECKING=ON 



and got the following error:


Code:
Warning: detected OpenGL error 'invalid operation' after applying attribute 
Viewport 0x7fb35406e500



How can I properly do the resizing of my FBO camera?



Code:
// create a RTT (render to texture) camera
osg::Camera *ImageViewerCaptureTool::createRTTCamera(osg::Camera* cam, 
osg::Camera::BufferComponent buffer, osg::Texture2D *tex, osg::GraphicsContext 
*gfxc)
{
osg::ref_ptr camera = cam;
camera->setClearColor(osg::Vec4(0, 0, 0, 1));
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->setRenderOrder(osg::Camera::PRE_RENDER, 0);
camera->setViewport(0, 0, tex->getTextureWidth(), tex->getTextureHeight());
camera->setGraphicsContext(gfxc);
camera->setDrawBuffer(GL_FRONT);
camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->attach(buffer, tex);
return camera.release();
}

// create float textures to be rendered in FBO
osg::Texture2D* ImageViewerCaptureTool::createFloatTexture(uint width, uint 
height)
{
osg::ref_ptr tex2D = new osg::Texture2D;
tex2D->setTextureSize( width, height );
tex2D->setInternalFormat( GL_RGB32F_ARB );
tex2D->setSourceFormat( GL_RGBA );
tex2D->setSourceType( GL_FLOAT );
tex2D->setResizeNonPowerOfTwoHint( false );
tex2D->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR );
tex2D->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
return tex2D.release();
}

void ImageViewerCaptureTool::setupViewer(uint width, uint height, double fovY)
{
// set graphics contexts
osg::ref_ptr traits = new 
osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = width;
traits->height = height;
traits->pbuffer = true;
traits->readDISPLAY();
osg::ref_ptr gfxc = 
osg::GraphicsContext::createGraphicsContext(traits.get());

// set the main camera
_viewer = new osgViewer::Viewer;
osg::ref_ptr tex = createFloatTexture(width, height);
osg::ref_ptr cam = createRTTCamera(_viewer->getCamera(), 
osg::Camera::COLOR_BUFFER0, tex, gfxc);
cam->setProjectionMatrixAsPerspective(osg::RadiansToDegrees(fovY), (width * 
1.0 / height), 0.1, 1000);

// render texture to image
_capture = new WindowCaptureScreen(gfxc, tex);
cam->setFinalDrawCallback(_capture);
}

osg::ref_ptr 
ImageViewerCaptureTool::grabImage(osg::ref_ptr node)
{
// set the current node
_viewer->setSceneData(node);

// if the view matrix is invalid (NaN), use the identity
if (_viewer->getCamera()->getViewMatrix().isNaN())
_viewer->getCamera()->setViewMatrix(osg::Matrixd::identity());

// grab the current frame
_viewer->frame();
return _capture->captureImage();
}


WindowCaptureScreen METHODS


WindowCaptureScreen::WindowCaptureScreen(osg::ref_ptr 
gfxc, osg::Texture2D* tex) {
_mutex = new OpenThreads::Mutex();
_condition = new OpenThreads::Condition();
_image = new osg::Image();

// checks the GraficContext from the camera viewer
if (gfxc->getTraits()) {
_tex = tex;
int width = gfxc->getTraits()->width;
int height = gfxc->getTraits()->height;
_image->allocateImage(width, height, 1, GL_RGBA, GL_FLOAT);
}
}

WindowCaptureScreen::~WindowCaptureScreen() {
delete (_condition);
delete (_mutex);
}

osg::ref_ptr WindowCaptureScreen::captureImage() {
//wait to finish the capture image in call back
_condition->wait(_mutex);
return _image;
}

void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {
osg::ref_ptr gfxc = 
renderInfo.getState()->getGraphicsContext();

if (gfxc->getTraits()) {
_mutex->lock();

// read the color buffer as 32-bit floating point
renderInfo.getState()->applyTextureAttribute(0, _tex);
_image->readImageFromCurrentTexture(renderInfo.getContextID(), true, 
GL_FLOAT);

// grants the access to image
_condition->signal();
_mutex->unlock();
}
}



... 

Thanks in advance,

Cheers,
Rômulo

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





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


Re: [osg-users] Read Image from RTT

2018-09-27 Thread Rômulo Cerqueira
Solved the problem!

Perhaps readImageFromCurentTexture() works only with osg::ref_ptr 
instead of osg::Image*.
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Read Image from RTT

2018-09-27 Thread Rômulo Cerqueira
Hi Martin,

I never faced with this problem. Do you have some tip to solve it?
... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Read Image from RTT

2018-09-27 Thread Rômulo Cerqueira
Hi,

I have tried to read image from RTT (where the image is "not attached", but 
available on buffer) using a osg::Camera::DrawCallback, the compilation is 
working, however the executable brings me a segmentation fault during image 
rendering. How can I solve this?



Code:
WindowCaptureScreen::WindowCaptureScreen(osg::ref_ptr 
gfxc, osg::Texture2D* tex) {
_mutex = new OpenThreads::Mutex();
_condition = new OpenThreads::Condition();
_image = new osg::Image();

// checks the GraficContext from the camera viewer
if (gfxc->getTraits()) {
_tex = tex;
int width = gfxc->getTraits()->width;
int height = gfxc->getTraits()->height;
_image->allocateImage(width, height, 1, GL_RGBA, GL_FLOAT);
}
}

WindowCaptureScreen::~WindowCaptureScreen() {
delete (_condition);
delete (_mutex);
}

osg::ref_ptr WindowCaptureScreen::captureImage() {
//wait to finish the capture image in call back
_condition->wait(_mutex);

return _image;
}

void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {
osg::ref_ptr gfxc = 
renderInfo.getState()->getGraphicsContext();

if (gfxc->getTraits()) {
_mutex->lock();

// read the color buffer as 32-bit floating point
renderInfo.getState()->applyTextureAttribute(0, _tex);

// THE PROGRAM CRASHES HERE
_image->readImageFromCurrentTexture(renderInfo.getContextID(), true, 
GL_FLOAT);

// grants the access to image
_condition->signal();
_mutex->unlock();
}
}




Output from GDB:


Code:
#0  0xff88 in ?? ()
#1  0x7fffef1ee39d in normal_depth_map::WindowCaptureScreen::operator() 
(this=0x7fffb53ee7a0, renderInfo=...)
at 
/home/romulo/dev/sonarsim/simulation/normal_depth_map/src/ImageViewerCaptureTool.cpp:158
#2  0x7fffebb43b10 in osgUtil::RenderStage::draw(osg::RenderInfo&, 
osgUtil::RenderLeaf*&) ()
   from target:/usr/lib/x86_64-linux-gnu/libosgUtil.so.100
#3  0x7fffebb4bdb7 in osgUtil::SceneView::draw() () from 
target:/usr/lib/x86_64-linux-gnu/libosgUtil.so.100
#4  0x7fffec31c03f in osgViewer::Renderer::draw() () from 
target:/usr/lib/x86_64-linux-gnu/libosgViewer.so.100
#5  0x7fffef557d49 in osg::GraphicsContext::runOperations() ()
   from target:/usr/lib/x86_64-linux-gnu/libosg.so.100
#6  0x7fffef5a7bbf in osg::OperationThread::run() () from 
target:/usr/lib/x86_64-linux-gnu/libosg.so.100
#7  0x7fffef5596f8 in osg::GraphicsThread::run() () from 
target:/usr/lib/x86_64-linux-gnu/libosg.so.100
#8  0x7fffecbd06c8 in OpenThreads::ThreadPrivateActions::StartThread(void*) 
()
   from target:/usr/lib/x86_64-linux-gnu/libOpenThreads.so.20
#9  0x760246ba in start_thread (arg=0x7fffa7efe700) at 
pthread_create.c:333
#10 0x7130f41d in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:109




Thanks in advance,

Cheers,
Rômulo

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





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


Re: [osg-users] Problem with output - OSG/Shader

2018-08-05 Thread Rômulo Cerqueira
Hi Johny,

I would like to draw what I want... the red was just an example.

My main goal is to simulate the reverberation phenomena using rasterization 
(for the first reflection) + ray tracing (for the second reflection). I would 
like to output the surface of reflected scenes, which are always not visible 
from the viewpoint.

... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Problem with output - OSG/Shader

2018-08-04 Thread Rômulo Cerqueira
Hi,

I would like to write the output/buffer of fragment shader to texture (RTT) as 
I wish (e.g. all red), however this result is depending of the model's shapes 
visible in the scene. How can I proceed with this correctly?

Follow below my minimal source code and the results.

Thanks in advance!

Expected: 
[Image: http://forum.openscenegraph.org/files/expected_964.jpg ] 

Current: 
[Image: http://forum.openscenegraph.org/files/current_875.jpg ] 


Code:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static const char *mrtVertSource = {
"#version 130\n"
"out vec3 worldNormal;\n"
"void main(void)\n"
"{\n"
"   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
"   worldNormal = normalize(gl_NormalMatrix * gl_Normal);\n"
"   gl_TexCoord[0] = gl_MultiTexCoord0;\n"
"}\n"};

static const char *mrtFragSource = {
"#version 130\n"
"in vec3 worldNormal;\n"
"void main(void)\n"
"{\n"
"   gl_FragData[0] = vec4(worldNormal, 0.0);\n"
"}\n"};

osg::Geode *createScreenQuad(float width, float height, float scale = 1.0f)
{
osg::Geometry *geom = osg::createTexturedQuadGeometry(
osg::Vec3(), osg::Vec3(width, 0.0f, 0.0f), osg::Vec3(0.0f, height, 
0.0f),
0.0f, 0.0f, width * scale, height * scale);
osg::ref_ptr quad = new osg::Geode;
quad->addDrawable(geom);

int values = osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED;
quad->getOrCreateStateSet()->setAttribute(
new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, 
osg::PolygonMode::FILL), values);
quad->getOrCreateStateSet()->setMode(GL_LIGHTING, values);
return quad.release();
}

osg::Camera *createRTTCamera(osg::Camera::BufferComponent buffer, osg::Texture 
*tex)
{
osg::ref_ptr camera = new osg::Camera;
camera->setClearColor(osg::Vec4());
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setViewport(0, 0, tex->getTextureWidth(), tex->getTextureHeight());
camera->attach(buffer, tex);

return camera.release();
}

osg::Camera *createHUDCamera(double left, double right, double bottom, double 
top)
{
osg::ref_ptr camera = new osg::Camera;
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::POST_RENDER);
camera->setAllowEventFocus(false);
camera->setProjectionMatrix(osg::Matrix::ortho2D(left, right, bottom, top));
camera->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
return camera.release();
}

osg::TextureRectangle *createFloatTexture(uint w, uint h)
{
osg::ref_ptr tex2D = new osg::TextureRectangle;
tex2D->setTextureSize(w, h);
tex2D->setInternalFormat(GL_RGB32F_ARB);
tex2D->setSourceFormat(GL_RGBA);
tex2D->setSourceType(GL_FLOAT);
tex2D->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
tex2D->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
return tex2D.release();
}

int main(int argc, char **argv)
{
osg::ref_ptr scene = 
osgDB::readNodeFile("/home/romulo/Tools/OpenSceneGraph-Data/cow.osg");

unsigned int w = 800, h = 800;
osg::Texture *normalTex = createFloatTexture(w, h);

osg::ref_ptr rttCamera = 
createRTTCamera(osg::Camera::COLOR_BUFFER0, normalTex);
rttCamera->addChild(scene.get());

osg::ref_ptr program = new osg::Program;
program->addShader(new osg::Shader(osg::Shader::VERTEX, mrtVertSource));
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, mrtFragSource));
rttCamera->getOrCreateStateSet()->setAttributeAndModes(program.get(), 
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
rttCamera->getOrCreateStateSet()->addUniform(new osg::Uniform("defaultTex", 
0));

osg::ref_ptr hudCamera = createHUDCamera(0.0, 1.0, 0.0, 1.0);
hudCamera->addChild(createScreenQuad(1.f, 1.0f, w));
hudCamera->getOrCreateStateSet()->setTextureAttributeAndModes(0, normalTex);

osg::ref_ptr root = new osg::Group;
root->addChild(rttCamera.get());
root->addChild(hudCamera.get());
root->addChild(scene.get());

osgViewer::Viewer viewer;
viewer.setUpViewInWindow(0, 0, w, h);
viewer.setSceneData(root.get());
return viewer.run();
}




Rômulo

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



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


Re: [osg-users] Problems with MRT

2018-05-18 Thread Rômulo Cerqueira
Hi Sebastian and Julien,

thanks for your comments. I tried your suggestions without success, even output 
image in different formats (BMP, PNG, TIFF...). It is funny, because I can 
handle the image data as GL_FLOAT, but the image is only properly written in 
disk as UNSIGNED_BYTE.

At this moment, this process is not more necessary to me, however a work around 
can help more people.

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Problems with MRT

2018-05-15 Thread Rômulo Cerqueira
Hi,

just updating my progress:

What have I got so far? 
[ ✓ ] Allow rendering for color or depth buffers on the same camera;
[ ✓ ] Display only the color buffer in the post render camera;
[ ✓ ] Read color or depth buffer in the final draw callback;
[ ✗ ] Write collected image (color or depth) in disk - only images as 
GL_UNSIGNED_BYTE, instead of GL_FLOAT.

I changed the buffer reader in my callback (readImageFromCurrentTexture() 
instead of readPixels()), however I still got problems when I render floating 
textures...

This is my current code:


Code:
// OSG includes
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct SnapImage : public osg::Camera::DrawCallback {
SnapImage(osg::GraphicsContext* gc, osg::Texture2D* tex1, osg::Texture2D* 
tex2 ) {
if (gc->getTraits()) {
_texColor = tex1;
_texDepth = tex2;
}
}

virtual void operator () (osg::RenderInfo& renderInfo) const {
// color buffer
renderInfo.getState()->applyTextureAttribute(0, _texColor);
osg::ref_ptr mColor = new osg::Image();
mColor->readImageFromCurrentTexture(renderInfo.getContextID(), true, 
GL_UNSIGNED_BYTE);
osgDB::ReaderWriter::WriteResult wrColor = 
osgDB::Registry::instance()->writeImage(*mColor, "./Test-color.png", NULL);
if (!wrColor.success()) {
osg::notify(osg::WARN) << "Color image: failed! (" << 
wrColor.message() << ")" << std::endl;
}

// depth buffer
renderInfo.getState()->applyTextureAttribute(0, _texDepth);
osg::ref_ptr mDepth = new osg::Image();
mDepth->readImageFromCurrentTexture(renderInfo.getContextID(), true, 
GL_UNSIGNED_BYTE);
osgDB::ReaderWriter::WriteResult wrDepth = 
osgDB::Registry::instance()->writeImage(*mDepth, "./Test-depth.png", NULL);
if (!wrDepth.success()) {
osg::notify(osg::WARN) << "Depth image: failed! (" << 
wrDepth.message() << ")" << std::endl;
}
}
osg::ref_ptr _texColor;
osg::ref_ptr _texDepth;
};

osg::Camera* setupMRTCamera( osg::ref_ptr camera, 
std::vector& attachedTextures, int w, int h ) {
camera->setClearColor( osg::Vec4() );
camera->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
camera->setRenderOrder( osg::Camera::PRE_RENDER, 0 );
camera->setViewport( 0, 0, w, h );

osg::Texture2D* tex = new osg::Texture2D;
tex->setTextureSize( w, h );
tex->setInternalFormat( GL_RGB );
tex->setSourceFormat( GL_RGBA );
tex->setSourceType( GL_UNSIGNED_BYTE );
tex->setResizeNonPowerOfTwoHint( false );
tex->setFilter( osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR );
tex->setFilter( osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR );
attachedTextures.push_back( tex );
camera->attach( osg::Camera::COLOR_BUFFER, tex );

tex = new osg::Texture2D;
tex->setTextureSize(w,h);
tex->setSourceFormat(GL_DEPTH_COMPONENT);
tex->setInternalFormat(GL_DEPTH_COMPONENT);
tex->setSourceType(GL_UNSIGNED_BYTE);
attachedTextures.push_back( tex );
camera->attach( osg::Camera::DEPTH_BUFFER, tex );

return camera.release();
}


int main() {
osg::ref_ptr< osg::Group > root( new osg::Group );
root->addChild( osgDB::readNodeFile( 
"/home/romulo/Tools/OpenSceneGraph-Data/cow.osg" ) );
unsigned int winW = 800;
unsigned int winH = 600;

osgViewer::Viewer viewer;
viewer.setUpViewInWindow( 0, 0, winW, winH );
viewer.setSceneData( root.get() );
viewer.realize();

// setup MRT camera
std::vector attachedTextures;
osg::Camera* mrtCamera ( viewer.getCamera() );
setupMRTCamera( mrtCamera, attachedTextures, winW, winH );

// set RTT textures to quad
osg::Geode* geode( new osg::Geode );
geode->addDrawable( osg::createTexturedQuadGeometry(
osg::Vec3(-1,-1,0), osg::Vec3(2.0,0.0,0.0), osg::Vec3(0.0,2.0,0.0)) );
geode->getOrCreateStateSet()->setTextureAttributeAndModes( 0, 
attachedTextures[0] );
geode->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );
geode->getOrCreateStateSet()->setMode( GL_DEPTH_TEST, 
osg::StateAttribute::OFF );

// configure postRenderCamera to draw fullscreen textured quad
osg::Camera* postRenderCamera( new osg::Camera );
postRenderCamera->setClearMask( 0 );
postRenderCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER, 
osg::Camera::FRAME_BUFFER );
postRenderCamera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
postRenderCamera->setRenderOrder( osg::Camera::POST_RENDER );
// postRenderCamera->setViewMatrix( osg::Matrixd::identity() );
// postRenderCamera->setProjectionMatrix( osg::Matrixd::identity() );
postRenderCamera->addChild( geode );
root->addChild(postRenderCamera);

// setup the callback
SnapImage* finalDrawCallback = new 

Re: [osg-users] Problems with MRT

2018-05-14 Thread Rômulo Cerqueira
Folks!

Any tips here?

Thanks in advance,

Rômulo

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





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


[osg-users] MRT doubts

2018-05-12 Thread Rômulo Cerqueira
)->setTextureAttributeAndModes( 0, 
attachedTextures[0] );
geode->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );
geode->getOrCreateStateSet()->setMode( GL_DEPTH_TEST, 
osg::StateAttribute::OFF );

// configure postRenderCamera to draw fullscreen textured quad
osg::Camera* postRenderCamera( new osg::Camera );
postRenderCamera->setClearMask( 0 );
postRenderCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER, 
osg::Camera::FRAME_BUFFER );
postRenderCamera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
postRenderCamera->setRenderOrder( osg::Camera::POST_RENDER );
postRenderCamera->setViewMatrix( osg::Matrixd::identity() );
postRenderCamera->setProjectionMatrix( osg::Matrixd::identity() );
postRenderCamera->addChild( geode );
root->addChild(postRenderCamera);

// setup the callback
SnapImage* finalDrawCallback = new 
SnapImage(viewer.getCamera()->getGraphicsContext());
mrtCamera->setFinalDrawCallback(finalDrawCallback);

return (viewer.run());
}




Thanks in advance,

Rômulo Cerqueira

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





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


Re: [osg-users] FBO-RTT doubt

2018-05-12 Thread Rômulo Cerqueira
Hi Robert,

thanks for your reply. Nowadays this topic is outdated. I will create a new 
topic in OSG forum and explain better the scenario. Thanks for the tip.
... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] FBO-RTT doubt

2018-04-30 Thread Rômulo Cerqueira
Hi Folks!

I have developed a GPU-based underwater imaging sonar simulator for real-time 
applications (for further details please refer to my last paper 
(http://https://www.sciencedirect.com/science/article/pii/S0097849317301371)) 
using OSG + GLSL. The missing part is the reverberation effect, that can be 
represented by a ray-triangle intersection algorithm. This work uses 
precomputed information (normal and depth) during rasterization pipeline using 
shaders in order to calculate the simulated sonar data, however this way is 
restricted to primary reflections. To address the secondary reflections, I need 
to build a hybrid pipeline (rasterization and ray-triangle intersection), where 
the data computed in first shader (rasterization) will be used in second one 
(ray-triangle intersection) to produce the final precomputed information 
(normal and depth from both reflections). Once the data computed on fragment 
shader is not pixel level yet (they are ¨fragments¨), it is necessary to use 
the 
 FBO-RTT to allow two shader passes:

FIRST PASS
-> output: primary reflections (as RTT texture)
SECOND PASS
-> output: RTT texture + secondary reflections (as fragment out vec4 data)

My main C++ classes are: NormaDepthMap, responsible by OSG node and shaders; 
and ImageViewCaptureTool, where the camera with GraphicsContext is configured 
(e.g. resolution and field-of-view) and the scene/shader image is grabbed from 
NormalDepthMap. I investigated a lot the related OSG examples (osgdeferred, 
osgmultiplerendertargets, osgprerender and stereomatch) and I`m aware how the 
FBO-RTT works, where each RTT texture needs one PRE_RENDER camera. My question 
is: how can I set the FBO-RTT setup for my scenario, once I have the main 
camera defined at ImageViewCaptureTool and the shaders at NormalDepthMap?

I already have the source codes to implement the RTT (from osgCookbook):
https://github.com/openscenegraph/OpenSceneGraph/blob/master/examples/osgdeferred/osgdeferred.cpp#L161

Source codes:
- NormalDepthMap.hpp:   
https://github.com/Brazilian-Institute-of-Robotics/simulation-normal_depth_map/blob/master/src/NormalDepthMap.hpp
- NormalDepthMap.cpp:   
https://github.com/Brazilian-Institute-of-Robotics/simulation-normal_depth_map/blob/master/src/NormalDepthMap.cpp
- ImageViewerCaptureTool.hpp:   
https://github.com/Brazilian-Institute-of-Robotics/simulation-normal_depth_map/blob/master/src/ImageViewerCaptureTool.hpp
- ImageViewerCaptureTool.cpp:   
https://github.com/Brazilian-Institute-of-Robotics/simulation-normal_depth_map/blob/master/src/ImageViewerCaptureTool.cpp

Thanks in advance,

Rômulo Cerqueira[/url]

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





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


Re: [osg-users] Cheaper way to implement rendering-to-texture and post-processing pipeline?

2018-04-23 Thread Rômulo Cerqueira
Folks,

is there any example to implement FBO without cameras? Where can I find it?

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] osg::Vec3Array as uniform to Shader

2018-03-05 Thread Rômulo Cerqueira
Thanks, Robert.
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] osg::Vec3Array as uniform to Shader

2018-03-03 Thread Rômulo Cerqueira
Hi,

I found a way to solve this problem: converting the array to texture.

Follows an example:


Code:

osg::ref_ptr image = new osg::Image;
image->setImage(myVec3Array->size(), 1, 1, GL_RGBA8, GL_RGBA, GL_FLOAT, 
(unsigned char*) [0], osg::Image::NO_DELETE);

osg::ref_ptr texture = new osg::Texture2D;
texture->setImage(image);

...

ss->addUniform( new osg::Uniform("vertexMap", texture) );




... 

Thank you!

Cheers,
Rômulo[/code]

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





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


[osg-users] osg::Vec3Array as uniform to Shader

2018-03-03 Thread Rômulo Cerqueira
Hi,

can I pass a osg::Vec3Array as uniform to Shader?

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Normal Mapping using Dynamic Cubemap

2018-02-03 Thread Rômulo Cerqueira
Hi Sebastian,

thanks for all comments. Do you know how I can manage these six faces of 
cubemap? I can handle all faces using one texture or I need to create six 
textures?

I really need help with this...It's essential to my project.
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Normal Mapping using Dynamic Cubemap

2018-02-03 Thread Rômulo Cerqueira
Hi Sebastian,

I have managed the normal and depth using MRT-FBO. I changed the osgdeferred 
example to display the normal (blue) and depth (green). Now I need to repeat 
this process for each six faces of cubemap.

I have a question: to capture the normal/depth data, as seen in Figure, I used 
the eye space. For dynamic cubemap, I need to use the eye space or world space?
... 

Thank you!

Cheers,
Rômulo

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




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


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


Re: [osg-users] Normal Mapping using Dynamic Cubemap

2018-01-29 Thread Rômulo Cerqueira
Hi,

I still have problems to manage the normal view from reflected objects (using 
dynamic cubemaps technique). Please any tip here? 
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Normal Mapping using Dynamic Cubemap

2018-01-11 Thread Rômulo Cerqueira
Moreover, I installed the openscenegraph-examples package (using Ubuntu), 
however the osgdeferred example does not contain all complementary data (i.e. 
data/shaders/simpleShader01, data/shaders/colorTextureShader and 
data/shaders/lightingPass).

I could not find these shader codes in 
https://github.com/openscenegraph/OpenSceneGraph-Data.

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Normal Mapping using Dynamic Cubemap

2018-01-11 Thread Rômulo Cerqueira
Hi Sebastian,

I believe copying and pasting code is not the case here. I have read a lot 
about MRT, RTT and FBO and debugged some source code examples (including your 
hints), however I still have problems in my side to compute the normal.

So let's go to new doubts:
- In Kapelko's example, if I disable the bumpmap use, why is the normal still 
computed by using the TBN matrix (please see [0])? Why the nn is set to 
vec3(1.0)? In addition, why one of the walls does not contains data (green 
channel is missing?) - please see attachment?


[0] 
https://bitbucket.org/kornerr/osg-deferred-shading/src/2b2f5532f41c305b31c46467291281388657b392/pass2.frag?at=default=file-view-default#pass2.frag-20
- 
... 

Thank you!

Cheers,
Rômulo

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




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


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


Re: [osg-users] Normal Mapping using Dynamic Cubemap

2017-12-26 Thread Rômulo Cerqueira
Hi Roberto and Sebastian,

sorry for my duplicated post. I need to render the depth/normal surface to 
texture of reflected objects by cube maps.

Until this moment, I got the depth data. Could you help me to get the normal 
data too (as single channel data). My current code follows below:

C++ code:

Code:

// OSG includes
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

// C++ includes
#include 

#define SHADER_PATH_FRAG "normal_depth_map/shaders/normalDepthMap.frag"
#define SHADER_PATH_VERT "normal_depth_map/shaders/normalDepthMap.vert"

#define BOOST_TEST_MODULE "DynamicCubeMap_test"

using namespace osg;

unsigned int numTextures = 6;

enum TextureUnitTypes {
TEXTURE_UNIT_DIFFUSE,
TEXTURE_UNIT_NORMAL,
TEXTURE_UNIT_CUBEMAP
};

osg::ref_ptr _create_scene() {
osg::ref_ptr scene = new osg::Group;

osg::ref_ptr geode = new osg::Geode;
scene->addChild(geode.get());

const float radius = 0.8f;
const float height = 1.0f;
osg::ref_ptr shape;

// sphere
shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(-3.0f, 0.0f, 
0.0f), radius));
shape->setColor(osg::Vec4(0.6f, 0.8f, 0.8f, 1.0f));
geode->addDrawable(shape.get());

// box
shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(3.0f, 0.0f, 0.0f), 2 
* radius));
shape->setColor(osg::Vec4(0.4f, 0.9f, 0.3f, 1.0f));
geode->addDrawable(shape.get());

// cone
shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 
-3.0f), radius, height));
shape->setColor(osg::Vec4(1.0f, 0.3f, 0.3f, 1.0f));
geode->addDrawable(shape.get());

// cylinder
shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, 3.0f), 2* 
radius));
shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f));
geode->addDrawable(shape.get());

return scene;
}

osg::NodePath createReflector() {
Geode* node = new Geode;
const float radius = 0.8f;
ref_ptr hints = new TessellationHints;
hints->setDetailRatio(2.0f);
ShapeDrawable* shape = new ShapeDrawable(new Sphere(Vec3(0.0f, 0.0f, 0.0f), 
radius * 1.5f), hints.get());
shape->setColor(Vec4(0.8f, 0.8f, 0.8f, 1.0f));
node->addDrawable(shape);

osg::NodePath nodeList;
nodeList.push_back(node);

return nodeList;
}

class UpdateCameraAndTexGenCallback : public osg::NodeCallback
{
public:

typedef std::vector< osg::ref_ptr >  CameraList;

UpdateCameraAndTexGenCallback(osg::NodePath& reflectorNodePath, 
CameraList& Cameras):
_reflectorNodePath(reflectorNodePath),
_Cameras(Cameras)
{
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
// first update subgraph to make sure objects are all moved into 
position
traverse(node,nv);

// compute the position of the center of the reflector subgraph
osg::Matrixd worldToLocal = 
osg::computeWorldToLocal(_reflectorNodePath);
osg::BoundingSphere bs = _reflectorNodePath.back()->getBound();
osg::Vec3 position = bs.center();

typedef std::pair ImageData;
const ImageData id[] =
{
ImageData( osg::Vec3( 1,  0,  0), osg::Vec3( 0, -1,  0) ), // +X
ImageData( osg::Vec3(-1,  0,  0), osg::Vec3( 0, -1,  0) ), // -X
ImageData( osg::Vec3( 0,  1,  0), osg::Vec3( 0,  0,  1) ), // +Y
ImageData( osg::Vec3( 0, -1,  0), osg::Vec3( 0,  0, -1) ), // -Y
ImageData( osg::Vec3( 0,  0,  1), osg::Vec3( 0, -1,  0) ), // +Z
ImageData( osg::Vec3( 0,  0, -1), osg::Vec3( 0, -1,  0) )  // -Z
};

for(unsigned int i = 0; i < 6 && i < _Cameras.size(); ++i) {
osg::Matrix localOffset;

localOffset.makeLookAt(position,position+id[i].first,id[i].second);

osg::Matrix viewMatrix = worldToLocal*localOffset;

_Cameras[i]->setReferenceFrame(osg::Camera::ABSOLUTE_RF);

_Cameras[i]->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,1.0);
_Cameras[i]->setViewMatrix(viewMatrix);
}
}

protected:

virtual ~UpdateCameraAndTexGenCallback() {}

osg::NodePath   _reflectorNodePath;
CameraList  _Cameras;
};

class TexMatCullCallback : public osg::NodeCallback
{
public:

TexMatCullCallback(osg::TexMat* texmat):
_texmat(texmat)
{
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
// first update subgraph to make sure objects are all moved into 
position
traverse(node,nv);

osgUtil::CullVisitor* cv = dynamic_cast(nv);
if (cv)
{
osg::Quat q = 

Re: [osg-users] dynamic cube map

2017-12-19 Thread Rômulo Cerqueira
Hi,

I got the depth data from reflected objects. I needed to render the depth 
buffer to texture. Follows my update code:

C++ code:

Code:

// OSG includes
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

// C++ includes
#include 

#define SHADER_PATH_FRAG "normal_depth_map/shaders/normalDepthMap.frag"
#define SHADER_PATH_VERT "normal_depth_map/shaders/normalDepthMap.vert"

#define BOOST_TEST_MODULE "DynamicCubeMap_test"

using namespace osg;

unsigned int numTextures = 6;

enum TextureUnitTypes {
TEXTURE_UNIT_DIFFUSE,
TEXTURE_UNIT_NORMAL,
TEXTURE_UNIT_CUBEMAP
};

osg::ref_ptr _create_scene() {
osg::ref_ptr scene = new osg::Group;

osg::ref_ptr geode = new osg::Geode;
scene->addChild(geode.get());

const float radius = 0.8f;
const float height = 1.0f;
osg::ref_ptr shape;

// sphere
shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(-3.0f, 0.0f, 
0.0f), radius));
shape->setColor(osg::Vec4(0.6f, 0.8f, 0.8f, 1.0f));
geode->addDrawable(shape.get());

// box
shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(3.0f, 0.0f, 0.0f), 2 
* radius));
shape->setColor(osg::Vec4(0.4f, 0.9f, 0.3f, 1.0f));
geode->addDrawable(shape.get());

// cone
shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 
-3.0f), radius, height));
shape->setColor(osg::Vec4(1.0f, 0.3f, 0.3f, 1.0f));
geode->addDrawable(shape.get());

// cylinder
shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, 3.0f), 2* 
radius));
shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f));
geode->addDrawable(shape.get());

return scene;
}

osg::NodePath createReflector() {
Geode* node = new Geode;
const float radius = 0.8f;
ref_ptr hints = new TessellationHints;
hints->setDetailRatio(2.0f);
ShapeDrawable* shape = new ShapeDrawable(new Sphere(Vec3(0.0f, 0.0f, 0.0f), 
radius * 1.5f), hints.get());
shape->setColor(Vec4(0.8f, 0.8f, 0.8f, 1.0f));
node->addDrawable(shape);

osg::NodePath nodeList;
nodeList.push_back(node);

return nodeList;
}

class UpdateCameraAndTexGenCallback : public osg::NodeCallback
{
public:

typedef std::vector< osg::ref_ptr >  CameraList;

UpdateCameraAndTexGenCallback(osg::NodePath& reflectorNodePath, 
CameraList& Cameras):
_reflectorNodePath(reflectorNodePath),
_Cameras(Cameras)
{
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
// first update subgraph to make sure objects are all moved into 
position
traverse(node,nv);

// compute the position of the center of the reflector subgraph
osg::Matrixd worldToLocal = 
osg::computeWorldToLocal(_reflectorNodePath);
osg::BoundingSphere bs = _reflectorNodePath.back()->getBound();
osg::Vec3 position = bs.center();

typedef std::pair ImageData;
const ImageData id[] =
{
ImageData( osg::Vec3( 1,  0,  0), osg::Vec3( 0, -1,  0) ), // +X
ImageData( osg::Vec3(-1,  0,  0), osg::Vec3( 0, -1,  0) ), // -X
ImageData( osg::Vec3( 0,  1,  0), osg::Vec3( 0,  0,  1) ), // +Y
ImageData( osg::Vec3( 0, -1,  0), osg::Vec3( 0,  0, -1) ), // -Y
ImageData( osg::Vec3( 0,  0,  1), osg::Vec3( 0, -1,  0) ), // +Z
ImageData( osg::Vec3( 0,  0, -1), osg::Vec3( 0, -1,  0) )  // -Z
};

for(unsigned int i = 0; i < 6 && i < _Cameras.size(); ++i) {
osg::Matrix localOffset;

localOffset.makeLookAt(position,position+id[i].first,id[i].second);

osg::Matrix viewMatrix = worldToLocal*localOffset;

_Cameras[i]->setReferenceFrame(osg::Camera::ABSOLUTE_RF);

_Cameras[i]->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,1.0);
_Cameras[i]->setViewMatrix(viewMatrix);
}
}

protected:

virtual ~UpdateCameraAndTexGenCallback() {}

osg::NodePath   _reflectorNodePath;
CameraList  _Cameras;
};

class TexMatCullCallback : public osg::NodeCallback
{
public:

TexMatCullCallback(osg::TexMat* texmat):
_texmat(texmat)
{
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
// first update subgraph to make sure objects are all moved into 
position
traverse(node,nv);

osgUtil::CullVisitor* cv = dynamic_cast(nv);
if (cv)
{
osg::Quat q = 
osg::Matrix::inverse(*cv->getModelViewMatrix()).getRotate();


float yaw2 = asin(-2.0f*(q.x()*q.z() - 
q.w()*q.y()));

Re: [osg-users] Normal Mapping using Dynamic Cubemap

2017-12-19 Thread Rômulo Cerqueira
Hi Sebastian,

can you help me to find an example? I've been looking for this solution for 
almost two months.
... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Normal Mapping using Dynamic Cubemap

2017-12-18 Thread Rômulo Cerqueira
Hi,

is it possible to generate dynamic cubemaps (with normal mapping textures)?

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] dynamic cube map

2017-12-18 Thread Rômulo Cerqueira
Hi Nick,

I still need help to get the normal/depth data from reflected objects. Could 
you have a look in my current code?

C++ code:

Code:

// OSG includes
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

// C++ includes
#include 

#define SHADER_PATH_FRAG "normal_depth_map/shaders/normalDepthMap.frag"
#define SHADER_PATH_VERT "normal_depth_map/shaders/normalDepthMap.vert"

#define BOOST_TEST_MODULE "DynamicCubeMap_test"

using namespace osg;

unsigned int numTextures = 6;

enum TextureUnitTypes {
TEXTURE_UNIT_DIFFUSE,
TEXTURE_UNIT_NORMAL,
TEXTURE_UNIT_CUBEMAP
};

osg::ref_ptr _create_scene() {
osg::ref_ptr scene = new osg::Group;

osg::ref_ptr geode = new osg::Geode;
scene->addChild(geode.get());

const float radius = 0.8f;
const float height = 1.0f;
osg::ref_ptr shape;

// sphere
shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(-3.0f, 0.0f, 
0.0f), radius));
shape->setColor(osg::Vec4(0.6f, 0.8f, 0.8f, 1.0f));
geode->addDrawable(shape.get());

// box
shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(3.0f, 0.0f, 0.0f), 2 
* radius));
shape->setColor(osg::Vec4(0.4f, 0.9f, 0.3f, 1.0f));
geode->addDrawable(shape.get());

// cone
shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 
-3.0f), radius, height));
shape->setColor(osg::Vec4(1.0f, 0.3f, 0.3f, 1.0f));
geode->addDrawable(shape.get());

// cylinder
shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, 3.0f), 2* 
radius));
shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f));
geode->addDrawable(shape.get());

return scene;
}

osg::NodePath createReflector() {
Geode* node = new Geode;
const float radius = 0.8f;
ref_ptr hints = new TessellationHints;
hints->setDetailRatio(2.0f);
ShapeDrawable* shape = new ShapeDrawable(new Sphere(Vec3(0.0f, 0.0f, 0.0f), 
radius * 1.5f), hints.get());
shape->setColor(Vec4(0.8f, 0.8f, 0.8f, 1.0f));
node->addDrawable(shape);

osg::NodePath nodeList;
nodeList.push_back(node);

return nodeList;
}

class UpdateCameraAndTexGenCallback : public osg::NodeCallback
{
public:

typedef std::vector< osg::ref_ptr >  CameraList;

UpdateCameraAndTexGenCallback(osg::NodePath& reflectorNodePath, 
CameraList& Cameras):
_reflectorNodePath(reflectorNodePath),
_Cameras(Cameras)
{
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
// first update subgraph to make sure objects are all moved into 
position
traverse(node,nv);

// compute the position of the center of the reflector subgraph
osg::Matrixd worldToLocal = 
osg::computeWorldToLocal(_reflectorNodePath);
osg::BoundingSphere bs = _reflectorNodePath.back()->getBound();
osg::Vec3 position = bs.center();

typedef std::pair ImageData;
const ImageData id[] =
{
ImageData( osg::Vec3( 1,  0,  0), osg::Vec3( 0, -1,  0) ), // +X
ImageData( osg::Vec3(-1,  0,  0), osg::Vec3( 0, -1,  0) ), // -X
ImageData( osg::Vec3( 0,  1,  0), osg::Vec3( 0,  0,  1) ), // +Y
ImageData( osg::Vec3( 0, -1,  0), osg::Vec3( 0,  0, -1) ), // -Y
ImageData( osg::Vec3( 0,  0,  1), osg::Vec3( 0, -1,  0) ), // +Z
ImageData( osg::Vec3( 0,  0, -1), osg::Vec3( 0, -1,  0) )  // -Z
};

for(unsigned int i = 0; i < 6 && i < _Cameras.size(); ++i) {
osg::Matrix localOffset;

localOffset.makeLookAt(position,position+id[i].first,id[i].second);

osg::Matrix viewMatrix = worldToLocal*localOffset;

_Cameras[i]->setReferenceFrame(osg::Camera::ABSOLUTE_RF);

_Cameras[i]->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,1.0);
_Cameras[i]->setViewMatrix(viewMatrix);
}
}

protected:

virtual ~UpdateCameraAndTexGenCallback() {}

osg::NodePath   _reflectorNodePath;
CameraList  _Cameras;
};

class TexMatCullCallback : public osg::NodeCallback
{
public:

TexMatCullCallback(osg::TexMat* texmat):
_texmat(texmat)
{
}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
// first update subgraph to make sure objects are all moved into 
position
traverse(node,nv);

osgUtil::CullVisitor* cv = dynamic_cast(nv);
if (cv)
{
osg::Quat q = 
osg::Matrix::inverse(*cv->getModelViewMatrix()).getRotate();


float yaw2 = asin(-2.0f*(q.x()*q.z() - 
q.w()*q.y()));

Re: [osg-users] dynamic cube map

2017-12-11 Thread Rômulo Cerqueira
Hi Nick,

how can I encode the normal and depth data in the env texture?

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] dynamic cube map

2017-12-09 Thread Rômulo Cerqueira
Hi Nick,

I have a deep look in your code and I have a doubt.

The cube mapping results provides the reflected color. Is it possible to get 
the normal and depth instead of the reflected color?

Best regards,

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] dynamic cube map

2017-12-08 Thread Rômulo Cerqueira
Thanks a lot, Nick.

I will have a look in this source code. If I have some doubts, I will ask.

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] dynamic cube map

2017-12-05 Thread Rômulo Cerqueira
Hi Robert,

my idea is to compute the secondary reflections by using dynamic cubemap. I 
need to get the normal and depth from cube map reflections. Is it possible?

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] dynamic cube map

2017-12-05 Thread Rômulo Cerqueira
Thanks a lot, Robert!

Do you have some example with dynamic cube map with OSG and GLSL?

... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Dynamic Cubemap with OSG and Shader

2017-12-04 Thread Rômulo Cerqueira
Hi,

I would like to use the dynamic cubemaps to reproduce the mirror effects in my 
application, however I found few examples on the internet.

Is there any example code related to this topic? I will appreciate that.

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] dynamic cube map

2017-12-04 Thread Rômulo Cerqueira
Hi,

I would like to use the dynamic cubemaps to reproduce the mirror effects in my 
application, however I found few examples on the internet.

Do you have any code about dynamic cubemaps to suggest me?

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] TBN Matrix for Normal Mapping - OSG and GLSL

2017-11-08 Thread Rômulo Cerqueira
Hi Jordi and Sebastian,

thanks for your replies. I will have a look on osg::TangentSpaceVisitor, 
however I have a question: I will have in my OSG scene a lot of objects 
with/without normal mapping. How can I handle different normal textures using 
the same osg::TangentSpaceVisitor?

... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] TBN Matrix for Normal Mapping - OSG and GLSL

2017-11-07 Thread Rômulo Cerqueira
Hi,

I have used normal mapping using GLSL and OSG for my application (an imaging 
sonar simulation) and I got problems by calculating the TBN matrix on shaders. 
The normal vectors contain lower resolution on border in comparison with the 
center of image.

Follows my vertex code:

Code:

#version 130

out vec3 pos;
out vec3 normal;
out mat3 TBN;

void main() {
pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
normal = gl_NormalMatrix * gl_Normal.xyz;

vec3 n = normalize(normal); 
vec3 t = normalize(cross(normal, vec3(-1,0,0)));
vec3 b = cross(t, n) + cross(n, t); 
TBN = transpose(mat3(t,b,n));

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}




Part of my fragment code:

Code:

#version 130

in vec3 pos;
in vec3 normal;
in mat3 TBN;
uniform sampler2D normalTexture;

void main() {
vec3 newNormal = (texture2D(normalTexture, gl_TexCoord[0].st).rgb * 2.0 - 
1) * TBN;
newNormal = normalize(newNormal);
...
}




The resulting figure is attached.

How can I calculate the TBN matrix to compute the normal mapping properly?

Thanks in advance,


... 

Thank you!

Cheers,
Rômulo[/img]

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




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


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


Re: [osg-users] Warning: Error in reading to jpg images

2017-11-07 Thread Rômulo Cerqueira
Hi Christian and Robert,

I solved in an alternative way: converting my images to PNG. I did not change 
anything in the source code and it worked!

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Warning: Error in reading to jpg images

2017-11-05 Thread Rômulo Cerqueira
Follows attached my output info when OSG_NOTIFY_LEVEL = DEBUG.

... 

Thank you!

Cheers,
Rômulo

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




Attachments: 
http://forum.openscenegraph.org//files/debug_596.txt


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


[osg-users] Warning: Error in reading to jpg images

2017-11-04 Thread Rômulo Cerqueira
Hi community!

I got some problems by loading JPG images using OSG.

When I read them directly using osgviewer, the images are loaded with success. 


Code:

osgviewer --image /home/romulo/gray_texture_n.jpg




However, the problem occurs when I read the images by OSG code, as presented in 
my unitary test code: 
https://github.com/Brazilian-Institute-of-Robotics/simulation-normal_depth_map/blob/master/test/NormalMapping_test.cpp

I got the following output message:

Code:

Warning: Error in reading to "/home/romulo/gray_texture_n.jpg".




How can I fix this? I will appreciate any information or help on the same.

Cheers,
Rômulo[/code][/b]

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




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


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


Re: [osg-users] CullVisitor::apply(Geode&) detected NaN,

2017-09-02 Thread Rômulo Cerqueira
Hi guys,

I found and solved the problem! :D

When I grab the osg scene at first time, my view matrix is NaN; from the second 
time, this matrix is correctly filled. 

Then, I modified the grabImage method to replace when the view matrix is NaN by 
the identity matrix, as follows:


Code:

osg::ref_ptr 
ImageViewerCaptureTool::grabImage(osg::ref_ptr node) {
// set the current root node
_viewer->setSceneData(node);

// if the view matrix is invalid (NaN), use the identity
osg::ref_ptr camera = _viewer->getCamera();
if (camera->getViewMatrix().isNaN())
camera->setViewMatrix(osg::Matrix::identity());

// grab the current frame
_viewer->frame();
return _capture->captureImage();
}




Thanks for all messages!

Cheers,

Rômulo

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





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


Re: [osg-users] CullVisitor::apply(Geode&) detected NaN,

2017-09-01 Thread Rômulo Cerqueira
Ok Robert,

this is my current code (only .cpp):


Code:

#include "ImageViewerCaptureTool.hpp"
#include 
#include 
#include 

namespace normal_depth_map {

ImageViewerCaptureTool::ImageViewerCaptureTool(uint width, uint height) {

// initialize the hide viewer;
initializeProperties(width, height);
}

ImageViewerCaptureTool::ImageViewerCaptureTool( double fovY, double fovX, uint 
value, bool isHeight) {
uint width, height;

if (isHeight) {
height = value;
width = height * tan(fovX * 0.5) / tan(fovY * 0.5);
} else {
width = value;
height = width * tan(fovY * 0.5) / tan(fovX * 0.5);
}

double aspectRatio = width * 1.0 / height;

initializeProperties(width, height);
_viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);

_viewer->getCamera()->setProjectionMatrixAsPerspective(fovY * 180.0 / M_PI, 
aspectRatio, 0.1, 1000);
}

void ImageViewerCaptureTool::initializeProperties(uint width, uint height) {
// initialize the hide viewer;
_viewer = new osgViewer::Viewer;
osg::Camera *camera = this->_viewer->getCamera();
osg::ref_ptr traits = new 
osg::GraphicsContext::Traits;
traits->width = width;
traits->height = height;
traits->pbuffer = true;
traits->readDISPLAY();
osg::ref_ptr gc = 
osg::GraphicsContext::createGraphicsContext(traits.get());
camera->setGraphicsContext(gc);
camera->setDrawBuffer(GL_FRONT);
camera->setViewport(new osg::Viewport(0, 0, width, height));

// initialize the class to get the image in float data resolution
_capture = new WindowCaptureScreen(gc);
_viewer->getCamera()->setFinalDrawCallback(_capture);
}

osg::ref_ptr 
ImageViewerCaptureTool::grabImage(osg::ref_ptr node ) {

_viewer->setSceneData(node);
_viewer->frame();
return _capture->captureImage();;
}

osg::ref_ptr ImageViewerCaptureTool::getDepthBuffer() {
return _capture->getDepthBuffer();
}


void ImageViewerCaptureTool::setCameraPosition( const osg::Vec3d& eye, const 
osg::Vec3d& center, const osg::Vec3d& up) {
_viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);
}

void ImageViewerCaptureTool::getCameraPosition( osg::Vec3d& eye,osg::Vec3d& 
center, osg::Vec3d& up) {
_viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
}

void ImageViewerCaptureTool::setBackgroundColor(osg::Vec4d color) {
_viewer->getCamera()->setClearColor(color);
}


WindowCaptureScreen METHODS


WindowCaptureScreen::WindowCaptureScreen(osg::ref_ptr gc) 
{
_mutex = new OpenThreads::Mutex();
_condition = new OpenThreads::Condition();
_image = new osg::Image();
_depth_buffer = new osg::Image();

// checks the GraficContext from the camera viewer
if (gc->getTraits()) {

GLenum pixelFormat;
if (gc->getTraits()->alpha) pixelFormat = GL_RGBA;
else pixelFormat = GL_RGB;

int width = gc->getTraits()->width;
int height = gc->getTraits()->height;

// allocates the image memory space
_image->allocateImage(width, height, 1, pixelFormat, GL_FLOAT);
_depth_buffer->allocateImage(width, height, 1, GL_DEPTH_COMPONENT, GL_FLOAT);
}
}

WindowCaptureScreen::~WindowCaptureScreen() {
delete (_condition);
delete (_mutex);
}

osg::ref_ptr WindowCaptureScreen::captureImage() {

//wait to finish the capture image in call back
_condition->wait(_mutex);
return _image;
}

osg::ref_ptr WindowCaptureScreen::getDepthBuffer() {
return _depth_buffer;
}


void WindowCaptureScreen::operator ()(osg::RenderInfo& renderInfo) const {
osg::ref_ptr gc = 
renderInfo.getState()->getGraphicsContext();
if (gc->getTraits()) {
_mutex->lock();
_image->readPixels( 0, 0, _image->s(), _image->t(), _image->getPixelFormat(), 
GL_FLOAT);
_depth_buffer->readPixels(0, 0, _image->s(), _image->t(), 
_depth_buffer->getPixelFormat(), GL_FLOAT);

//grants the access to image
_condition->signal();
_mutex->unlock();
}
}

}





... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] CullVisitor::apply(Geode&) detected NaN,

2017-08-31 Thread Rômulo Cerqueira
Up!

Rômulo

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





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


[osg-users] CullVisitor::apply(Geode&) detected NaN,

2017-08-30 Thread Rômulo Cerqueira
Hi,

I have the following message when I run my OSG application:


Code:

CullVisitor::apply(Geode&) detected NaN,
depth=nan, center=(1.79588 1.50488 1.42179),
matrix={
nan nan -nan -nan 
nan nan -nan -nan 
nan nan -nan -nan 
nan nan -nan -nan 
}





What this kind of warning/error means?
... 

Thank you!

Cheers,
Rômulo[/code]

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





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


Re: [osg-users] Problem to load images

2017-08-15 Thread Rômulo Cerqueira
Hi Robert,

thanks for your reply. Follows my code:

Code:

#define BOOST_TEST_MODULE "NormalMapping_test"
#include 

// OpenSceneGraph includes
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

// Rock includes
#include 
#include 

// OpenCV includes
#include 
#include 
#include 
#include 

// C++ includes
#include 

using namespace normal_depth_map;

BOOST_AUTO_TEST_SUITE(NormalMapping)


// add one object to scene (sphere)
void addSimpleObject(osg::ref_ptr root) {
osg::ref_ptr geode = new osg::Geode();
geode->addDrawable(new osg::ShapeDrawable(new 
osg::Sphere(osg::Vec3(0,0,-14), 5)));
root->addChild(geode);
root->getChild(0)->asGeode()->addDrawable(geode->getDrawable(0));
}

// define texture attributes
osg::ref_ptr insertNormalMapTexture(osg::ref_ptr 
diffuseImage, osg::ref_ptr normalImage) {
osg::ref_ptr diffuse = new osg::Texture2D();
osg::ref_ptr normal = new osg::Texture2D();

diffuse->setImage(diffuseImage);
diffuse->setDataVariance(osg::Object::DYNAMIC);
diffuse->setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::LINEAR_MIPMAP_LINEAR);
diffuse->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
diffuse->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
diffuse->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
diffuse->setResizeNonPowerOfTwoHint(false);
diffuse->setMaxAnisotropy(8.0f);

normal->setImage(normalImage);
normal->setDataVariance(osg::Object::DYNAMIC);
normal->setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::LINEAR_MIPMAP_LINEAR);
normal->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
normal->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
normal->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
normal->setResizeNonPowerOfTwoHint(false);
normal->setMaxAnisotropy(8.0f);

osg::ref_ptr normalState = new osg::StateSet();
normalState->setTextureAttributeAndModes(TEXTURE_UNIT_DIFFUSE, diffuse, 
osg::StateAttribute::ON);
normalState->setTextureAttributeAndModes(TEXTURE_UNIT_NORMAL, normal, 
osg::StateAttribute::ON);
return normalState;
}

// get texture files
void loadTextures(osg::ref_ptr root, TextureImages textureId) {
osg::ref_ptr diffuseImage = 
osgDB::readImageFile("/home/romulo/dev.bir.master/simulation/normal_depth_map/textures/gray_texture_d.jpg");
osg::ref_ptr normalImage = 
osgDB::readImageFile("/home/romulo/dev.bir.master/simulation/normal_depth_map/textures/gray_texture_n.jpg");

// texture properties
osg::ref_ptr geode = new osg::Geode();
geode->setStateSet(insertNormalMapTexture(diffuseImage, normalImage));
root->addChild(geode);
}

// create scene with normal mapping and one object
osg::ref_ptr createNormalMapSimpleScene() {
osg::ref_ptr root = new osg::Group();
osg::ref_ptr stateset = new osg::StateSet();
stateset->addUniform(new osg::Uniform("diffuseTexture", 
TEXTURE_UNIT_DIFFUSE));
stateset->addUniform(new osg::Uniform("normalTexture", 
TEXTURE_UNIT_NORMAL));
stateset->setDataVariance(osg::Object::STATIC);
root->setStateSet(stateset);

loadTextures(root, TEXTURE_GRAY);
addSimpleObject(root);
return root;
}

// compute the normal depth map for a osg scene
cv::Mat computeNormalDepthMap(osg::ref_ptr root, float maxRange, 
float fovX, float fovY) {
uint height = 500;

// normal depth map
NormalDepthMap normalDepthMap(maxRange, fovX * 0.5, fovY * 0.5);
ImageViewerCaptureTool capture(fovY, fovX, height);
capture.setBackgroundColor(osg::Vec4d(0, 0, 0, 0));
normalDepthMap.addNodeChild(root);

// grab scene
osg::ref_ptr osgImage = 
capture.grabImage(normalDepthMap.getNormalDepthMapNode());
osg::ref_ptr osgDepth = capture.getDepthBuffer();
cv::Mat cvImage = cv::Mat(osgImage->t(), osgImage->s(), CV_32FC3, 
osgImage->data());
cv::Mat cvDepth = cv::Mat(osgDepth->t(), osgDepth->s(), CV_32FC1, 
osgDepth->data());
cvDepth = cvDepth.mul( cv::Mat1f(cvDepth < 1) / 255);

std::vector channels;
cv::split(cvImage, channels);
channels[1] = cvDepth;
cv::merge(channels, cvImage);
cv::cvtColor(cvImage, cvImage, cv::COLOR_RGB2BGR);
cv::flip(cvImage, cvImage, 0);

return cvImage.clone();
}

BOOST_AUTO_TEST_CASE(differentNormalMaps_TestCase) {
float maxRange = 20.0f;
float fovX = M_PI / 3;  // 60 degrees
float fovY = M_PI / 3;  // 60 degrees

osg::ref_ptr normalRoot = createNormalMapSimpleScene();

cv::Mat cvNormal = computeNormalDepthMap(normalRoot, maxRange, fovX, fovY);

plotSonarTest(cvNormal, maxRange, fovX * 0.5);
}

BOOST_AUTO_TEST_SUITE_END()





... 

Thank you!

Cheers,
Rômulo

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org

Re: [osg-users] Problem to load images

2017-08-13 Thread Rômulo Cerqueira
Hi Nick and Robert,

the attached file is the output from my C++ program. Any suggestions to solve 
that?

Thanks in advance,

Rômulo Cerqueira

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




Attachments: 
http://forum.openscenegraph.org//files/out_639.txt


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


Re: [osg-users] Problem to load images

2017-08-12 Thread Rômulo Cerqueira
Hi Trace and Nick,

this attachment is my output when I perform the following commands:


Code:
export OSG_NOTIFY_LEVEL=DEBUG
osgviewer --image gray_texture_d.jpg





... 

Thank you!

Cheers,
Rômulo

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




Attachments: 
http://forum.openscenegraph.org//files/out_515.txt


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


[osg-users] Change Perspective to Orthogonal View

2017-03-05 Thread Rômulo Cerqueira
Hi,

I like to change the current perspective view of my camera to an orthogonal 
projection, keeping the same position. How can I do this?

My current code of perspective camera:


Code:

_viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
_viewer->getCamera()->setProjectionMatrixAsPerspective(fovY * 180.0 / M_PI, 
aspectRatio, 0.1, 1000);





... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Check if sampler2D is valid in fragment shader

2017-01-03 Thread Rômulo Cerqueira
Hi,


> 
> I can create a minimal example if you're stuck with this. 
> 


I will appreciate this, please.
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Check if sampler2D is valid in fragment shader

2017-01-03 Thread Rômulo Cerqueira
Hi Sebastian,

I have used the last openscenegraph stable package in ubuntu (version 3.2.3 - 
https://launchpad.net/ubuntu/+source/openscenegraph), and there is no 
setDefine() method in osg::StateSet (only for 2.4 and newer). There is a 
different way?

Cheers,
Rômulo

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





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


Re: [osg-users] Check if sampler2D is valid in fragment shader

2016-12-29 Thread Rômulo Cerqueira
Hi Christian,


> You could traverse the scene graph and check the state sets to see if they 
> bind a texture to a texture unit. 
> 
> Then depending on these findings, choose the correct shader code. 


I appreciated it. Can you give me some example?
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Check if sampler2D is valid in fragment shader

2016-12-28 Thread Rômulo Cerqueira
Hi Sebastian,


> 
> There is no direct way. If you need shaders with and without texturing 
> you should bind different programs to the affected geometries. 
> 


I think my problem is a little bit different. I will receive the final scene 
with or without textures and process it properly. I won't participate in the 
scene development.

... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Material Properties to Change the Normal Intensity

2016-12-28 Thread Rômulo Cerqueira
Hi Sebastian,

I followed your tip and passed the reflectance as float-uniform. Each object 
has a different reflectance passed by individual statesets.
... 

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Check if sampler2D is valid in fragment shader

2016-12-26 Thread Rômulo Cerqueira
Hi,

is there a way to check if a texture (as uniform sampler2D) is valid in 
fragment shader?

This is my current code:


Code:

if (textureSize(myTexture, 0).x > 1) {
// do something with the texture
}
else {
// process without texture information
}



... 

Thank you in advance!

Cheers,
Rômulo

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





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


Re: [osg-users] Material Properties to Change the Normal Intensity

2016-12-26 Thread Rômulo Cerqueira
Hi Sebastian,


> 
> Are you planning on using the bump-maps alpha channel, or which alpha do you 
> plan to use.
> 


I wanna to pass a reflectance value to be multiplied by the normal map 
(normNormal in fragment shader) to simulate real situations. For example, a 
steel cube (e.g. reflectance = 1.12) should reflect more than a plastic cube 
(e.g. reflectance = 0.6) for a real sonar. In this case, I need to pass this 
"reflectance" value to shader for each object present in the scene.


> 
> What kind of input geometries do you use? Are the objects with the different 
> reflectances models or can one model have multiple parts with different 
> reflectance values?
> 


Any kind of geometries: cubes, spheres, cones, structures... Initially all 
parts of the same object will have an unique reflectance model.

... 

Cheers,
Rômulo[/quote]

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





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


Re: [osg-users] Material Properties to Change the Normal Intensity

2016-12-26 Thread Rômulo Cerqueira
Hi Sebastian,

I was having a look in the second option and it is easy to code 
(https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/uniform.php), 
however I'm not sure if I can set different reflectance in a scene with 
multiple objects. Maybe use the alpha channel is a better option. 
... 

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Material Properties to Change the Normal Intensity

2016-12-26 Thread Rômulo Cerqueira
Hi Sebastian,

this is my vertex shader:


Code:

#version 130

out vec3 pos;
out vec3 normal;
out mat3 TBN;

void main() {

pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
normal = gl_NormalMatrix * gl_Normal;

vec3 n = normalize(normal);
vec3 t = normalize(gl_NormalMatrix[0]);
vec3 b = cross(t, n);
TBN = transpose(mat3(t, b, n));

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;

}





and this is my fragment code:


Code:

#version 130

in vec3 pos;
in vec3 normal;
in mat3 TBN;

uniform float farPlane;
uniform bool drawNormal;
uniform bool drawDepth;
uniform sampler2D normalTexture;

out vec4 out_data;

void main() {

out_data = vec4(0, 0, 0, 0);

vec3 normNormal;

// Normal for textured scenes (by bump mapping)
if (textureSize(normalTexture, 0).x > 1) {
vec3 bumpedNormal = (texture2D(normalTexture, gl_TexCoord[0].st).rgb * 2.0 - 
1.0) * TBN;
normNormal = normalize(bumpedNormal);
}

// Normal for untextured scenes
else {
normNormal = normalize(normal);
}

vec3 normPosition = normalize(-pos);
float linearDepth = sqrt(pos.z * pos.z + pos.x * pos.x + pos.y * pos.y);
linearDepth = linearDepth / farPlane;

if (!(linearDepth > 1)) {
if (drawNormal) {
out_data.zw = vec2(max(dot(normPosition, normNormal), 0), 1.0);
}

if (drawDepth) {
out_data.yw = vec2(linearDepth, 1.0);
}

gl_FragDepth = linearDepth;
}





and this is my code:


Code:

// define texture attributes
osg::ref_ptr insertBumpMapTexture(osg::ref_ptr 
diffuseImage, osg::ref_ptr normalImage, osg::ref_ptr 
specularImage) {
osg::ref_ptr diffuse = new osg::Texture2D();
osg::ref_ptr normal = new osg::Texture2D();
osg::ref_ptr specular = new osg::Texture2D();

diffuse->setImage(diffuseImage);
diffuse->setDataVariance(osg::Object::DYNAMIC);
diffuse->setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::LINEAR_MIPMAP_LINEAR);
diffuse->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
diffuse->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
diffuse->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
diffuse->setResizeNonPowerOfTwoHint(false);
diffuse->setMaxAnisotropy(8.0f);

normal->setImage(normalImage);
normal->setDataVariance(osg::Object::DYNAMIC);
normal->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
normal->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
normal->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
normal->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
normal->setResizeNonPowerOfTwoHint(false);
normal->setMaxAnisotropy(8.0f);

specular->setImage(specularImage);
specular->setDataVariance(osg::Object::DYNAMIC);
specular->setFilter(osg::Texture::MIN_FILTER, 
osg::Texture::LINEAR_MIPMAP_LINEAR);
specular->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
specular->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
specular->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
specular->setResizeNonPowerOfTwoHint(false);
specular->setMaxAnisotropy(8.0f);

osg::ref_ptr bumpState = new osg::StateSet();
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_DIFFUSE, diffuse, 
osg::StateAttribute::ON);
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_NORMAL, normal, 
osg::StateAttribute::ON);
bumpState->setTextureAttributeAndModes(TEXTURE_UNIT_SPECULAR, specular, 
osg::StateAttribute::ON);
return bumpState;
}





How can I pass this attribute by alpha channel and by uniform per drawable?

Cheers,
Rômulo

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





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


Re: [osg-users] Material Properties to Change the Normal Intensity

2016-12-25 Thread Rômulo Cerqueira
Hi SMesserschmidt,

Thanks for your reply. I wanna set a refletance value for each scene's object 
and multiply it by normal value (e.g. Steel and aluminium have more 
reflectivity than wood and plastic). In this case, the alpha channel will 
change the object transparency, right? If yes, I think the normal value can not 
be increased, only decreased.

There is a way to pass the reflectance value or similar and manipulate it in 
the shader?

Thank you!

Cheers,
Rômulo

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





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


Re: [osg-users] Material Properties to Change the Normal Intensity

2016-12-25 Thread Rômulo Cerqueira
Hi SMesserschmidt,

Thanks for your reply. I wanna set a refletance value for each scene's object 
and multiply it by normal value (e.g. Steel and aluminium have more 
reflectivity than wood and plastic). In this case, the alpha channel will 
change the object transparency, right? If yes, I think the normal value can not 
be increased, only decreased.

There is a way to pass the reflectance value or similar and manipulate it in 
the shader?

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Material Properties to Change the Normal Intensity

2016-12-23 Thread Rômulo Cerqueira
Hi,

I have simulated a sonar sensor using normal depth map by custom 3D shader from 
OpenSceneGraph scene.

I already implemented the Bump Mapping technique to change the normal 
directions. For now, I need to change the material properties (e.g. 
reflectance) of scene's objects to increase/decrease the normal values. Is it 
possible?  

Thank you!

Cheers,
Rômulo

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





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


[osg-users] Rotate Camera on Its Axis

2015-06-17 Thread Rômulo Cerqueira
Hi,
I have problems with this topic.

I get my View Matrix by viewer-getCamera()-getViewMatrix() and apply a 
rotation by preMult, but the camera rotates using the center of the world scene 
as reference, not its own center.

How I can do this?

... 

Thank you!

Cheers,
Rômulo

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





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