00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CAELUM__DEPTH_COMPOSER_H
00022 #define CAELUM__DEPTH_COMPOSER_H
00023
00024 #include "CaelumPrerequisites.h"
00025 #include "FastGpuParamRef.h"
00026
00027 namespace Caelum
00028 {
00035 class CAELUM_EXPORT DepthComposer
00036 {
00037 private:
00038 Ogre::SceneManager *mSceneMgr;
00039
00040 void onCompositorMaterialChanged ();
00041 const String& getCompositorName ();
00042
00043 protected:
00044 inline Ogre::SceneManager* getSceneManager() const { return mSceneMgr; }
00045
00046 friend class DepthComposerInstance;
00047
00048 public:
00049 DepthComposer(Ogre::SceneManager *sceneMgr);
00050 virtual ~DepthComposer();
00051
00052 void update ();
00053
00054 public:
00055 typedef std::map<Ogre::Viewport*, DepthComposerInstance*> ViewportInstanceMap;
00056 ViewportInstanceMap mViewportInstanceMap;
00057
00058 public:
00059 DepthComposerInstance* createViewportInstance(Ogre::Viewport* viewport);
00060 void destroyViewportInstance(Ogre::Viewport* viewport);
00061 DepthComposerInstance* getViewportInstance(Ogre::Viewport* viewport);
00062 void destroyAllViewportInstances();
00063
00064 private:
00065 bool mDebugDepthRender;
00066
00067 public:
00069 void setDebugDepthRender (bool value);
00070 bool getDebugDepthRender () const { return mDebugDepthRender; }
00071
00072 private:
00073 bool mSkyDomeHazeEnabled;
00074 Ogre::Vector3 mSunDirection;
00075 Ogre::ColourValue mHazeColour;
00076
00077 public:
00079 void setSkyDomeHazeEnabled (bool value);
00080 bool getSkyDomeHazeEnabled () const { return mSkyDomeHazeEnabled; }
00081
00082 void setSunDirection (const Ogre::Vector3& value) { mSunDirection = value; }
00083 const Ogre::Vector3 getSunDirection () const { return mSunDirection; }
00084
00085 void setHazeColour (const Ogre::ColourValue& value) { mHazeColour = value; }
00086 const Ogre::ColourValue getHazeColour () const { return mHazeColour; }
00087
00088 private:
00089 bool mGroundFogEnabled;
00090 Real mGroundFogDensity;
00091 Real mGroundFogBaseLevel;
00092 Real mGroundFogVerticalDecay;
00093 Ogre::ColourValue mGroundFogColour;
00094
00095 public:
00097 void setGroundFogEnabled (bool value);
00098 bool getGroundFogEnabled () const { return mGroundFogEnabled; }
00099
00101 void setGroundFogDensity (Real value) { mGroundFogDensity = value; }
00102
00104 Real getGroundFogDensity () const { return mGroundFogDensity; }
00105
00108 void setGroundFogBaseLevel (Real value) { mGroundFogBaseLevel = value; }
00109
00111 Real getGroundFogBaseLevel () const { return mGroundFogBaseLevel; }
00112
00114 void setGroundFogVerticalDecay (Real value) { mGroundFogVerticalDecay = value; }
00115
00117 Real getGroundFogVerticalDecay () const { return mGroundFogVerticalDecay; }
00118
00120 void setGroundFogColour (const Ogre::ColourValue& value) { mGroundFogColour = value; }
00121
00123 const Ogre::ColourValue getGroundFogColour () const { return mGroundFogColour; }
00124 };
00125
00129 class CAELUM_EXPORT DepthComposerInstance: private Ogre::CompositorInstance::Listener
00130 {
00131 private:
00132 DepthComposer* mParent;
00133 Ogre::Viewport* mViewport;
00134 Ogre::CompositorInstance* mCompInst;
00135 std::auto_ptr<DepthRenderer> mDepthRenderer;
00136
00137 virtual void notifyMaterialSetup(uint pass_id, Ogre::MaterialPtr &mat);
00138 virtual void notifyMaterialRender(uint pass_id, Ogre::MaterialPtr &mat);
00139
00140 struct Params {
00141 void setup(Ogre::GpuProgramParametersSharedPtr params);
00142
00143 Ogre::GpuProgramParametersSharedPtr fpParams;
00144 FastGpuParamRef invViewProjMatrix;
00145 FastGpuParamRef worldCameraPos;
00146 FastGpuParamRef groundFogDensity;
00147 FastGpuParamRef groundFogVerticalDecay;
00148 FastGpuParamRef groundFogBaseLevel;
00149 FastGpuParamRef groundFogColour;
00150 FastGpuParamRef sunDirection;
00151 FastGpuParamRef hazeColour;
00152 } mParams;
00153
00154 protected:
00156 void _update ();
00157
00158 void addCompositor ();
00159 void removeCompositor ();
00160 bool isCompositorEnabled () { return mCompInst != 0; }
00161
00162 friend class DepthComposer;
00163
00164 public:
00166 DepthComposer* getParent() const { return mParent; }
00167
00169 Ogre::Viewport* getViewport() const { return mViewport; }
00170
00172 Ogre::CompositorInstance* getCompositorInstance() const { return mCompInst; }
00173
00177 Caelum::DepthRenderer* getDepthRenderer () const { return mDepthRenderer.get(); }
00178
00179 DepthComposerInstance(DepthComposer* parent, Ogre::Viewport* view);
00180 virtual ~DepthComposerInstance();
00181 };
00182
00188 class CAELUM_EXPORT DepthRenderer: private Ogre::RenderQueue::RenderableListener
00189 {
00190 private:
00191 Ogre::Viewport* mMasterViewport;
00192 Ogre::Viewport* mDepthRenderViewport;
00193 Ogre::TexturePtr mDepthRenderTexture;
00194 bool mDepthRenderingNow;
00195 Ogre::MaterialPtr mDepthRenderMaterial;
00196
00197
00198 #if OGRE_VERSION < 0x00010600
00199 virtual bool renderableQueued(
00200 Ogre::Renderable* rend,
00201 Ogre::uint8 groupId,
00202 Ogre::ushort priority,
00203 Ogre::Technique** ppTech);
00204 #else
00205 virtual bool renderableQueued(
00206 Ogre::Renderable* rend,
00207 Ogre::uint8 groupId,
00208 Ogre::ushort priority,
00209 Ogre::Technique** ppTech,
00210 Ogre::RenderQueue* pQueue);
00211 #endif // OGRE_VERSION
00212 inline Ogre::Material* getDepthRenderMaterial() const { return mDepthRenderMaterial.get(); }
00213
00214 int mMinRenderGroupId;
00215 int mMaxRenderGroupId;
00216 int mViewportVisibilityMask;
00217
00218 public:
00219 DepthRenderer (Ogre::Viewport* viewport);
00220 ~DepthRenderer ();
00221
00222 inline Ogre::Viewport* getMasterViewport() { return mMasterViewport; }
00223 inline Ogre::Texture* getDepthRenderTexture () { return mDepthRenderTexture.get(); }
00224 inline Ogre::Viewport* getDepthRenderViewport () { return mDepthRenderViewport; }
00225 inline Ogre::RenderTexture* getDepthRenderTarget () {
00226 return mDepthRenderTexture->getBuffer()->getRenderTarget ();
00227 }
00228
00230 void update ();
00231
00237 void setRenderGroupRangeFilter (int minGroup, int maxGroup);
00238
00240 int getRenderGroupRangeFilterMin () { return mMinRenderGroupId; }
00241 int getRenderGroupRangeFilterMax () { return mMaxRenderGroupId; }
00242
00245 void disableRenderGroupRangeFilter ();
00246
00250 void setViewportVisibilityMask (uint value) { mViewportVisibilityMask = value; }
00251 uint getViewportVisibilityMask () { return mViewportVisibilityMask; }
00252 void disableViewportVisibilityMask () { mViewportVisibilityMask = ~0; }
00253
00254 public:
00263 inline void setUseCustomDepthScheme (bool value) { mUseCustomDepthScheme = value; }
00264 inline bool getUseCustomDepthScheme () { return mUseCustomDepthScheme; }
00265
00268 inline void setCustomDepthSchemeName (const Ogre::String& value) { mCustomDepthSchemeName = value; }
00269 inline const Ogre::String& getCustomDepthSchemeName () { return mCustomDepthSchemeName; }
00270
00272 static const String DEFAULT_CUSTOM_DEPTH_SCHEME_NAME;
00273
00274 private:
00275 bool mUseCustomDepthScheme;
00276 Ogre::String mCustomDepthSchemeName;
00277 };
00278 }
00279
00280 #endif // CAELUM__DEPTH_COMPOSER_H