查看: 951|回复: 1

osg中为相机添加着色器,着色器中的gl_FragmentColor指的是什么

[复制链接]

该用户从未签到

发表于 2015-12-7 22:35:41 | 显示全部楼层 |阅读模式
    g_HeightMap = new osg::Texture2D();
    g_HeightMap->setTextureSize(2048, 2048);
    g_HeightMap->setInternalFormat(GL_RGBA);
    g_HeightMap->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D:INEAR);
    g_HeightMap->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
    g_HeightMap->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
    g_HeightMap->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);

    // Create its camera and render to it
    model = osgDB::ReadNodeFile("D:\\xx.ive");
    g_HeightMapCamera = new osg::Camera;
    g_HeightMapCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    g_HeightMapCamera->setClearColor(osg::Vec4(-1000.0, -1000.0, -1000.0, 1.0f));
    g_HeightMapCamera->setViewport(0, 0, 2048, 2048);
    g_HeightMapCamera->setRenderOrder(osg::Camera:RE_RENDER);
    g_HeightMapCamera->attach(osg::Camera::COLOR_BUFFER, g_HeightMap);
    g_HeightMapCamera->addChild(model);
    g_HeightMapCamera->setProjectionMatrix(osg::Matrix:rtho2D(-HEIGHT_MAP_AREA,HEIGHT_MAP_AREA,-            HEIGHT_MAP_AREA,HEIGHT_MAP_AREA));
    g_HeightMapCamera->setCullingActive(false);
    g_HeightMapCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF_INHERIT_VIEWPOINT);
    g_HeightMapCamera->setImplicitBufferAttachmentMask(0, 0);
    g_HeightMapCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
    g_HeightMapCamera->getOrCreateStateSet()->setMode(GL_ALPHA_TEST,
            osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);

    osg::ref_ptr<osg::Program> heightMapProgram = new osg::Program;
    heightMapProgram->addShader(new osg::Shader(osg::Shader::VERTEX, HeightMapVertSource));
    heightMapProgram->addShader(new osg::Shader(osg::Shader::FRAGMENT, HeightMapFragSource));
其中的顶点着色器和片段着色器如下:

const char *HeightMapVertSource = {
    "varying float height;\n"
    "void main()\n"
    "{\n"
    "   vec4 worldVert = gl_Vertex;\n"
    "   height = worldVert.z;\n"
    "   gl_Position = gl_ModelViewProjectionMatrix * worldVert;\n"
    "   gl_ClipVertex = gl_ModelViewMatrix * worldVert;\n"
   "        gl_FrontColor = gl_Color;\n"
    "}\n"
};

const char *HeightMapFragSource = {
   "varying vec4 gl_Color;\n"
    "varying float height;\n"
    "void main()\n"
    "{\n"
    "   gl_FragColor = gl_Color;\n"
    "}\n"
};

为什么渲染出来的纹理显示的不是正常的场景呢。只是一块白色
无标题.jpg

该用户从未签到

发表于 2015-12-17 17:23:27 | 显示全部楼层
gl_FragColor 是最终的颜色呈现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表