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 

Loading a SilverLining environment map into an OpenSceneGraph texture


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Kanpachi
Newbie


Joined: 19 Apr 2017
Posts: 4

PostPosted: Wed Feb 14, 2018 4:34 pm    Post subject:
Loading a SilverLining environment map into an OpenSceneGraph texture
Reply with quote

Hi,

Perhaps this is as much a SilverLining question so I've reached out to Frank Kane, but I am attempting to use SilverLining’s GetEnvironmentMap to load an HDR cube map into an osg::TextureCubeMap for input into an image based lighting scheme. I can’t seem to figure out how to do this properly.

I’ve tried something like the following, based on these old forum posts I’ve found:
http://forum.openscenegraph.org/viewtopic.php?t=15277&view=next
http://forum.openscenegraph.org/viewtopic.php?t=12966&view=next

Code:
osg::TextureCubeMap* hdrEnvMap = new osg::TextureCubeMap;
hdrEnvMap->setTextureSize(width, height);
hdrEnvMap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
hdrEnvMap->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
hdrEnvMap->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
hdrEnvMap->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
hdrEnvMap->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
hdrEnvMap->setInternalFormat(GL_RGB16F);
hdrEnvMap->setSourceFormat(GL_RGB);
hdrEnvMap->setSourceType(GL_FLOAT);

osg::GraphicsContext* graphicsContext = camera->getGraphicsContext();
unsigned int cid = graphicsContext->getState()->getContextID();
osg::Texture::TextureObject* obj = hdrEnvMap->getTextureObject(cid);
obj->setAllocated(true);

unsigned int handle = obj->id();
void* ptr = &handle;
atmosphere->GetEnvironmentMap(ptr, 6);

osg::Texture::TextureObject *textureObject = new osg::Texture::TextureObject(hdrEnvMap, handle, GL_TEXTURE_CUBE_MAP);
textureObject->setAllocated();
hdrEnvMap->setTextureObject(cid, textureObject);
osg::State *state = camera->getGraphicsContext()->getState();

state->setActiveTextureUnit(0);
hdrEnvMap->apply(*state);
state->haveAppliedTextureAttribute(0, hdrEnvMap);


The environment map seems like it’s being returned correctly, as GetEnvironmentMap returns true, and I call it elsewhere in my codebase to pass to Triton for reflections, which also works okay. So I think it’s a matter of not knowing how to initialize the cube map object in OSG properly.

Thanks in advance for any insight.

Chris
Back to top
View user's profile Send private message
Kanpachi
Newbie


Joined: 19 Apr 2017
Posts: 4

PostPosted: Thu Feb 15, 2018 2:51 pm    Post subject:
Reply with quote

It turns out this is pretty easy, I just made a couple of silly uncaffeinated mistakes. In case anyone gets stuck in the same hole, all you have to do is create your own TextureObject and assign it to the TextureCubeMap.

Perhaps there are some finer details missing in this solution but the output on the screen is at least accurate to what I want for the moment.

Code:

unsigned int handle;
void* ptr = &handle;
atm->GetEnvironmentMap(ptr, 6);

osg::TextureCubeMap* hdrEnvMap = new osg::TextureCubeMap;
osg::Texture::TextureObject* textureObject = new osg::Texture::TextureObject(hdrEnvMap, (GLuint)ptr, GL_TEXTURE_CUBE_MAP);
hdrEnvMap->setTextureObject(camera->getGraphicsContext()->getState()->getContextID(), textureObject);


My reflections are the wrong way around but that's my own problem I suppose. Razz
Back to top
View user's profile Send private message
Trajce Nikolov NICK
Guest





PostPosted: Fri Feb 16, 2018 2:50 pm    Post subject:
Loading a SilverLining environment map into an OpenSceneGraph texture
Reply with quote

Hi,

you can get inspiration from the OpenIG project (http://openig.compro.net) , there is a SilverLining plugin (https://github.com/CCSI-CSSI/MuseOpenIG/tree/master/Plugin-SilverLining) with reflections working together with Triton


On Thu, Feb 15, 2018 at 3:51 PM, Chris Hardy < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
It turns out this is pretty easy, I just made a couple of silly uncaffeinated mistakes. In case anyone gets stuck in the same hole, all you have to do is create your own TextureObject and assign it to the TextureCubeMap.

Perhaps there are some finer details missing in this solution but the output on the screen is at least accurate to what I want for the moment.


Code:

unsigned int handle;
void* ptr = &handle;
atm->GetEnvironmentMap(ptr, 6);

osg::TextureCubeMap* hdrEnvMap = new osg::TextureCubeMap;
osg::Texture::TextureObject* textureObject = new osg::Texture::TextureObject(hdrEnvMap, (GLuint)ptr, GL_TEXTURE_CUBE_MAP);
hdrEnvMap->setTextureObject(camera->getGraphicsContext()->getState()->getContextID(), textureObject);




My reflections are the wrong way around but that's my own problem I suppose. Razz

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




_______________________________________________
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





--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
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 DirectX Texture Stage Sets to OSG sbrkopac General 2 Tue Dec 04, 2018 8:47 pm View latest post
No new posts reflection on mesh texture nonnenmacher General 2 Tue Nov 06, 2018 7:58 pm View latest post
No new posts Mapping texture coordinates to a port... ijwolf8 General 0 Thu Oct 25, 2018 8:11 pm View latest post
No new posts OpenSceneGraph 3.0 for beginners book... NoeMurr General 5 Fri Oct 12, 2018 3:55 pm View latest post
No new posts OpenSceneGraph-3.6.3 stable release h... robertosfield General 0 Fri Sep 14, 2018 10:39 am 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