日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

osg glsl添加半透明

發布時間:2024/1/1 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 osg glsl添加半透明 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一開始,沒有設置對,所以GLSL半透明沒出來,看了下例子,實際上很簡單,除了在片元著色器alpha設置外,還要啟動混合

osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_BLEND, osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

廢話不多說,上代碼

//點集合啟動半透明

#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>

#include <osg/Switch>
#include <osg/Types>
#include <osgText/Text>

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>

#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/SphericalManipulator>

#include <osgGA/Device>

#include
#include <osg/Shader>

osg::ref_ptrosg::Geode createPointsGeode()
{
osg::ref_ptrosg::Geode geode = new osg::Geode;
osg::ref_ptrosg::Geometry geom = new osg::Geometry;

osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; for (int i = 0; i < 100; i++) {float x = i * 10;for (int j = 0; j < 100; j++){float y = j * 10;for (int k = 0; k < 100; k++){float z = k * 10;vertices->push_back(osg::Vec3(x, y, z));}} } geom->setVertexArray(vertices); // osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; // colors->push_back(osg::Vec4(1.0f, 1.0f, 0.0f, 0.5f)); // geom->setColorArray(colors, osg::Array::BIND_OVERALL);osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0, -1.0f, 0.0f)); geom->setNormalArray(normals, osg::Array::BIND_OVERALL);geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, vertices->size())); geode->addDrawable(geom); return geode;

}

static const char * vertexShader =
{
“void main(void)\n”
“{\n”
" gl_Position = ftransform();\n"
“}\n”
};
static const char *psShader =
{
“void main(void)\n”
“{\n”
“gl_FragColor =vec4(0.0f,0.0f,1.0f,1.0f);\n”
“}\n”
};

int main()
{
osg::ref_ptrosg::Group grp = new osg::Group;
osg::ref_ptrosg::Geode geode = createPointsGeode();
grp->addChild(geode);
osg::ref_ptrosg::StateSet stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
osg::ref_ptrosg::Shader vs = new osg::Shader(osg::Shader::VERTEX, vertexShader);
osg::ref_ptrosg::Shader ps = new osg::Shader(osg::Shader::FRAGMENT, psShader);
osg::ref_ptrosg::Program program = new osg::Program;
program->addShader(vs);
program->addShader(ps);
stateset->setAttribute(program, osg::StateAttribute::ON);
osg::ref_ptrosgViewer::Viewer viewer = new osgViewer::Viewer;
viewer->setSceneData(grp);
viewer->run();

return 0;

}

總結

以上是生活随笔為你收集整理的osg glsl添加半透明的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。