PlanarReflection::PlanarReflection( osg::Camera * sceneCamera )
{
    int w = 1024, h = 1024;
    _sceneCamera = sceneCamera;

    _texture = new osg::Texture2D;
    _texture->setInternalFormat( GL_RGBA );
    _texture->setSourceFormat( GL_RGBA );
    _texture->setSourceType( GL_UNSIGNED_BYTE );
    _texture->setTextureWidth( w );
    _texture->setTextureHeight( h );
    _texture->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
    _texture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST );
    _textureProjectionMatrix = new osg::RefMatrix();

    // set up the background color and clear mask.
    setClearColor(osg::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
    setClearMask( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

    setViewport( 0,0,w,h );
    setReferenceFrame( osg::Transform::ABSOLUTE_RF );

    // set the camera to render before the main camera.
    setRenderOrder(osg::Camera::PRE_RENDER);
    attach( osg::Camera::COLOR_BUFFER, _texture );

    setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
}
Exemplo n.º 2
0
DisplayTexture::DisplayTexture()
{
    setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    setRenderOrder(osg::Camera::POST_RENDER);
    setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    setViewMatrix(osg::Matrix());
    setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1));
    getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF);
    addChild(createFullscreenQuad());

    setName("Display");

}
Exemplo n.º 3
0
    Refraction()
    {
        unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water");
        setRenderOrder(osg::Camera::PRE_RENDER);
        setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
        setReferenceFrame(osg::Camera::RELATIVE_RF);
        setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water"));
        setName("RefractionCamera");

        setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|Mask_Lighting);
        setNodeMask(Mask_RenderToTexture);
        setViewport(0, 0, rttSize, rttSize);

        // No need for Update traversal since the scene is already updated as part of the main scene graph
        // A double update would mess with the light collection (in addition to being plain redundant)
        setUpdateCallback(new NoTraverseCallback);

        // No need for fog here, we are already applying fog on the water surface itself as well as underwater fog
        // assign large value to effectively turn off fog
        // shaders don't respect glDisable(GL_FOG)
        osg::ref_ptr<osg::Fog> fog (new osg::Fog);
        fog->setStart(10000000);
        fog->setEnd(10000000);
        getOrCreateStateSet()->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);

        mClipCullNode = new ClipCullNode;
        addChild(mClipCullNode);

        mRefractionTexture = new osg::Texture2D;
        mRefractionTexture->setTextureSize(rttSize, rttSize);
        mRefractionTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
        mRefractionTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
        mRefractionTexture->setInternalFormat(GL_RGB);
        mRefractionTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
        mRefractionTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);

        attach(osg::Camera::COLOR_BUFFER, mRefractionTexture);

        mRefractionDepthTexture = new osg::Texture2D;
        mRefractionDepthTexture->setSourceFormat(GL_DEPTH_COMPONENT);
        mRefractionDepthTexture->setInternalFormat(GL_DEPTH_COMPONENT24);
        mRefractionDepthTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
        mRefractionDepthTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
        mRefractionDepthTexture->setSourceType(GL_UNSIGNED_INT);
        mRefractionDepthTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
        mRefractionDepthTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);

        attach(osg::Camera::DEPTH_BUFFER, mRefractionDepthTexture);
    }
Exemplo n.º 4
0
	void WeaponHUD::createWeaponHUD() {
	
		ref_ptr<Node> crow = osgDB::readNodeFile("../BlenderFiles/exports/Brecheisen.ive");
	/*
	 * here a transformation is applied to the crowbar to show 
	 * it at the lower right of the screen as if it is held in
	 * the right hand
	 */
		ref_ptr<MatrixTransform> crowTransform = new MatrixTransform;
        crowTransform->setMatrix(
         Matrix::rotate(osg::DegreesToRadians(3.0f), Y_AXIS)
       * Matrix::rotate(DegreesToRadians(190.0f), Z_AXIS)
       * Matrix::translate(osg::Vec3(1.0f, 1.5f, -1.5f))
                                );
		crowTransform->addChild(crow);
	/*
	 * adjusting the shininess to give the crowbar a good appearance 
	 */
        brtr::ModifyMaterialVisitor mmv;
        mmv.setShininess(42).setSpecular(Vec4(0.4, 0.4, 0.4, 1));
        crow->accept(mmv);
	/*
	 * Adding a weapon switch to enable multiple weapon use
	 */
        ref_ptr<Switch> switcher = new Switch;
        switcher->addChild(crowTransform, true);
        _switcher = switcher;
        _handler = new WeaponSwitchHandler(switcher);

        ref_ptr<brtr::CelShading> celshade = new brtr::CelShading;
        celshade->addChild(switcher);
        celshade->setNodeMask(~brtr::interactionAndCollisionMask);

		setClearMask(GL_DEPTH_BUFFER_BIT);
		setRenderOrder(Camera::POST_RENDER);
        setReferenceFrame(Camera::ABSOLUTE_RF);
        setProjectionMatrixAsPerspective(100, 1, 0.001, 5);
		
        setViewMatrixAsLookAt(Vec3(), Vec3(0,1,0), Z_AXIS);
        getOrCreateStateSet()->setMode(GL_LIGHTING, StateAttribute::OFF | StateAttribute::PROTECTED | StateAttribute::OVERRIDE);
        addChild(celshade);
	}
Exemplo n.º 5
0
    Reflection()
    {
        setRenderOrder(osg::Camera::PRE_RENDER);
        setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
        setReferenceFrame(osg::Camera::RELATIVE_RF);
        setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water"));
        setName("ReflectionCamera");

        bool reflectActors = Settings::Manager::getBool("reflect actors", "Water");

        setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_ParticleSystem|Mask_Sky|Mask_Player|Mask_Lighting|(reflectActors ? Mask_Actor : 0));
        setNodeMask(Mask_RenderToTexture);

        unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water");
        setViewport(0, 0, rttSize, rttSize);

        // No need for Update traversal since the mSceneRoot is already updated as part of the main scene graph
        // A double update would mess with the light collection (in addition to being plain redundant)
        setUpdateCallback(new NoTraverseCallback);

        mReflectionTexture = new osg::Texture2D;
        mReflectionTexture->setInternalFormat(GL_RGB);
        mReflectionTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
        mReflectionTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
        mReflectionTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
        mReflectionTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);

        attach(osg::Camera::COLOR_BUFFER, mReflectionTexture);

        // XXX: should really flip the FrontFace on each renderable instead of forcing clockwise.
        osg::ref_ptr<osg::FrontFace> frontFace (new osg::FrontFace);
        frontFace->setMode(osg::FrontFace::CLOCKWISE);
        getOrCreateStateSet()->setAttributeAndModes(frontFace, osg::StateAttribute::ON);

        mClipCullNode = new ClipCullNode;
        addChild(mClipCullNode);
    }
Exemplo n.º 6
0
CInputFilter::EFilterStatus		
CInputFilter::CMouseButtonCondition::match(CEvent& event, void*,
				EActionMode& outMode)
{
	// check for hotkey events
	bool down;
	CEvent::Type type = event.getType();
	if (type == IPrimaryScreen::getButtonDownEvent()) {
		outMode = kModeTurnOn;
		down    = true;
	}
	else if (type == IPrimaryScreen::getButtonUpEvent()) {
		outMode = kModeTurnOff;
		down    = false;
	}
	else {
		return kNoMatch;
	}

	// check if it's the right button and modifiers
	IPlatformScreen::CButtonInfo* minfo =
		reinterpret_cast<IPlatformScreen::CButtonInfo*>(event.getData());
	if (minfo->m_button != m_button || getLastMask() != m_mask) {
		return kNoMatch;
	}

	// convert event type for toggled conditions
	if (getActionMode() != kModePass) {
		if (type != IPlatformScreen::getButtonDownEvent()) {
			return kDiscard;
		}
		outMode = getActionMode();
	}

	setClearMask(down ? m_mask : 0);
	return kMatch;
}
Exemplo n.º 7
0
void osaOSGHUD::Initialize( osg::GraphicsContext* gc ){

  // Set the intrinsic paramters
  setProjectionMatrixAsOrtho2D( 0, gc->getTraits()->width, 
				0, gc->getTraits()->height );
  setViewMatrix( osg::Matrix::identity() );
  setReferenceFrame( osg::Camera::ABSOLUTE_RF );
  setRenderOrder( osg::Camera::NESTED_RENDER );
  setClearMask( GL_DEPTH_BUFFER_BIT );
  
  getOrCreateStateSet()->setMode( GL_LIGHTING, GL_FALSE );
  getOrCreateStateSet()->setMode( GL_DEPTH_TEST, GL_FALSE );

  // don't capture events
  setAllowEventFocus(false);

  setGraphicsContext( gc );
  setViewport( gc->getTraits()->x,
	       gc->getTraits()->y,
	       gc->getTraits()->width, 
	       gc->getTraits()->height );

  // search for the HUD branch
  bool found = false;
  for( unsigned int i=0; i<root->getNumParents(); i++ ){
    
    osg::ref_ptr<osg::Node> parent = root->getParent( i );
    osg::ref_ptr<osg::Group> group = parent->asGroup();
    if( group != 0 ){
      for( unsigned int j=0; j<group->getNumChildren(); j++ ){
        osg::ref_ptr<osg::Node> child = group->getChild( j );
        if( child->getName() == "HUD" ){
          found = true;
          osg::ref_ptr<osg::Group> hud = child->asGroup();
          hud->addChild( this );
        }
      }
    }
  }
  
  if( !found ){
    
    // create/configure the hud branch
    osg::ref_ptr<osg::Group> hud = new osg::Group;
    hud->setName( "HUD" );
    hud->getOrCreateStateSet()->setRenderBinDetails( 1, "RenderBin" );
    hud->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
    
    // add this camera to the hud branch
    hud->addChild( this );
    
    // configure the world branch
    root->getOrCreateStateSet()->setRenderBinDetails( 2, "RenderBin" );
    root->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON);
    
    
    osg::ref_ptr<osg::Group> group = new osg::Group;
    group->addChild( hud );
    group->addChild( root );
    
    viewer->setSceneData( group.get() );
    
  }
  
}
Exemplo n.º 8
0
void
SkyDomeStage::internalInit()
{
    setClearMask( GL_DEPTH_BUFFER_BIT );
}
Exemplo n.º 9
0
void
SkyDomeStage::setEnable( bool enable )
{
    _enable = enable;
    setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}