-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor bumpmap extensions into a layer
- Loading branch information
Showing
10 changed files
with
214 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* -*-c++-*- */ | ||
/* osgEarth - Geospatial SDK for OpenSceneGraph | ||
* Copyright 2020 Pelican Mapping | ||
* http://osgearth.org | ||
* | ||
* osgEarth is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
#pragma once | ||
|
||
#include "BumpMapOptions" | ||
#include "BumpMapTerrainEffect" | ||
#include <osgEarth/VisibleLayer> | ||
|
||
namespace osgEarth | ||
{ | ||
class TerrainEngine; | ||
|
||
/** | ||
* Layer that installs a bumpmapping terrain effect. | ||
*/ | ||
class BumpMapLayer : public VisibleLayer | ||
{ | ||
public: | ||
META_Layer(osgEarth, BumpMapLayer, BumpMapOptions, VisibleLayer, bumpmap); | ||
|
||
void prepareForRendering(TerrainEngine* engine) override; | ||
|
||
osg::ref_ptr<BumpMapTerrainEffect> _effect; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* -*-c++-*- */ | ||
/* osgEarth - Geospatial SDK for OpenSceneGraph | ||
* Copyright 2020 Pelican Mapping | ||
* http://osgearth.org | ||
* | ||
* osgEarth is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
#include "BumpMapLayer" | ||
#include "BumpMapTerrainEffect" | ||
|
||
#include <osgEarth/TerrainEngineNode> | ||
|
||
using namespace osgEarth; | ||
|
||
#define LC "[BumpMapLayer] " | ||
|
||
REGISTER_OSGEARTH_LAYER(bumpmap, BumpMapLayer); | ||
|
||
|
||
void | ||
BumpMapLayer::prepareForRendering(TerrainEngine* engine) | ||
{ | ||
if ( !engine ) | ||
return; | ||
|
||
osg::ref_ptr<osg::Image> image = options().imageURI()->getImage(getReadOptions()); | ||
if ( !image.valid() ) | ||
{ | ||
OE_WARN << LC << "Failed; unable to load normal map image from " | ||
<< options().imageURI()->full() << "\n"; | ||
return; | ||
} | ||
|
||
_effect = new BumpMapTerrainEffect(); | ||
|
||
_effect->setBumpMapImage(image.get()); | ||
|
||
if (options().intensity().isSet()) | ||
_effect->getIntensityUniform()->set(options().intensity().get()); | ||
|
||
if (options().scale().isSet()) | ||
_effect->getScaleUniform()->set(options().scale().get()); | ||
|
||
if (options().octaves().isSet()) | ||
_effect->setOctaves(options().octaves().get()); | ||
|
||
if (options().baseLOD().isSet()) | ||
_effect->setBaseLOD(options().baseLOD().get()); | ||
|
||
engine->addEffect(_effect); | ||
|
||
OE_DEBUG << LC << "Installed.\n"; | ||
|
||
onVisibleChanged([&](auto* layer) | ||
{ | ||
_effect->setActive(layer->getVisible()); | ||
}); | ||
} |
Oops, something went wrong.