java点光源,Openscenegraph SoftShadowMap点光源工件

Screen当光源非常靠近球体时,会出现第二个阴影,否则一切都会按原样运行......

资源:

#define ptr(x,y) osg::ref_ptr y = new x

添加光源:

ptr(osg::LightSource, lightSource);

lightSource->getLight()->setPosition(v4(0.0f, -8.0f, 8.0f, 1.0f));

lightSource->getLight()->setAmbient(v4(0.0f, 0.0f, 0.0f, 1.0f));

lightSource->getLight()->setDiffuse(v4(0.8f, 0.8f, 0.8f, 1.0f));

lightSource->getLight()->setLightNum(0);

场景创作:

osg::ref_ptr <:geode> grass = createTexture2DGeode(-50.0f, -50.0f, 0.0f, 100.0f, 100.0f, 0.0f, osg::Texture::REPEAT, 20.0f);

ptr(osg::ShapeDrawable, sphere);

sphere->setShape(new osg::Sphere(v3(0.0f, 0.0f, 5.0f), 5.0f));

sphere->setColor(v4(0.0f, 0.0f, 1.0f, 1.0f));

ptr(osgShadow::ShadowedScene, root);

osg::ref_ptr <:shadowsettings> settings = root->getShadowSettings();`

settings->setReceivesShadowTraversalMask(RECEIVE_SHADOW);

settings->setCastsShadowTraversalMask(CAST_SHADOW);

ptr(osgShadow::SoftShadowMap, softShadowMap);

root->setShadowTechnique(softShadowMap);

root->addChild(lightSource);

root->addChild(sphere);

root->addChild(grass);

纹理创建:

osg::Geode *createTexture2DGeode(float x, float y, float z, float width, float height, float high, osg::Texture::WrapMode wrapMode, float count)

{

osg::ref_ptr <:geometry> quad = osg::createTexturedQuadGeometry(v3(x, y, z), v3(width, 0.0f, 0.0f), v3(0.0f, height, high), count, count);

osg::ref_ptr <:image> image = osgDB::readImageFile("images/grass.png");

osg::ref_ptr <:texture2d> texture = new osg::Texture2D(image);

texture->setWrap(osg::Texture::WRAP_S, wrapMode);

texture->setWrap(osg::Texture::WRAP_T, wrapMode);

osg::Geode *geode = new osg::Geode;

geode->addDrawable(quad);

geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

return geode;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值