/usr/include/osgEarth/ShaderUtils is in libosgearth-dev 2.7.0+dfsg-2+b3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | /* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2015 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/>
*/
#ifndef OSGEARTH_SHADER_UTILS_H
#define OSGEARTH_SHADER_UTILS_H 1
#include <osgEarth/Common>
#include <osg/NodeCallback>
#include <osg/StateSet>
#include <osg/Uniform>
#include <osg/Light>
#include <osg/Material>
#include <osg/observer_ptr>
#include <osgDB/Options>
#include <map>
namespace osgEarth
{
/**
* ShaderPolicy encodes general behavior when deciding how to
* employ shaders in certain situations
*/
enum ShaderPolicy
{
SHADERPOLICY_DISABLE,
SHADERPOLICY_GENERATE,
SHADERPOLICY_INHERIT
};
/**
* Container for light uniforms
*/
//light product
struct osg_LightProducts
{
osg_LightProducts(int id);
osg::ref_ptr<osg::Uniform> ambient; // vec4
osg::ref_ptr<osg::Uniform> diffuse; // vec4
osg::ref_ptr<osg::Uniform> specular; //vec4
// GLSL strings
static std::string glslDefinition();
};
struct osg_LightSourceParameters
{
osg_LightSourceParameters(int id);
void setUniformsFromOsgLight(const osg::Light* light, osg::Matrix viewMatrix, const osg::Material* frontMat);
void applyState(osg::StateSet* stateset);
osg::ref_ptr<osg::Uniform> ambient; // vec4
osg::ref_ptr<osg::Uniform> diffuse; // vec4
osg::ref_ptr<osg::Uniform> specular; // vec4
osg::ref_ptr<osg::Uniform> position; // vec4
osg::ref_ptr<osg::Uniform> halfVector; // vec4
osg::ref_ptr<osg::Uniform> spotDirection; // vec3
osg::ref_ptr<osg::Uniform> spotExponent; // float
osg::ref_ptr<osg::Uniform> spotCutoff; // float
osg::ref_ptr<osg::Uniform> spotCosCutoff; // float
osg::ref_ptr<osg::Uniform> constantAttenuation; // float
osg::ref_ptr<osg::Uniform> linearAttenuation; // float
osg::ref_ptr<osg::Uniform> quadraticAttenuation; // float
//just store the light product in here
osg_LightProducts _frontLightProduct;
// GLSL strings
static std::string glslDefinition();
};
/**
* Preprocesses GLES shader source to include our osg_LightProducts and osg_LightSourceParameters
* definitions and uniforms.
*/
class OSGEARTH_EXPORT ShaderPreProcessor
{
public:
static void run(osg::Shader* shader);
};
/**
* A callback that will update the osgEarth lighting uniforms (based on the
* FFP lighting state) if necessary.
*/
class OSGEARTH_EXPORT UpdateLightingUniformsHelper : public osg::NodeCallback
{
public:
UpdateLightingUniformsHelper( bool useUpdateTraversal =false );
virtual ~UpdateLightingUniformsHelper();
void cullTraverse( osg::Node* node, osg::NodeVisitor* nv );
void updateTraverse( osg::Node* node );
public: // NodeCallback
// for use as a cull callback.
virtual void operator()(osg::Node*, osg::NodeVisitor* nv);
protected:
int _maxLights;
bool* _lightEnabled;
bool _lightingEnabled;
bool _dirty;
bool _applied;
bool _useUpdateTrav;
OpenThreads::Mutex _stateSetMutex;
//osg::ref_ptr<osg::Uniform> _lightingEnabledUniform;
osg::ref_ptr<osg::Uniform> _lightEnabledUniform;
std::vector<osg_LightSourceParameters> _osgLightSourceParameters;
};
/**
* Helper class for dealing with array uniforms. Array uniform naming works
* differently on different drivers (ATI vs NVIDIA), so this class helps mitigate
* those differences.
*/
class OSGEARTH_EXPORT ArrayUniform // : public osg::Referenced
{
public:
/** Empty array uniform */
ArrayUniform() { }
/**
* Creates or retrieves a named uniform array.
*/
ArrayUniform(
const std::string& name,
osg::Uniform::Type type,
osg::StateSet* stateSet,
unsigned size =1 );
/** dtor */
virtual ~ArrayUniform() { }
void attach(
const std::string& name,
osg::Uniform::Type type,
osg::StateSet* stateSet,
unsigned size =1 );
void detach();
void setElement( unsigned index, int value );
void setElement( unsigned index, unsigned value );
void setElement( unsigned index, bool value );
void setElement( unsigned index, float value );
void setElement( unsigned index, const osg::Matrix& value );
void setElement( unsigned index, const osg::Vec3& value );
bool getElement( unsigned index, int& out_value ) const;
bool getElement( unsigned index, unsigned& out_value ) const;
bool getElement( unsigned index, bool& out_value ) const;
bool getElement( unsigned index, float& out_value ) const;
bool getElement( unsigned index, osg::Matrix& out_value ) const;
bool getElement( unsigned index, osg::Vec3& out_value ) const;
bool isValid() const { return _uniform.valid() && _uniformAlt.valid(); }
int getNumElements() const { return isValid() ? _uniform->getNumElements() : -1; }
bool isDirty() const { return
(_uniform.valid() && _uniform->getModifiedCount() > 0) ||
(_uniformAlt.valid() && _uniformAlt->getModifiedCount() > 0); }
private:
osg::ref_ptr<osg::Uniform> _uniform;
osg::ref_ptr<osg::Uniform> _uniformAlt;
osg::observer_ptr<osg::StateSet> _stateSet;
void ensureCapacity( unsigned newSize );
};
/**
* Cull callback that installs a range (distance to view point) uniform
* in the State based on the bounding center of the node being culled.
* The actual name of the range uniform can is returned by
* ShaderFactory::getRangeUniformName().
*/
class OSGEARTH_EXPORT RangeUniformCullCallback : public osg::NodeCallback
{
public:
RangeUniformCullCallback();
void operator()(osg::Node*, osg::NodeVisitor* nv);
// testing
void setDump(bool v) { _dump = true; }
private:
osg::ref_ptr<osg::StateSet> _stateSet;
osg::ref_ptr<osg::Uniform> _uniform;
bool _dump;
};
/**
* Shader that will discard fragments whose alpha component falls below
* the specified threshold.
*/
class OSGEARTH_EXPORT DiscardAlphaFragments
{
public:
void install(osg::StateSet* ss, float minAlpha) const;
void uninstall(osg::StateSet* ss) const;
};
}
#endif // OSGEARTH_SHADER_UTILS_H
|