Skip to content

Commit

Permalink
LogDepthBuffer: cleanup names
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 7, 2015
1 parent 2f5fcdd commit 6c6ff05
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/osgEarthUtil/LogDepthBuffer.VertOnly.vert.glsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#version $GLSL_VERSION_STR
$GLSL_DEFAULT_PRECISION_FLOAT

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

uniform float oe_ldb_C;
uniform float oe_ldb_FC;
uniform float oe_logDepth_C;
uniform float oe_logDepth_FC;

void oe_ldb_vert(inout vec4 clip)
void oe_logDepth_vert(inout vec4 clip)
{
clip.z = (log2(max(1e-6,oe_ldb_C*clip.w+1.0))*oe_ldb_FC - 1.0) * clip.w;
clip.z = (log2(max(1e-6,oe_logDepth_C*clip.w+1.0))*oe_logDepth_FC - 1.0) * clip.w;
}
10 changes: 5 additions & 5 deletions src/osgEarthUtil/LogDepthBuffer.frag.glsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#version $GLSL_VERSION_STR
$GLSL_DEFAULT_PRECISION_FLOAT

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

uniform float oe_ldb_FC;
varying float oe_ldb_logz;
uniform float oe_logDepth_FC;
varying float oe_logDepth_logz;

void oe_ldb_frag(inout vec4 color)
void oe_logDepth_frag(inout vec4 color)
{
gl_FragDepth = log2(oe_ldb_logz)*0.5*oe_ldb_FC;
gl_FragDepth = log2(oe_logDepth_logz)*0.5*oe_logDepth_FC;
}
14 changes: 7 additions & 7 deletions src/osgEarthUtil/LogDepthBuffer.vert.glsl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#version $GLSL_VERSION_STR
$GLSL_DEFAULT_PRECISION_FLOAT

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

uniform float oe_ldb_C;
uniform float oe_ldb_FC;
varying float oe_ldb_logz;
uniform float oe_logDepth_C;
uniform float oe_logDepth_FC;
varying float oe_logDepth_logz;

void oe_ldb_vert(inout vec4 clip)
void oe_logDepth_vert(inout vec4 clip)
{
oe_ldb_logz = max(1e-6, clip.w*oe_ldb_C + 1.0);
clip.z = log2(oe_ldb_logz)*oe_ldb_FC - 1.0;
oe_logDepth_logz = max(1e-6, clip.w*oe_logDepth_C + 1.0);
clip.z = log2(oe_logDepth_logz)*oe_logDepth_FC - 1.0;
}
13 changes: 7 additions & 6 deletions src/osgEarthUtil/LogarithmicDepthBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define NEAR_RES_COEFF_STR "0.0005"
#define LOG2(X) (::log((double)(X))/::log(2.0))

#define C_UNIFORM "oe_logDepth_C"
#define FC_UNIFORM "oe_logDepth_FC"

using namespace osgEarth;
using namespace osgEarth::Util;

Expand Down Expand Up @@ -72,7 +75,7 @@ namespace
}

// the uniform conveying the far clip plane:
osg::Uniform* u = stateset->getOrCreateUniform("oe_ldb_FC", osg::Uniform::FLOAT);
osg::Uniform* u = stateset->getOrCreateUniform(FC_UNIFORM, osg::Uniform::FLOAT);

// calculate the far plane based on the camera location:
osg::Vec3d E, A, U;
Expand Down Expand Up @@ -130,12 +133,10 @@ LogarithmicDepthBuffer::install(osg::Camera* camera)
{
if ( camera && _supported )
{
OE_NOTICE <<" Installing LDB......\n";

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

stateset->addUniform( new osg::Uniform("oe_ldb_C", (float)NEAR_RES_COEFF) );
stateset->addUniform( new osg::Uniform(C_UNIFORM, (float)NEAR_RES_COEFF) );

VirtualProgram* vp = VirtualProgram::getOrCreate( stateset );
Shaders pkg;
Expand Down Expand Up @@ -180,8 +181,8 @@ LogarithmicDepthBuffer::uninstall(osg::Camera* camera)
pkg.unloadFunction( vp, pkg.LogDepthBuffer_VertOnly_VertFile );
}

stateset->removeUniform( "oe_ldb_FC" );
stateset->removeUniform( "oe_ldb_C" );
stateset->removeUniform( FC_UNIFORM );
stateset->removeUniform( C_UNIFORM );
}
}
}

0 comments on commit 6c6ff05

Please sign in to comment.