[osg-users] Loading a SilverLining environment map into an OpenSceneGraph texture

Chris Hardy hardyc02 at gmail.com
Wed Feb 14 08:34:18 PST 2018


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.

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







More information about the osg-users mailing list