예제 #1
0
void
PointDrawable::setupState()
{
    // Create the singleton state set for the shader. This stateset will be
    // shared by all PointDrawable instances so OSG will sort them together.
    if (!_sharedStateSet.valid())
    {
        static Threading::Mutex s_mutex;
        s_mutex.lock();
        if (!_sharedStateSet.valid())
        {
            _sharedStateSet = new osg::StateSet();

            _sharedStateSet->setTextureAttributeAndModes(0, new osg::PointSprite(), osg::StateAttribute::ON);

            if (_gpu)
            {
                VirtualProgram* vp = VirtualProgram::getOrCreate(_sharedStateSet.get());
                Shaders shaders;
                shaders.load(vp, shaders.PointDrawable);
                _sharedStateSet->setMode(GL_PROGRAM_POINT_SIZE, 1);
            }
            else
            {
                //todo
            }

            s_isCoreProfile = Registry::capabilities().isCoreProfile();
        }
        s_mutex.unlock();
    }
}
예제 #2
0
void
ContourMap::onUninstall(TerrainEngineNode* engine)
{
    if ( engine )
    {
        osg::StateSet* stateset = engine->getStateSet();
        if ( stateset )
        {
            stateset->removeUniform( _xferMin.get() );
            stateset->removeUniform( _xferRange.get() );
            stateset->removeUniform( _xferSampler.get() );
            stateset->removeUniform( _opacityUniform.get() );

            stateset->removeTextureAttribute( _unit, osg::StateAttribute::TEXTURE );

            VirtualProgram* vp = VirtualProgram::get(stateset);
            if ( vp )
            {
                Shaders pkg;
                pkg.unload(vp, pkg.ContourMap_Vertex);
                pkg.unload(vp, pkg.ContourMap_Fragment);
            }
        }

        if ( _unit >= 0 )
        {
            engine->getResources()->releaseTextureImageUnit( _unit );
            _unit = -1;
        }
    }
}
예제 #3
0
void ShaderComposer::addShaderToProgram(Program* program, const Shaders& shaders)
{
    ShaderMainMap::iterator itr = _shaderMainMap.find(shaders);
    if (itr == _shaderMainMap.end())
    {
        // no vertex shader in map yet, need to compose a new main shader
        osg::Shader* mainShader = composeMain(shaders);
        _shaderMainMap[shaders] = mainShader;
        program->addShader(mainShader);
    }
    else
    {
        program->addShader(itr->second.get());
    }

    for(Shaders::const_iterator itr = shaders.begin();
        itr != shaders.end();
        ++itr)
    {
        Shader* shader = const_cast<Shader*>(*itr);
        if (!(shader->getShaderSource().empty()) || shader->getShaderBinary())
        {
            program->addShader(shader);
        }
    }
}
예제 #4
0
void
BumpMapTerrainEffect::onUninstall(TerrainEngineNode* engine)
{
    osg::StateSet* stateset = engine->getStateSet();
    if ( stateset )
    {
        if ( _bumpMapTex.valid() )
        {
            stateset->removeUniform("oe_bumpmap_maxRange");
            stateset->removeUniform("oe_bumpmap_octaves");
            stateset->removeUniform( _scaleUniform.get() );
            stateset->removeUniform( _intensityUniform.get() );
            stateset->removeUniform( _bumpMapTexUniform.get() );
            stateset->removeTextureAttribute( _bumpMapUnit, osg::StateAttribute::TEXTURE );
        }

        VirtualProgram* vp = VirtualProgram::get(stateset);
        if ( vp )
        {
            Shaders pkg;
            pkg.unloadAll( vp );
        }
    }
    
    if ( _bumpMapUnit >= 0 )
    {
        engine->getResources()->releaseTextureImageUnit( _bumpMapUnit );
        _bumpMapUnit = -1;
    }
}
예제 #5
0
void
LogarithmicDepthBuffer::install(osg::Camera* camera)
{
    if ( camera && _supported )
    {
        // install the shader component:
        osg::StateSet* stateset = camera->getOrCreateStateSet();

        if ( _useFragDepth )
        {
            stateset->addUniform( new osg::Uniform(C_UNIFORM, (float)NEAR_RES_COEFF) );
        }
        
        VirtualProgram* vp = VirtualProgram::getOrCreate( stateset );
        Shaders pkg;

        if ( _useFragDepth )
        {
            pkg.loadFunction( vp, pkg.LogDepthBuffer_VertFile );
            pkg.loadFunction( vp, pkg.LogDepthBuffer_FragFile );
        }
        else
        {
            pkg.loadFunction( vp, pkg.LogDepthBuffer_VertOnly_VertFile );
        }

        osg::ref_ptr<osg::Camera::DrawCallback> next = camera->getPreDrawCallback();
        if ( dynamic_cast<SetFarPlaneUniformCallback*>(next.get()) )
            next = static_cast<SetFarPlaneUniformCallback*>(next.get())->_next.get();
        
        stateset->addUniform( _FCUniform.get() );

        camera->setPreDrawCallback( new SetFarPlaneUniformCallback(_FCUniform.get(), next.get()) );
    }
}
void
BumpMapTerrainEffect::onInstall(TerrainEngineNode* engine)
{
    if ( engine && _bumpMapTex.valid() )
    {
        osg::StateSet* stateset = engine->getTerrainStateSet();

        // install the NormalMap texture array:
        if ( engine->getResources()->reserveTextureImageUnit(_bumpMapUnit, "BumpMap") )
        {
            // NormalMap sampler
            _bumpMapTexUniform = stateset->getOrCreateUniform(BUMP_SAMPLER, osg::Uniform::SAMPLER_2D);
            _bumpMapTexUniform->set( _bumpMapUnit );
            stateset->setTextureAttribute( _bumpMapUnit, _bumpMapTex.get(), osg::StateAttribute::ON );

            // configure shaders
            VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);

            Shaders package;            
            package.define( "OE_USE_NORMAL_MAP", engine->normalTexturesRequired() );

            package.loadFunction( vp, package.VertexModel );
            package.loadFunction( vp, package.VertexView );
            package.loadFunction( vp, _octaves <= 1? package.FragmentSimple : package.FragmentProgressive );

            if ( _octaves > 1 )
                stateset->addUniform(new osg::Uniform("oe_bumpmap_octaves", _octaves));

            stateset->addUniform(new osg::Uniform("oe_bumpmap_maxRange", _maxRange));

            stateset->addUniform( _scaleUniform.get() );
            stateset->addUniform( _intensityUniform.get() );
        }
    }
}
예제 #7
0
RexTerrainEngineNode::RexTerrainEngineNode() :
TerrainEngineNode     ( ),
_terrain              ( 0L ),
_update_mapf          ( 0L ),
_tileCount            ( 0 ),
_tileCreationTime     ( 0.0 ),
_batchUpdateInProgress( false ),
_refreshRequired      ( false ),
_stateUpdateRequired  ( false )
{
    // unique ID for this engine:
    _uid = Registry::instance()->createUID();

    // always require elevation.
    _requireElevationTextures = true;

    // install an elevation callback so we can update elevation data
    _elevationCallback = new ElevationChangedCallback( this );

    // static shaders.
    if ( Registry::capabilities().supportsGLSL() )
    {
        osg::StateSet* stateset = getOrCreateStateSet();
        VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
        Shaders package;
        package.load(vp, package.SDK);
    }

    // TODO: replace with a "renderer" object that can return statesets
    // for different layer types, or something.
    _imageLayerStateSet = new osg::StateSet();
}
예제 #8
0
void
LogarithmicDepthBuffer::uninstall(osg::Camera* camera)
{
    if ( camera && _supported )
    {
        SetFarPlaneUniformCallback* dc = dynamic_cast<SetFarPlaneUniformCallback*>(camera->getPreDrawCallback());
        if ( dc )
        {
            osg::ref_ptr<osg::Camera::DrawCallback> next = dc->_next.get();
            camera->setPreDrawCallback( next.get() );
        }

        osg::StateSet* stateset = camera->getStateSet();
        if ( stateset )
        {
            VirtualProgram* vp = VirtualProgram::get( camera->getStateSet() );
            if ( vp )
            {
                Shaders pkg;
                pkg.unloadFunction( vp, pkg.LogDepthBuffer_FragFile );
                pkg.unloadFunction( vp, pkg.LogDepthBuffer_VertFile );
                pkg.unloadFunction( vp, pkg.LogDepthBuffer_VertOnly_VertFile );
            }

            stateset->removeUniform( FC_UNIFORM );
            stateset->removeUniform( C_UNIFORM );
        }
    }
}
예제 #9
0
파일: main.cpp 프로젝트: forevermzm/s096
int main( int argc, char **argv ) {
  try {
		size_t N = 13;
		size_t bufSize = 4 * N;
		float *buf = new float[bufSize];

		for( size_t i = 0; i < N; ++i ) {
			buf[4*i] = cosf( 2 * 3.1415f * float( i ) / float( N - 1 ) );
			buf[4*i+1] = sinf( 2 * 3.1415f * float( i ) / float( N - 1 ) );
			buf[4*i+2] = 0.0f;
			buf[4*i+3] = 1.0f;
			std::cout << buf[4*i] << " " << buf[4*i+1];
      std::cout << " " << buf[4*i+2] << " " << buf[4*i+3] << "\n";
    }

		Shaders shaders;
		shaders.addToVertexList( nBodyShaders::vertex1 );
		shaders.addToFragmentList( nBodyShaders::fragment1 );
    NBodyWindow window{ "N-Body Simulation", GlutWrapper::NDEBUG };
		window.init( argc, argv, 500, 500, &shaders, bufSize, buf );
		window.run();

		delete [] buf;
    return 0;
  } catch( const std::exception &e ) {
    std::cerr << "Error: " << e.what() << "\n";
    return 1;
  }
}
예제 #10
0
파일: Fog.cpp 프로젝트: 2php/osgearth
void FogEffect::attach( osg::StateSet* stateSet )
{
    VirtualProgram* vp = VirtualProgram::getOrCreate( stateSet );
    Shaders pkg;
    pkg.load( vp, pkg.Fog_Vertex );
    pkg.load( vp, pkg.Fog_Fragment );
    _statesets.push_back(stateSet);
}
예제 #11
0
void
DepthOffsetAdapter::setGraph(osg::Node* graph)
{
    if ( !_supported ) return;

    bool graphChanging =
        _graph.get() != graph;

    bool uninstall =
        (_graph.valid() && _graph->getStateSet()) &&
        (graphChanging || (_options.enabled() == false));

    bool install =
        (graph && graphChanging ) || 
        (graph && (_options.enabled() == true));

    // shader package:
    Shaders shaders;

    if ( uninstall )
    {
        OE_TEST << LC << "Removing depth offset shaders" << std::endl;

        // uninstall uniforms and shaders.
        osg::StateSet* s = _graph->getStateSet();
        s->removeUniform( _minBiasUniform.get() );
        s->removeUniform( _maxBiasUniform.get() );
        s->removeUniform( _minRangeUniform.get() );
        s->removeUniform( _maxRangeUniform.get() );
        
        shaders.unloadFunction( VirtualProgram::get(s), shaders.DepthOffsetVertex );
    }

    if ( install )
    {
        OE_TEST << LC << "Installing depth offset shaders" << std::endl;

        // install uniforms and shaders.
        osg::StateSet* s = graph->getOrCreateStateSet();
        s->addUniform( _minBiasUniform.get() );
        s->addUniform( _maxBiasUniform.get() );
        s->addUniform( _minRangeUniform.get() );
        s->addUniform( _maxRangeUniform.get() );
        
        shaders.loadFunction(VirtualProgram::getOrCreate(s), shaders.DepthOffsetVertex);        
    }

    if ( graphChanging )
    {
        _graph = graph;
    }

    // always set Dirty when setGraph is called sine it may be called anytime
    // the subgraph changes (as can be detected by a computeBound)
    _dirty = (_options.automatic() == true);
}
예제 #12
0
파일: Fog.cpp 프로젝트: 2php/osgearth
void FogEffect::detach( osg::StateSet* stateSet )
{
    VirtualProgram* vp = VirtualProgram::get(stateSet);
    if ( vp )
    {
        Shaders pkg;
        pkg.unload( vp, pkg.Fog_Vertex );
        pkg.unload( vp, pkg.Fog_Fragment );
    }
}
예제 #13
0
void
AlphaEffect::detach(osg::StateSet* stateset)
{
    if ( stateset && _installed )
    {
        stateset->removeUniform( _alphaUniform.get() );
        VirtualProgram* vp = VirtualProgram::get( stateset );
        if ( vp )
        {
            Shaders pkg;
            pkg.unload( vp, pkg.AlphaEffectFragment );
        }
    }
}
예제 #14
0
void
DrawInstanced::remove(osg::StateSet* stateset)
{
    if ( !stateset )
        return;

    VirtualProgram* vp = VirtualProgram::get(stateset);
    if ( !vp )
        return;

    Shaders pkg;
    pkg.unload( vp, pkg.InstancingVertex );

    stateset->removeUniform("oe_di_postex_TBO");
}
예제 #15
0
void
AlphaEffect::install(osg::StateSet* stateset)
{
    if (stateset)
    {
        VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
        if (vp)
        {
            vp->setName( "osgEarth.AlphaEffect" );
            Shaders pkg;
            pkg.load(vp, pkg.AlphaEffectFragment);
            stateset->addUniform(_alphaUniform.get());
        }
    }
}
예제 #16
0
파일: Mesh.cpp 프로젝트: ZimboPro/glfw_test
void Mesh::Draw(Shaders & shader) 
{
    unsigned int diffuseNr = 1;
    unsigned int specularNr = 1;
    unsigned int normalNr = 1;
    unsigned int heightNr = 1;
    for(size_t i = 0; i < this->_textures.size(); i++)
    {
        glActiveTexture(GL_TEXTURE0 + i); // activate proper texture unit before binding
        // retrieve texture number (the N in diffuse_textureN)
        std::string number;
        std::string name = this->_textures[i]._type;
        if(name == "texture_diffuse")
            number = std::to_string(diffuseNr++);
        else if(name == "texture_specular")
            number = std::to_string(specularNr++);
        else if(name == "texture_normal")
				number = std::to_string(normalNr++);
        else if(name == "texture_height")
            number = std::to_string(heightNr++);

        glUniform1i(glGetUniformLocation(shader.ID(), (name + number).c_str()), i);
        glBindTexture(GL_TEXTURE_2D, this->_textures[i]._id);
    }

    // draw mesh
    glBindVertexArray(VAO);
    glDrawElements(GL_TRIANGLES, this->_indices.size(), GL_UNSIGNED_INT, 0);
    glBindVertexArray(0);

    glActiveTexture(GL_TEXTURE0);
}
예제 #17
0
int _tmain(int argc, _TCHAR* argv[])
{
	ESContext esContext;

    esInitContext ( &esContext );

	esCreateWindow ( &esContext, "Hello Model", Globals::screenWidth, Globals::screenHeight, ES_WINDOW_RGB | ES_WINDOW_DEPTH);

	if ( Init ( &esContext ) != 0 )
		return 0;

	if (ppShaders.Init("../Resources/Shaders/PPShaderVS.vs", "../Resources/Shaders/PPShaderFS.fs") != 0)
		return 0;

	esRegisterDrawFunc ( &esContext, Draw );
	esRegisterUpdateFunc ( &esContext, Update );
	esRegisterKeyFunc ( &esContext, Key);

	esMainLoop ( &esContext );

	//releasing OpenGL resources
	CleanUp();

	//identifying memory leaks
	MemoryDump();
	printf("Press any key...\n");
	_getch();

	return 0;
}
예제 #18
0
int Init ( ESContext *esContext )
{
	glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );

	//triangle data (heap)
	Vertex verticesData[3];
	RotationMatrix.SetIdentity();
	verticesData[0].pos.x =  0.0f;  verticesData[0].pos.y =  0.5f;  verticesData[0].pos.z =  0.0f;
	verticesData[1].pos.x = -0.5f;  verticesData[1].pos.y = -0.5f;  verticesData[1].pos.z =  0.0f;
	verticesData[2].pos.x =  0.5f;  verticesData[2].pos.y = -0.5f;  verticesData[2].pos.z =  0.0f;

	verticesData[0].color.x = 0.5f;  verticesData[0].color.y = 1.0f;  verticesData[0].color.z = 0.3f;
	verticesData[1].color.x = 0.0f;  verticesData[1].color.y = 0.3f;  verticesData[1].color.z = 0.0f;
	verticesData[2].color.x = 0.1f;  verticesData[2].color.y = 0.1f;  verticesData[2].color.z = 0.3f;

	//buffer object
	glGenBuffers(1, &vboId); //buffer object name generation
	glBindBuffer(GL_ARRAY_BUFFER, vboId); //buffer object binding
	glBufferData(GL_ARRAY_BUFFER, sizeof(verticesData), verticesData, GL_STATIC_DRAW); //creation and initializion of buffer onject storage
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
예제 #19
0
bool Application::Init(std::string title, int xpos, int ypos, int width,int height, int flags)
{
	std::string tempTitle;
	tempTitle=  title + " " + GIT_DESCRIBE_VERSION;
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
		{
		return false;
		}
		
	//if (SDL_CreateWindowAndRenderer(width, height, SDL_WINDOW_OPENGL, &pWindow, &pRenderer) < 0)
	
	pWindow = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
	if (pWindow == NULL)
	
		{
		return false;
		}

	mainContext = SDL_GL_CreateContext(pWindow);

	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
	

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	SDL_GL_SetSwapInterval(1);

	GLenum glewError = glewInit();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	//Initialize Modelview Matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	AudioManager::Get().Init();

	bRunning = true;

	Shaders * pTempShader = new Shaders();
	pTempShader->LoadFromFile("simple");
	
	return true;
}
예제 #20
0
int Init ( ESContext *esContext )
{
	glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
	glEnable(GL_DEPTH_TEST);

	//triangle data (heap)
	FILE *pFile;
	fopen_s(&pFile, "../Resources/Models/Woman1.nfg", "r");
	fscanf_s(pFile, "NrVertices: %d", &vertices);
	Vertex *verticesData = new Vertex[vertices];
	for (int i = 0; i<vertices; i++) {
		fscanf_s(pFile, " %*d. pos:[%f, %f, %f]; norm:[%*f, %*f, %*f]; binorm:[%*f, %*f, %*f]; tgt:[%*f, %*f, %*f]; uv:[%f, %f]; ", &verticesData[i].pos.x, &verticesData[i].pos.y, &verticesData[i].pos.z, &verticesData[i].uv.x, &verticesData[i].uv.y);
	}

	//buffer object
	glGenBuffers(1, &vboId); //buffer object name generation
	glBindBuffer(GL_ARRAY_BUFFER, vboId); //buffer object binding
	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*vertices, verticesData, GL_STATIC_DRAW); //creation and initializion of buffer onject storage
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	fscanf_s(pFile, "NrIndices: %d", &indices);
	Index *indicesData = new Index[indices];
	for (int i = 0; i<indices/3; i++) {
		fscanf_s(pFile, " %*d. %u, %u, %u ", &indicesData[i].x, &indicesData[i].y, &indicesData[i].z);
	}
	
	glGenBuffers(1, &iboId);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboId);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*indices, indicesData, GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	fclose(pFile);

	glGenTextures(1, &textureHandle);
	glBindTexture(GL_TEXTURE_2D, textureHandle);
	int width, height, bpp;
	char* bufferTGA = LoadTGA("../Resources/Textures/Woman1.tga", &width, &height, &bpp);

	if (bpp == 24) {
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, bufferTGA);
	}
	else {
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bufferTGA);
	}
	delete []bufferTGA;

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glGenerateMipmap(GL_TEXTURE_2D);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	delete []verticesData;
	delete []indicesData;
	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
예제 #21
0
void
GeodeticGraticule::installEffect()
{
    if (_mapNode.valid() == false)
        return;

    // shader components
    osg::StateSet* stateset = _mapNode->getTerrainEngine()->getSurfaceStateSet();
    VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);

    // configure shaders
    Shaders package;
    package.load(vp, package.Graticule_Vertex);
    package.load(vp, package.Graticule_Fragment);
    
    stateset->addUniform(new osg::Uniform(COLOR_UNIFORM, options().color().get()));
    stateset->addUniform(new osg::Uniform(WIDTH_UNIFORM, options().lineWidth().get()));
}
void
GraticuleTerrainEffect::onUninstall(TerrainEngineNode* engine)
{
    osg::StateSet* stateset = engine->getTerrainStateSet();
    if ( stateset )
    {
        VirtualProgram* vp = VirtualProgram::get(stateset);
        if ( vp )
        {
            Shaders package;
            package.unloadFunction( vp, package.Graticule_Vertex );
            package.unloadFunction( vp, package.Graticule_Fragment );

            stateset->removeUniform( GraticuleOptions::resolutionUniformName() );
            stateset->removeUniform( GraticuleOptions::colorUniformName() );
            stateset->removeUniform( GraticuleOptions::lineWidthUniformName() );
        }
    }
}
예제 #23
0
GroundPlane::GroundPlane(Shaders& shaders) :
   mesh_{
      createIndexBufferObject(ground_indices),
      {
         createArrayBufferObject(
            ground_vertices,
            shaders.getAttributes(Attribute::VERTEX),
            3),
         createArrayBufferObject(
            ground_normals,
            shaders.getAttributes(Attribute::NORMAL),
            3),
      }
   },
   model_matrix_(shaders,
         glm::rotate(glm::scale(glm::mat4(), glm::vec3(20.0f)), 90.0f, glm::vec3(1, 0, 0))),
   blue_uniform_(shaders.getUniforms(Uniform::BLUE))
{
}
예제 #24
0
void
BumpMapTerrainEffect::onInstall(TerrainEngineNode* engine)
{
    if ( engine && _bumpMapTex.valid() )
    {
        osg::StateSet* stateset = engine->getSurfaceStateSet();

        // install the NormalMap texture array:
        if ( engine->getResources()->reserveTextureImageUnit(_bumpMapUnit, "BumpMap") )
        {
            // NormalMap sampler
            _bumpMapTexUniform = stateset->getOrCreateUniform(BUMP_SAMPLER, osg::Uniform::SAMPLER_2D);
            _bumpMapTexUniform->set( _bumpMapUnit );
            stateset->setTextureAttribute( _bumpMapUnit, _bumpMapTex.get() );

            // configure shaders
            VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);

            Shaders package;            
            package.define( "OE_USE_NORMAL_MAP", false ); //engine->normalTexturesRequired() );

            //package.load( vp, package.VertexModel );
            package.load( vp, package.VertexView );
            package.load( vp, _octaves <= 1? package.FragmentSimple : package.FragmentProgressive );

            if ( _octaves > 1 )
                stateset->addUniform(new osg::Uniform("oe_bumpmap_octaves", _octaves));

            stateset->addUniform(new osg::Uniform("oe_bumpmap_maxRange", _maxRange));
            stateset->addUniform(new osg::Uniform("oe_bumpmap_slopeFactor", 1.0f));
            stateset->addUniform(new osg::Uniform("oe_bumpmap_baseLOD", (float)_baseLOD));

            stateset->addUniform( _scaleUniform.get() );
            stateset->addUniform( _intensityUniform.get() );
        }
        else
        {
            OE_WARN << LC << "Failed to allocation a texture image unit!\n";
        }
    }
}
예제 #25
0
RexTerrainEngineNode::RexTerrainEngineNode() :
TerrainEngineNode     ( ),
_terrain              ( 0L ),
_update_mapf          ( 0L ),
_tileCount            ( 0 ),
_tileCreationTime     ( 0.0 ),
_batchUpdateInProgress( false ),
_refreshRequired      ( false ),
_stateUpdateRequired  ( false ),
_selectionInfo        ( 0L )
{
    // unique ID for this engine:
    _uid = Registry::instance()->createUID();

    // always require elevation.
    _requireElevationTextures = true;

    // Register our render bins protos.
    {
        // Mutex because addRenderBinPrototype isn't thread-safe.
        Threading::ScopedMutexLock lock(_renderBinMutex);

        // generate uniquely named render bin prototypes for this engine:
        //_surfaceRenderBinPrototype = new SurfaceBin();
        //osgUtil::RenderBin::addRenderBinPrototype( _surfaceRenderBinPrototype->getName(), _surfaceRenderBinPrototype.get() );
    }

    // install an elevation callback so we can update elevation data
    _elevationCallback = new ElevationChangedCallback( this );

    // static shaders.
    if ( Registry::capabilities().supportsGLSL() )
    {
        osg::StateSet* stateset = getOrCreateStateSet();
        VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);
        Shaders package;
        package.load(vp, package.SDK);
    }

    _surfaceSS = new osg::StateSet();
}
예제 #26
0
void
GeodeticGraticule::removeEffect()
{
    if (_mapNode.valid() == false)
        return;

    osg::StateSet* stateset = _mapNode->getTerrainEngine()->getSurfaceStateSet();
    if ( stateset )
    {
        VirtualProgram* vp = VirtualProgram::get(stateset);
        if ( vp )
        {
            Shaders package;
            package.unload( vp, package.Graticule_Vertex );
            package.unload( vp, package.Graticule_Fragment );

            stateset->removeUniform( COLOR_UNIFORM );
            stateset->removeUniform( WIDTH_UNIFORM );
        }
    }
}
예제 #27
0
int Init ( ESContext *esContext )
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glEnable(GL_DEPTH_TEST);
	m.SetIdentity();

	woman.loadModel("../Resources/Models/Woman1.nfg");
	woman.loadTexture("../Resources/Textures/Woman1.tga");

	//creation of shaders and program 
	return myShaders.Init("../Resources/Shaders/TriangleShaderVS.vs", "../Resources/Shaders/TriangleShaderFS.fs");

}
예제 #28
0
void
NormalMapTerrainEffect::onUninstall(TerrainEngineNode* engine)
{
    osg::StateSet* stateset = engine->getStateSet();
    if ( stateset )
    {
        VirtualProgram* vp = VirtualProgram::get(stateset);
        if ( vp )
        {
            Shaders package;
            package.unloadFunction( vp, package.Vertex );
            package.unloadFunction( vp, package.Fragment );
        }
        stateset->removeUniform( NORMAL_SAMPLER );
    }

    if ( _normalMapUnit >= 0 )
    {
        engine->getResources()->releaseTextureImageUnit( _normalMapUnit );
        _normalMapUnit = -1;
    }
}
예제 #29
0
void
NormalMapTerrainEffect::onInstall(TerrainEngineNode* engine)
{
    if ( engine )
    {
        engine->requireNormalTextures();

        engine->getResources()->reserveTextureImageUnit(_normalMapUnit, "NormalMap");
        engine->addTileNodeCallback( new NormalTexInstaller(this, _normalMapUnit) );

        // shader components
        osg::StateSet* stateset = engine->getTerrainStateSet();
        VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);

        // configure shaders
        Shaders package;
        package.loadFunction( vp, package.Vertex );
        package.loadFunction( vp, package.Fragment );

        stateset->addUniform( new osg::Uniform(NORMAL_SAMPLER, _normalMapUnit) );
    }
}
예제 #30
0
void
Sprite::Render(const Shaders& program)
{
   program.UseProgram();
   glBindVertexArray(m_vertexArrayBuffer);

   glm::mat4 modelMatrix;

   modelMatrix = glm::translate(modelMatrix, m_translateVal);
   modelMatrix = glm::translate(modelMatrix, glm::vec3((m_size.x / 2.0f) * m_scaleVal.x, (m_size.y / -2.0f) * m_scaleVal.y, 0.0f));
   modelMatrix = glm::rotate(modelMatrix, glm::radians(m_angle), glm::vec3(0.0f, 0.0f, 1.0f));
   modelMatrix = glm::translate(modelMatrix, glm::vec3((m_size.x / -2.0f) * m_scaleVal.x, (m_size.y / 2.0f) * m_scaleVal.y, 0.0f));
   modelMatrix = glm::scale(modelMatrix, glm::vec3(m_scaleVal, 1.0f));

   m_texture.Use(program.GetProgram());
   program.SetUniformFloatVec4(m_color, "color");
   program.SetUniformFloatMat4(Win_Window::GetInstance().GetProjection(), "projectionMatrix");
   program.SetUniformFloatMat4(modelMatrix, "modelMatrix");

   glDrawArrays(GL_TRIANGLES, 0, 6);
   glBindVertexArray(0);
}