OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

dynamic cube map

Goto page 1, 2  Next
 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
seb
User


Joined: 15 May 2009
Posts: 66

PostPosted: Tue Feb 09, 2010 2:13 pm    Post subject:
dynamic cube map
Reply with quote

Hi,

I am trying to make a dynamic cube map 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
Back to top
View user's profile Send private message
Trajce Nikolov
Guest





PostPosted: Tue Feb 09, 2010 2:39 pm    Post subject:
dynamic cube map
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
seb
User


Joined: 15 May 2009
Posts: 66

PostPosted: Wed Feb 10, 2010 9:51 am    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
Trajce Nikolov
Guest





PostPosted: Wed Feb 10, 2010 9:54 am    Post subject:
dynamic cube map
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
J.P. Delport
Guest





PostPosted: Wed Feb 10, 2010 10:27 am    Post subject:
dynamic cube map
Reply with quote

see here:

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

jp

Sebastien Nerig wrote:
Quote:
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








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



------------------
Post generated by Mail2Forum
Back to top
seb
User


Joined: 15 May 2009
Posts: 66

PostPosted: Wed Feb 10, 2010 11:22 am    Post subject:
Reply with quote

Hi Nick and JP
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
Back to top
View user's profile Send private message
Trajce Nikolov
Guest





PostPosted: Wed Feb 10, 2010 11:24 am    Post subject:
dynamic cube map
Reply with quote

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


On Wed, Feb 10, 2010 at 1:22 PM, Sebastien Nerig < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
Trajce Nikolov
Guest





PostPosted: Wed Feb 10, 2010 11:25 am    Post subject:
dynamic cube map
Reply with quote

the code I post assumes Z-up.-Nick


On Wed, Feb 10, 2010 at 1:24 PM, Trajce Nikolov < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
send me your code .. I will have a look -Nick



On Wed, Feb 10, 2010 at 1:22 PM, Sebastien Nerig < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org








------------------
Post generated by Mail2Forum
Back to top
seb
User


Joined: 15 May 2009
Posts: 66

PostPosted: Wed Feb 10, 2010 11:42 am    Post subject:
Reply with quote

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_ptr<osg::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
Back to top
View user's profile Send private message
Trajce Nikolov
Guest





PostPosted: Wed Feb 10, 2010 12:09 pm    Post subject:
dynamic cube map
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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_ptr<osg::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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
seb
User


Joined: 15 May 2009
Posts: 66

PostPosted: Wed Feb 10, 2010 1:27 pm    Post subject:
Reply with quote

mmm
I dont think it will work. I would like to make reflection into object that are not always plane.

Sebastien
Back to top
View user's profile Send private message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 41

PostPosted: Tue Dec 05, 2017 1:26 am    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11311

PostPosted: Tue Dec 05, 2017 8:09 am    Post subject:
dynamic cube map
Reply with quote

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 41

PostPosted: Wed Dec 06, 2017 1:37 am    Post subject:
Reply with quote

Thanks a lot, Robert!

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

...

Thank you!

Cheers,
Rômulo
Back to top
View user's profile Send private message
romulogcerqueira
User


Joined: 11 Jun 2015
Posts: 41

PostPosted: Wed Dec 06, 2017 2:08 am    Post subject:
Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Appending dynamic 3d line ertanataman General 2 Thu Jan 11, 2018 2:23 pm View latest post
No new posts Normal Mapping using Dynamic Cubemap romulogcerqueira General 6 Tue Dec 19, 2017 2:10 am View latest post
No new posts Dynamic Cubemap with OSG and Shader romulogcerqueira General 0 Tue Dec 05, 2017 1:27 am View latest post
No new posts Dynamic linking of fbx plugin and fbx... Vladimir Chebaev Submission 5 Mon Nov 14, 2016 1:20 pm View latest post
No new posts Drawing a textured cube cbuchner1 General 2 Fri Apr 08, 2016 8:31 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP