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] 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 Trajce Nikolov NICK
Hi Romulo,

more proper example is osgprerendercubemap - how to setup the RTT for
cubemaps. Then you can have a look again in the OpenIG project, in the
Triton plugin, line 70 - 114, that is the shader to generate HeighMap, for
your case instead of the world Z you put in the output Z from the camera
(the depth), and same for the normals. Here is the link for the code
snippet:

https://github.com/CCSI-CSSI/MuseOpenIG/blob/master/Plugin-Triton/IGPluginTriton.cpp

good luck ;-)

On Mon, Dec 11, 2017 at 8:19 PM, Trajce Nikolov NICK <
trajce.nikolov.n...@gmail.com> wrote:

> Hi Romulo,
>
> I guess you should do a render to texture and make sure the texture format
> is with texels as floating points. Then custom shaders that will render
> normals and depths into these textures.
>
> I am on travel at the moment will help you more when I get back. Meanwhile
> you can do research. Start with the osgprerender example
>
> On Dec 11, 2017 7:13 PM, "Rômulo Cerqueira" 
> wrote:
>
>> 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
>>
>


-- 
trajce nikolov nick
___
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-11 Thread Trajce Nikolov NICK
Hi Romulo,

I guess you should do a render to texture and make sure the texture format
is with texels as floating points. Then custom shaders that will render
normals and depths into these textures.

I am on travel at the moment will help you more when I get back. Meanwhile
you can do research. Start with the osgprerender example

On Dec 11, 2017 7:13 PM, "Rômulo Cerqueira" 
wrote:

> 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
>
___
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-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-10 Thread Trajce Nikolov NICK
Hi Romulo,

if the normal and the depth are encoded in the env texture I believe the
answer is yes. Are you encoding the normal and the depth into texture? if
so, can you provide snippet?

On Sun, Dec 10, 2017 at 6:38 AM, Rômulo Cerqueira <
romulogcerque...@gmail.com> wrote:

> 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
>



-- 
trajce nikolov nick
___
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 Trajce Nikolov NICK
Hi Romulo,

have a look at the OpenIG project sources, it has it implemented with GLSL

https://github.com/CCSI-CSSI/MuseOpenIG/blob/master/Plugin-ModelComposition/IGPluginModelComposition.cpp
Look here for "environmental", starting from line 395. Here you use texture
cache to set up the 6 textures and the #define for the shader composition

The GLSL part is here:
https://github.com/CCSI-CSSI/MuseOpenIG/blob/master/Resources/shaders/forwardplus_vs.glsl
https://github.com/CCSI-CSSI/MuseOpenIG/blob/master/Resources/shaders/forwardplus_ps.glsl
Again, it uses shader composition the code inside #if defined(ENVIRONMENTAL)

Shoot questions if you struggle

Hope this helps

Cheers,
Nick

On Wed, Dec 6, 2017 at 3:08 AM, Rômulo Cerqueira  wrote:

> 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
>



-- 
trajce nikolov nick
___
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


Re: [osg-users] dynamic cube map

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

Have a look at the osgprerendercubemap example as it illustrates how
to set up multi-pass rendering to render to the six faces of the
cubemap.

Robert

On 5 December 2017 at 01:26, Rômulo Cerqueira
 wrote:
> 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
___
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] dynamic cube map

2010-02-10 Thread Sebastien Nerig
Hi

thank you Nick I found your discussion about osgprerenderCubeMap
I did a search on dynamic cube map but I didn't find anything.

Thank you!

Cheers,
Sebastien

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





___
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

2010-02-10 Thread Trajce Nikolov
Hi Sebastian.

the discussion has to have attached working code sample for what you are
trying to achieve. That is what I am using in my app to do environmental
mapping.
-Nick


On Wed, Feb 10, 2010 at 11:51 AM, Sebastien Nerig overse...@hotmail.comwrote:

 Hi

 thank you Nick I found your discussion about osgprerenderCubeMap
 I did a search on dynamic cube map but I didn't find anything.

 Thank you!

 Cheers,
 Sebastien

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





 ___
 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] dynamic cube map

2010-02-10 Thread J.P. Delport

see here:

http://thread.gmane.org/gmane.comp.graphics.openscenegraph.user/54440

jp

Sebastien Nerig wrote:

Hi

thank you Nick I found your discussion about osgprerenderCubeMap
I did a search on dynamic cube map but I didn't find anything.

Thank you!

Cheers,
Sebastien

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





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



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


___
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

2010-02-10 Thread Sebastien Nerig
Hi Nick,
ok I did have a look at the osgPrerenderCubeMap code and at you thread about 
mixing a static 2D texture and a dynamic cube map into a shader. btw your 
version with 

Code:
{ 
osg::Uniform* u = new osg::Uniform(osg::Uniform::SAMPLER_CUBE,cubeMapUnit); 
u-set(unit);   
node-getOrCreateStateSet()-addUniform( u ); 
} 


 works well for me

I tried this sample with my own camera (Y up) and that works well too.
I want to use this sample in a more general case (dynamic reflection on water 
for example) . I tried to use the bottom plane as the reflector but the 
reflection is now awfull... Did you work on it ? Can you confirm ?

Thank you
Sebastien

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




Attachments: 
http://forum.openscenegraph.org//files/sans_titre_192.jpg


___
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

2010-02-10 Thread Trajce Nikolov
send me your code .. I will have a look
-Nick


On Wed, Feb 10, 2010 at 1:22 PM, Sebastien Nerig overse...@hotmail.comwrote:

 Hi Nick,
 ok I did have a look at the osgPrerenderCubeMap code and at you thread
 about mixing a static 2D texture and a dynamic cube map into a shader. btw
 your version with

 Code:
 {
 osg::Uniform* u = new
 osg::Uniform(osg::Uniform::SAMPLER_CUBE,cubeMapUnit);
 u-set(unit);
 node-getOrCreateStateSet()-addUniform( u );
 }


  works well for me

 I tried this sample with my own camera (Y up) and that works well too.
 I want to use this sample in a more general case (dynamic reflection on
 water for example) . I tried to use the bottom plane as the reflector but
 the reflection is now awfull... Did you work on it ? Can you confirm ?

 Thank you
 Sebastien

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




 Attachments:
 http://forum.openscenegraph.org//files/sans_titre_192.jpg


 ___
 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] dynamic cube map

2010-02-10 Thread Trajce Nikolov
the code I post assumes Z-up.

-Nick


On Wed, Feb 10, 2010 at 1:24 PM, Trajce Nikolov nikolov.tra...@gmail.comwrote:

 send me your code .. I will have a look
 -Nick



 On Wed, Feb 10, 2010 at 1:22 PM, Sebastien Nerig overse...@hotmail.comwrote:

 Hi Nick,
 ok I did have a look at the osgPrerenderCubeMap code and at you thread
 about mixing a static 2D texture and a dynamic cube map into a shader. btw
 your version with

 Code:
 {
 osg::Uniform* u = new
 osg::Uniform(osg::Uniform::SAMPLER_CUBE,cubeMapUnit);
 u-set(unit);
 node-getOrCreateStateSet()-addUniform( u );
 }


  works well for me

 I tried this sample with my own camera (Y up) and that works well too.
 I want to use this sample in a more general case (dynamic reflection on
 water for example) . I tried to use the bottom plane as the reflector but
 the reflection is now awfull... Did you work on it ? Can you confirm ?

 Thank you
 Sebastien

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




 Attachments:
 http://forum.openscenegraph.org//files/sans_titre_192.jpg


 ___
 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] dynamic cube map

2010-02-10 Thread Sebastien Nerig
Hi Nick,

Well the changes are minors. I just wanted to change de reflector from the 
sphere to the bottom plane (or box).

here is my reflector function, I changed the sphere to a box geode, ie the 
bottom plane/box.

Code:

osg::NodePathcreateReflector()
{
osg::PositionAttitudeTransform* pat = new 
osg::PositionAttitudeTransform;
pat-setPosition(osg::Vec3(0.0f,0.0f,0.0f));

pat-setAttitude(osg::Quat(osg::inDegrees(0.0f),osg::Vec3(0.0f,0.0f,1.0f)));

osg::Geode* geode_1 = new osg::Geode;
osg::ShapeDrawable* shape = new osg::ShapeDrawable(new 
osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f), 10, 10.f, 0.1));
shape-setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f));
geode_1-addDrawable(shape);

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

pat-addChild(geode_1);

osg::NodePath nodeList;
nodeList.push_back(pat);
nodeList.push_back(geode_1);

return nodeList;
}




And I have commented the code corresponding to the same bottom plane in the 
_create_scene() function.

Code:
//shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f), 10, 
10.f, 0.1), hints.get());
//shape-setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f));
//geode_1-addDrawable(shape.get());




Sebastien

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





___
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

2010-02-10 Thread Trajce Nikolov
maybe you dont need cube map for what you want to achieve. Have you seen the
osgreflect example ? Does it works for you ?
-Nick


On Wed, Feb 10, 2010 at 1:42 PM, Sebastien Nerig overse...@hotmail.comwrote:

 Hi Nick,

 Well the changes are minors. I just wanted to change de reflector from the
 sphere to the bottom plane (or box).

 here is my reflector function, I changed the sphere to a box geode, ie the
 bottom plane/box.

 Code:

 osg::NodePathcreateReflector()
 {
osg::PositionAttitudeTransform* pat = new
 osg::PositionAttitudeTransform;
pat-setPosition(osg::Vec3(0.0f,0.0f,0.0f));

  pat-setAttitude(osg::Quat(osg::inDegrees(0.0f),osg::Vec3(0.0f,0.0f,1.0f)));

osg::Geode* geode_1 = new osg::Geode;
osg::ShapeDrawable* shape = new osg::ShapeDrawable(new
 osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f), 10, 10.f, 0.1));
shape-setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f));
geode_1-addDrawable(shape);

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

pat-addChild(geode_1);

osg::NodePath nodeList;
nodeList.push_back(pat);
nodeList.push_back(geode_1);

return nodeList;
 }




 And I have commented the code corresponding to the same bottom plane in the
 _create_scene() function.

 Code:
 //shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f),
 10, 10.f, 0.1), hints.get());
 //shape-setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f));
 //geode_1-addDrawable(shape.get());




 Sebastien

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





 ___
 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] dynamic cube map

2010-02-10 Thread Sebastien Nerig
mmm
I dont think it will work. I would like to make reflection into object that are 
not always plane.

Sebastien

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





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


[osg-users] dynamic cube map

2010-02-09 Thread Sebastien Nerig
Hi,

I am trying to make a dynamic cube with osg.
The idea is to render into a cube map the +X, -X, +Y, -Y, +Z and -Z view from 
the camera view point at each frame.
Then the cube map is textured on a reflector surface (a plane) within a shader. 
I would like to see other objects (sphere, cube) reflecting in my plane as it 
was a mirror.
I managed to make the cube map and to texture it on my plane but the reflection 
is not correct, and I need some ideas to correct my app.

Ok, so I build a cubemap texture with osg, then I create 6 camera nodes. theses 
cameras are looking at +X, -X, +Y, -Y, +Z and -Z directions and are attached 
with a callback to the main camera position.
I use this command to attach the cube map texture for each camera :

Code:
camera-attach(osg::Camera::COLOR_BUFFER, m_textureEnvMap, 0, i);



Then I use this fragment shader to map the cube map on the plane : 

Code:
// world space eye vector
vec3 E = normalize(posWorld.xyz - cameraPosWorld);
// plane world vector (hadcoding!)
vec3 N = vec3(0,1,0);
vec3 coord = reflect(E, N);
vec3 reflectColor = textureCube(cubeMap, vec3(coord.x, coord.y, coord.z)).rgb;



posWorld is the current fragment world position (posWorld = modelMatWorld * 
gl_Vertex); cameraPosWorld is the camera world position (passed with uniform).

I would like to have some advice and ideas about my program.  Did anyone 
already try to make dynamic cube ? What did I miss ?

Thank you!

Cheers,
Sebastien

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




Attachments: 
http://forum.openscenegraph.org//files/sans_titre_2_182.jpg
http://forum.openscenegraph.org//files/sans_titre_243.jpg


___
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

2010-02-09 Thread Trajce Nikolov
Have a look in the mail archive for osgcubemapprerender/(or
osgprerendercubemap). There is a sample attached in one of the mail that do
that. Was in the recent discussion ...
-Nick


On Tue, Feb 9, 2010 at 4:13 PM, Sebastien Nerig overse...@hotmail.comwrote:

 Hi,

 I am trying to make a dynamic cube with osg.
 The idea is to render into a cube map the +X, -X, +Y, -Y, +Z and -Z view
 from the camera view point at each frame.
 Then the cube map is textured on a reflector surface (a plane) within a
 shader. I would like to see other objects (sphere, cube) reflecting in my
 plane as it was a mirror.
 I managed to make the cube map and to texture it on my plane but the
 reflection is not correct, and I need some ideas to correct my app.

 Ok, so I build a cubemap texture with osg, then I create 6 camera nodes.
 theses cameras are looking at +X, -X, +Y, -Y, +Z and -Z directions and are
 attached with a callback to the main camera position.
 I use this command to attach the cube map texture for each camera :

 Code:
 camera-attach(osg::Camera::COLOR_BUFFER, m_textureEnvMap, 0, i);



 Then I use this fragment shader to map the cube map on the plane :

 Code:
 // world space eye vector
 vec3 E = normalize(posWorld.xyz - cameraPosWorld);
 // plane world vector (hadcoding!)
 vec3 N = vec3(0,1,0);
 vec3 coord = reflect(E, N);
 vec3 reflectColor = textureCube(cubeMap, vec3(coord.x, coord.y,
 coord.z)).rgb;



 posWorld is the current fragment world position (posWorld = modelMatWorld *
 gl_Vertex); cameraPosWorld is the camera world position (passed with
 uniform).

 I would like to have some advice and ideas about my program.  Did anyone
 already try to make dynamic cube ? What did I miss ?

 Thank you!

 Cheers,
 Sebastien

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




 Attachments:
 http://forum.openscenegraph.org//files/sans_titre_2_182.jpg
 http://forum.openscenegraph.org//files/sans_titre_243.jpg


 ___
 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