/* osgEarth
* Copyright 2008-2012 Pelican Mapping
* MIT License
*/
#pragma once

#include <osgEarth/TerrainEffect>
#include <osgEarth/ImageLayer>
#include <osg/Image>
#include <osg/Uniform>
#include <osg/Texture2D>

using namespace osgEarth;

namespace osgEarth
{
    /**
     * Effect that applies bump mapping to the terrain.
     */
    class BumpMapTerrainEffect : public TerrainEffect
    {
    public:
        /** construct a new terrain effect. */
        BumpMapTerrainEffect();

        void setActive(bool);

        /** Sets the image containing the normal offsets. */
        void setBumpMapImage(osg::Image* image);

        /** Sets the LOD at which the bumpmap renders with native scale */
        void setBaseLOD(unsigned value) { _baseLOD = value; }

        /** Sets the number of progressive octaves. */
        void setOctaves(int value) { _octaves = value; }

        /** Sets the range of the first octave. */
        void setMaxRange(float value) { _maxRange = value; }

        /** UNiform that controls intensity */
        osg::Uniform* getIntensityUniform() const { return _intensityUniform.get(); }

        /** Uniform that controls scale factor */
        osg::Uniform* getScaleUniform() const { return _scaleUniform.get(); }


    public: // TerrainEffect interface

        void onInstall(TerrainEngineNode* engine) override;

        void onUninstall(TerrainEngineNode* engine) override;


    protected:
        virtual ~BumpMapTerrainEffect();

        bool _ok = true;
        int _bumpMapUnit = -1;
        int _octaves = 1;
        float _maxRange = 25000.0f;
        unsigned _baseLOD = 13u;
        osg::ref_ptr<osg::Texture2D> _bumpMapTex;
        osg::ref_ptr<osg::Uniform> _bumpMapTexUniform;
        osg::ref_ptr<osg::Uniform> _scaleUniform;
        osg::ref_ptr<osg::Uniform> _intensityUniform;
        osg::ref_ptr<osg::Uniform> _octavesUniform;
    };
}