在OSG中创建Sun光源 [英] Create Sun light source in OSG

查看:549
本文介绍了在OSG中创建Sun光源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在OpenSceneGraph中的景观上方设置一个点Source,它将像太阳一样起作用.我已经知道如何设置灯光,可以通过以下方式完成:

I need to set a point Source above my landscape in OpenSceneGraph that will act like a sun. I already know how to set up the light and it can be done in this fashion:

//LIGHT CODE ------------------------
osg::ref_ptr<osg::Group> lightGroup (new osg::Group);
osg::ref_ptr<osg::StateSet> lightSS (root->getOrCreateStateSet());
osg::ref_ptr<osg::LightSource> lightSource1 = new osg::LightSource;
osg::ref_ptr<osg::LightSource> lightSource2 = new osg::LightSource;

// create a local light.

float xCenter = tree->getRoot()->getXCenter();
float yCenter = tree->getRoot()->getYCenter();


osg::Vec4f lightPosition (osg::Vec4f(xCenter, yCenter,75.0,1.0f));
osg::ref_ptr<osg::Light> myLight = new osg::Light;
myLight->setLightNum(1);
myLight->setPosition(lightPosition);
    myLight->setAmbient(osg::Vec4(0.8f,0.8f,0.8f,1.0f));
    myLight->setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f));
    myLight->setConstantAttenuation(1.0f);
    myLight->setDirection(osg::Vec3(0.0f, 0.0f, -1.0f));
lightSource1->setLight(myLight.get());

lightSource1->setLocalStateSetModes(osg::StateAttribute::ON); 
lightSource1->setStateSetModes(*lightSS,osg::StateAttribute::ON);
//osg::StateSet* lightSS (lightGroup->getOrCreateStateSet());

lightGroup->addChild(lightSource1.get());

//Light markers: small spheres
osg::ref_ptr<osg::Geode> lightMarkerGeode (new osg::Geode);
lightMarkerGeode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(xCenter,yCenter,75),10.0f)));


//Tuto 9: lighting code
root->addChild(lightGroup.get());
//Tuto 9: Adding the light marker geode
root->addChild(lightMarkerGeode.get());

//LIGHTCODE END----------------

这将产生一个看起来像这样的风景:

And this will produce a landscape that looks like this:

上面有灯光的风景(灯光由球体表示)

The Landscape with light above (Light is indicated by the sphere)

尽管如此,这种光源似乎并没有真正改变景观. 问题是使太阳模拟光需要什么样的光设置(即环境,扩散等).

This light source doesn't really seem to make a difference to the landscape though. The question is what sort of light settings (ie. ambiance, diffusion etc) are needed to make a Sun emulating light.

推荐答案

对于有价值的东西,OSG论坛/邮件列表通常可以很好地回答问题: http://forum.openscenegraph.org/

For what it's worth, the OSG forum/mailing list is usually pretty good about answering questions: http://forum.openscenegraph.org/

要在此处回答您的问题-这取决于您要照明的材料的属性.

To try to answer your question here - it depends on the properties of the material you are trying to light.

我发现我加载的某些模型上的材质只会对3种光源类型中的一种做出反应(具体来说,某些模型仅是镜面反射的),因此我只打开所有3种光源:

I've found that materials on some models I load will only react to one particular of the 3 light types (specifically, some model are specular-only), so I just turn on all 3:

osg::Light *light = new osg::Light;
light->setAmbient(osg::Vec4(1.0,1.0,1.0,1.0));
light->setDiffuse(osg::Vec4(1.0,1.0,1.0,1.0));
light->setSpecular(osg::Vec4(1,1,1,1));  // some examples don't have this one

根据您的情况,您也许可以重新定义地形的环境和/或漫反射属性.

For your case, you might alternatively be able to redefine the ambient and/or diffuse properties of your terrain.

这篇关于在OSG中创建Sun光源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆