Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <uwsim/SkyDome.h>
00019 #include <osgOcean/ShaderManager>
00020
00021 SkyDome::SkyDome(void)
00022 {
00023
00024 }
00025
00026 SkyDome::SkyDome(const SkyDome& copy, const osg::CopyOp& copyop) :
00027 SphereSegment(copy, copyop)
00028 {
00029
00030 }
00031
00032 SkyDome::SkyDome(float radius, unsigned int longSteps, unsigned int latSteps, osg::TextureCubeMap* cubemap)
00033 {
00034 compute(radius, longSteps, latSteps, 90.f, 180.f, 0.f, 360.f);
00035 setupStateSet(cubemap);
00036 }
00037
00038 SkyDome::~SkyDome(void)
00039 {
00040 }
00041
00042 void SkyDome::create(float radius, unsigned int latSteps, unsigned int longSteps, osg::TextureCubeMap* cubemap)
00043 {
00044 compute(radius, longSteps, latSteps, 90.f, 180.f, 0.f, 360.f);
00045 setupStateSet(cubemap);
00046 }
00047
00048 void SkyDome::setupStateSet(osg::TextureCubeMap* cubemap)
00049 {
00050 osg::StateSet* ss = new osg::StateSet;
00051
00052 ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
00053 ss->setTextureAttributeAndModes(0, cubemap, osg::StateAttribute::ON);
00054 ss->setAttributeAndModes(createShader().get(), osg::StateAttribute::ON);
00055 ss->addUniform(new osg::Uniform("uEnvironmentMap", 0));
00056
00057 setStateSet(ss);
00058 }
00059
00060 osg::ref_ptr<osg::Program> SkyDome::createShader(void)
00061 {
00062 osg::ref_ptr < osg::Program > program = new osg::Program;
00063
00064
00065 if (osgOcean::ShaderManager::instance().areShadersEnabled())
00066 {
00067 char vertexSource[] = "varying vec3 vTexCoord;\n"
00068 "\n"
00069 "void main(void)\n"
00070 "{\n"
00071 " gl_Position = ftransform();\n"
00072 " vTexCoord = gl_Vertex.xyz;\n"
00073 "}\n";
00074
00075 char fragmentSource[] = "uniform samplerCube uEnvironmentMap;\n"
00076 "varying vec3 vTexCoord;\n"
00077 "\n"
00078 "void main(void)\n"
00079 "{\n"
00080 " vec3 texcoord = vec3(vTexCoord.x, vTexCoord.y, -vTexCoord.z);\n"
00081 " gl_FragData[0] = textureCube( uEnvironmentMap, texcoord.xzy );\n"
00082 " gl_FragData[0].a = 0.0;\n"
00083 " gl_FragData[1] = vec4(0.0);\n"
00084 "}\n";
00085
00086 program->setName("sky_dome_shader");
00087 program->addShader(new osg::Shader(osg::Shader::VERTEX, vertexSource));
00088 program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragmentSource));
00089 }
00090
00091 return program;
00092 }