Skip to content

Commit

Permalink
More shader upgrade work.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 6, 2015
1 parent ce5f96c commit 1ae910d
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include <osgEarthUtil/ContourMap>
#include <osgEarthUtil/LODBlending>
#include <osgEarthUtil/NormalMap>
#include <osgEarthUtil/VerticalScale>

#include <osgEarthSymbology/Color>
Expand Down Expand Up @@ -61,14 +60,12 @@ struct App

osg::ref_ptr<ContourMap> contourMap;
osg::ref_ptr<LODBlending> lodBlending;
osg::ref_ptr<NormalMap> normalMap;
osg::ref_ptr<VerticalScale> verticalScale;

App()
{
contourMap = new ContourMap();
lodBlending = new LODBlending();
normalMap = new NormalMap();
verticalScale = new VerticalScale();
}
};
Expand Down Expand Up @@ -131,15 +128,6 @@ struct LODBlendingController {
}
};

struct NormalMapController {
TOGGLE ( normalMap );
NormalMapController(App& app, ui::Grid* grid) {
int r = grid->getNumRows();
grid->setControl(0, r, new ui::LabelControl("NormalMap"));
grid->setControl(1, r, new ui::CheckBoxControl(false, new Toggle(app)));
}
};

struct VerticalScaleController {
TOGGLE ( verticalScale );
SET_FLOAT( verticalScale, setScale );
Expand All @@ -166,7 +154,6 @@ ui::Control* createUI( App& app )

ContourMapController (app, grid);
LODBlendingController (app, grid);
NormalMapController (app, grid);
VerticalScaleController (app, grid);

return grid;
Expand Down
13 changes: 3 additions & 10 deletions src/osgEarth/ClampingTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ ClampingTechnique::setUpCamera(OverlayDecorator::TechRTTParams& params)

#endif

// default value for altitude offset; can be overriden by geometry.
local->_groupStateSet->addUniform( new osg::Uniform("oe_clamp_altitudeOffset", 0.0f) );

// make the shader that will do clamping and depth offsetting.
VirtualProgram* vp = VirtualProgram::getOrCreate(local->_groupStateSet.get());
vp->setName( "GPUClamping" );
Expand Down Expand Up @@ -390,16 +393,6 @@ ClampingTechnique::cullOverlayGroup(OverlayDecorator::TechRTTParams& params,

LocalPerViewData& local = *static_cast<LocalPerViewData*>(params._techniqueData.get());

#if 0
osg::Vec3d eye, lookat, up;
params._rttViewMatrix.getLookAt(eye, lookat, up);
OE_WARN << "rtt eye=" << eye.x() << ", " << eye.y() << ", " << eye.z() << std::endl;

double left, right, bottom, top, n, f;
params._rttProjMatrix.getOrtho(left, right, bottom, top, n, f);
OE_WARN << "rtt prj=" << left << ", " << right << ", " << bottom << ", " << top << ", " << n << ", " << f << std::endl << std::endl;
#endif

// create the depth texture (render the terrain to tex)
params._rttCamera->accept( *cv );

Expand Down
15 changes: 8 additions & 7 deletions src/osgEarth/GPUClamping.vert.glsl
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#version 110
#version 120

#pragma vp_entryPoint "oe_clamp_vertex"
#pragma vp_location "vertex_view"

#pragma include "GPUClamping.vert.lib.glsl"

uniform float oe_clamp_altitudeOffset;
uniform float oe_clamp_horizonDistance2;
varying float oe_clamp_alpha;

// prototype; see GPUClamping.vert.lib.glsl
//void oe_getClampedViewVertex(in vec4 vertView,
// out vec4 out_clampedVertView,
// out float out_depth);

// clamp a vertex to the ground
void oe_clamp_vertex(inout vec4 vertexView)
{
Expand All @@ -29,7 +25,12 @@ void oe_clamp_vertex(inout vec4 vertexView)

// get the clamped vertex:
oe_getClampedViewVertex(vertexView, clampedVertexView, depth);
vertexView = clampedVertexView;

// apply the altitude offset.
vec3 up;
oe_getClampingUpVector(up);

vertexView.xyz = clampedVertexView.xyz + up*oe_clamp_altitudeOffset;

// if the clamped depth value is near the far plane, suppress drawing
// to avoid rendering anomalies.
Expand Down
6 changes: 6 additions & 0 deletions src/osgEarth/GPUClamping.vert.lib.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ void oe_getClampedViewVertex(in vec4 vertView,
// convert back into view space.
out_clampedVertView = oe_clamp_depthClip2cameraView * clampedVertDepthClip;
}

// Returns a vector indiciating the "down" direction.
void oe_getClampingUpVector(out vec3 up)
{
up = normalize(mat3(oe_clamp_depthClip2cameraView) * vec3(0,0,-1));
}
2 changes: 2 additions & 0 deletions src/osgEarthUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ set(SHADERS_CPP
"${CMAKE_CURRENT_BINARY_DIR}/AutoGenShaders.cpp")

set(TARGET_GLSL
ContourMap.vert.glsl
ContourMap.frag.glsl
Fog.vert.glsl
Fog.frag.glsl
LogDepthBuffer.vert.glsl
Expand Down
45 changes: 7 additions & 38 deletions src/osgEarthUtil/ContourMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <osgEarthUtil/ContourMap>
#include <osgEarthUtil/Shaders>
#include <osgEarth/Registry>
#include <osgEarth/Capabilities>
#include <osgEarth/VirtualProgram>
Expand All @@ -27,40 +28,6 @@
using namespace osgEarth;
using namespace osgEarth::Util;

namespace
{
const char* vs =
"#version " GLSL_VERSION_STR "\n"
GLSL_DEFAULT_PRECISION_FLOAT "\n"

"attribute vec4 oe_terrain_attr; \n"
"uniform float oe_contour_min; \n"
"uniform float oe_contour_range; \n"
"varying float oe_contour_lookup; \n"

"void oe_contour_vertex(inout vec4 VertexModel) \n"
"{ \n"
" float height = oe_terrain_attr[3]; \n"
" float height_normalized = (height-oe_contour_min)/oe_contour_range; \n"
" oe_contour_lookup = clamp( height_normalized, 0.0, 1.0 ); \n"
"} \n";


const char* fs =
"#version " GLSL_VERSION_STR "\n"
GLSL_DEFAULT_PRECISION_FLOAT "\n"

"uniform sampler1D oe_contour_xfer; \n"
"uniform float oe_contour_opacity; \n"
"varying float oe_contour_lookup; \n"

"void oe_contour_fragment( inout vec4 color ) \n"
"{ \n"
" vec4 texel = texture1D( oe_contour_xfer, oe_contour_lookup ); \n"
" color.rgb = mix(color.rgb, texel.rgb, texel.a * oe_contour_opacity); \n"
"} \n";
}


ContourMap::ContourMap() :
TerrainEffect()
Expand Down Expand Up @@ -162,8 +129,9 @@ ContourMap::onInstall(TerrainEngineNode* engine)
// before the terrain's layers.)
VirtualProgram* vp = VirtualProgram::getOrCreate(stateset);

vp->setFunction( "oe_contour_vertex", vs, ShaderComp::LOCATION_VERTEX_MODEL);
vp->setFunction( "oe_contour_fragment", fs, ShaderComp::LOCATION_FRAGMENT_COLORING ); //, -1.0);
Shaders pkg;
pkg.loadFunction(vp, pkg.ContourMap_Vertex);
pkg.loadFunction(vp, pkg.ContourMap_Fragment);

// Install some uniforms that tell the shader the height range of the color map.
stateset->addUniform( _xferMin.get() );
Expand Down Expand Up @@ -195,8 +163,9 @@ ContourMap::onUninstall(TerrainEngineNode* engine)
VirtualProgram* vp = VirtualProgram::get(stateset);
if ( vp )
{
vp->removeShader( "oe_contour_vertex" );
vp->removeShader( "oe_contour_fragment" );
Shaders pkg;
pkg.unloadFunction(vp, pkg.ContourMap_Vertex);
pkg.unloadFunction(vp, pkg.ContourMap_Fragment);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthUtil/LogDepthBuffer.VertOnly.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $GLSL_DEFAULT_PRECISION_FLOAT

#pragma vp_entryPoint "oe_ldb_vert"
#pragma vp_location "vertex_clip"
#pragma oe_order "FLT_MAX"
#pragma vp_order "FLT_MAX"

uniform float oe_ldb_C;
uniform float oe_ldb_FC;
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthUtil/LogDepthBuffer.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $GLSL_DEFAULT_PRECISION_FLOAT

#pragma vp_entryPoint "oe_ldb_frag"
#pragma vp_location "fragment_lighting"
#pragma oe_order "FLT_MAX"
#pragma vp_order "FLT_MAX"

uniform float oe_ldb_FC;
varying float oe_ldb_logz;
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthUtil/LogDepthBuffer.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $GLSL_DEFAULT_PRECISION_FLOAT

#pragma vp_entryPoint "oe_ldb_vert"
#pragma vp_location "vertex_clip"
#pragma oe_order "FLT_MAX"
#pragma vp_order "FLT_MAX"

uniform float oe_ldb_C;
uniform float oe_ldb_FC;
Expand Down
2 changes: 2 additions & 0 deletions src/osgEarthUtil/LogarithmicDepthBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ LogarithmicDepthBuffer::install(osg::Camera* camera)
{
if ( camera && _supported )
{
OE_NOTICE <<" Installing LDB......\n";

// install the shader component:
osg::StateSet* stateset = camera->getOrCreateStateSet();

Expand Down
3 changes: 3 additions & 0 deletions src/osgEarthUtil/Shaders
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace osgEarth { namespace Util
Shaders();

std::string
ContourMap_Vertex,
ContourMap_Fragment,

Fog_Vertex,
Fog_Fragment,

Expand Down
6 changes: 6 additions & 0 deletions src/osgEarthUtil/Shaders.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ using namespace osgEarth::Util;

Shaders::Shaders()
{
ContourMap_Vertex = "ContourMap.vert.glsl";
_sources[ContourMap_Vertex] = OE_MULTILINE(@ContourMap.vert.glsl@);

ContourMap_Fragment = "ContourMap.frag.glsl";
_sources[ContourMap_Fragment] = OE_MULTILINE(@ContourMap.frag.glsl@);

Fog_Vertex = "Fog.vert.glsl";
_sources[Fog_Vertex] == OE_MULTILINE(@Fog.vert.glsl@);

Expand Down

0 comments on commit 1ae910d

Please sign in to comment.