void TileNode::updateTileUniforms(const SelectionInfo& selectionInfo) { //assert(_surface.valid()); // update the tile key uniform const osg::BoundingBox& bbox = _surface->getAlignedBoundingBox(); float width = std::max( (bbox.xMax()-bbox.xMin()), (bbox.yMax()-bbox.yMin()) ); unsigned tw, th; _key.getProfile()->getNumTiles(_key.getLOD(), tw, th); _tileKeyUniform->set(osg::Vec4f(_key.getTileX(), th-_key.getTileY()-1.0f, _key.getLOD(), width)); // update the morph constants float start = (float)selectionInfo.visParameters(_key.getLOD())._fMorphStart; float end = (float)selectionInfo.visParameters(_key.getLOD())._fMorphEnd; float one_by_end_minus_start = end - start; one_by_end_minus_start = 1.0f/one_by_end_minus_start; osg::Vec2f morphConstants( end * one_by_end_minus_start, one_by_end_minus_start ); _tileMorphUniform->set( morphConstants ); const osg::Image* er = getElevationRaster(); if ( er ) { // pre-calculate texel-sampling scale and bias coefficients that allow us to sample // elevation textures on texel-center instead of edge: float size = (float)er->s(); osg::Vec2f elevTexelOffsets( (size-1.0f)/size, 0.5/size ); getOrCreateStateSet()->getOrCreateUniform("oe_tile_elevTexelCoeff", osg::Uniform::FLOAT_VEC2)->set(elevTexelOffsets); } }
bool TileNode::shouldSubDivide(TerrainCuller* culler, const SelectionInfo& selectionInfo) { unsigned currLOD = _key.getLOD(); EngineContext* context = culler->getEngineContext(); if (context->getOptions().rangeMode() == osg::LOD::PIXEL_SIZE_ON_SCREEN) { float pixelSize = -1.0; if (context->getEngine()->getComputeRangeCallback()) { pixelSize = (*context->getEngine()->getComputeRangeCallback())(this, *culler->_cv); } if (pixelSize <= 0.0) { pixelSize = culler->clampedPixelSize(getBound()); } return (pixelSize > context->getOptions().tilePixelSize().get() * 4); } else { float range = (float)selectionInfo.visParameters(currLOD+1)._visibilityRange2; if (currLOD < selectionInfo.getNumLODs() && currLOD != selectionInfo.getNumLODs()-1) { return _surface->anyChildBoxIntersectsSphere( culler->getViewPointLocal(), range, culler->getLODScale()); } } return false; }
bool TileNode::shouldSubDivide(osgUtil::CullVisitor* cv, const SelectionInfo& selectionInfo) { unsigned currLOD = _key.getLOD(); if (currLOD < selectionInfo.numLods() && currLOD != selectionInfo.numLods()-1) { return _surface->anyChildBoxIntersectsSphere( cv->getViewPointLocal(), (float)selectionInfo.visParameters(currLOD+1)._visibilityRange2, cv->getLODScale()); } return false; }
bool TileNode::shouldSubDivide(osg::NodeVisitor& nv, const SelectionInfo& selectionInfo, float lodScale) { unsigned currLOD = _key.getLOD(); if ( currLOD < selectionInfo.numLods() && currLOD != selectionInfo.numLods()-1) { osg::Vec3 cameraPos = nv.getViewPoint(); float radius2 = (float)selectionInfo.visParameters(currLOD+1)._visibilityRange2; return _surface->anyChildBoxIntersectsSphere(cameraPos, radius2, lodScale); } return false; }
void TileNode::updateTileUniforms(const SelectionInfo& selectionInfo) { //assert(_surface.valid()); // update the tile key uniform const osg::BoundingBox& bbox = _surface->getAlignedBoundingBox(); float width = std::max( (bbox.xMax()-bbox.xMin()), (bbox.yMax()-bbox.yMin()) ); unsigned tw, th; _key.getProfile()->getNumTiles(_key.getLOD(), tw, th); _tileKeyUniform->set(osg::Vec4f(_key.getTileX(), th-_key.getTileY()-1.0f, _key.getLOD(), width)); // update the morph constants float fStart = (float)selectionInfo.visParameters(_key.getLOD())._fMorphStart; float fEnd = (float)selectionInfo.visParameters(_key.getLOD())._fMorphEnd; float one_by_end_minus_start = fEnd - fStart; one_by_end_minus_start = 1.0f/one_by_end_minus_start; osg::Vec4f morphConstants( fStart , one_by_end_minus_start , fEnd * one_by_end_minus_start , one_by_end_minus_start ); _tileMorphUniform->set( morphConstants ); // Update grid dims float fGridDims = selectionInfo.gridDimX()-1; _tileGridDimsUniform->set(osg::Vec4f( fGridDims, fGridDims*0.5f, 2.0/fGridDims, selectionInfo.lodForMorphing(_key.getProfile()->getSRS()->isProjected()))); // update tile extents float fXExtents = fabs(bbox.xMax()-bbox.xMin()); float fYExtents = fabs(bbox.yMax()-bbox.yMin()); _tileExtentsUniform->set(osg::Vec4f(fXExtents,fYExtents,0,0)); const osg::Image* er = getElevationRaster(); if ( er ) { getOrCreateStateSet()->getOrCreateUniform("oe_tile_elevationSize", osg::Uniform::FLOAT)->set( (float)er->s() ); } }
bool TileNode::shouldSubDivide(osg::NodeVisitor& nv, const SelectionInfo& selectionInfo, float zoomFactor) { unsigned currLOD = _key.getLOD(); if ( currLOD < selectionInfo.numLods() && currLOD != selectionInfo.numLods()-1) { osg::Vec3 cameraPos = nv.getViewPoint(); #if OSGEARTH_REX_TILE_NODE_DEBUG_TRAVERSAL OE_INFO << LC <<cameraPos.x()<<" "<<cameraPos.y()<<" "<<cameraPos.z()<<" "<<std::endl; OE_INFO << LC <<"LOD Scale: "<<fZoomFactor<<std::endl; #endif float radius = (float)selectionInfo.visParameters(currLOD+1)._fVisibility; bool anyChildVisible = _surface->anyChildBoxIntersectsSphere(cameraPos, radius*radius, zoomFactor); return anyChildVisible; } return false; }