source: OGRE/trunk/ogrenew/Samples/DeferredShading/include/DeferredShading.h @ 692

Revision 692, 4.3 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]1/**
2Implementation of a Deferred Shading engine in OGRE, using Multiple Render Targets and
3HLSL/GLSL high level language shaders.
4        // W.J. :wumpus: van der Laan 2005 //
5
6Deferred shading renders the scene to a 'fat' texture format, using a shader that outputs colour,
7normal, depth, and possible other attributes per fragment. Multi Render Target is required as we
8are dealing with many outputs which get written into multiple render textures in the same pass.
9
10After rendering the scene in this format, the shading (lighting) can be done as a post process.
11This means that lighting is done in screen space. Adding them requires nothing more than rendering
12a screenful quad; thus the method allows for an enormous amount of lights without noticable
13performance loss.
14
15Little lights affecting small area ("Minilights") can be even further optimised by rendering
16their convex bounding geometry. This is also shown in this demo by 6 swarming lights.
17
18The paper for GDC2004 on Deferred Shading can be found here:
19  http://www.talula.demon.co.uk/DeferredShading.pdf
20*******************************************************************************
21Copyright (c) W.J. van der Laan
22
23Permission is hereby granted, free of charge, to any person obtaining a copy of
24this software  and associated documentation files (the "Software"), to deal in
25the Software without restriction, including without limitation the rights to use,
26copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
27Software, and to permit persons to whom the Software is furnished to do so, subject
28to the following conditions:
29
30The above copyright notice and this permission notice shall be included in all copies
31or substantial portions of the Software.
32
33THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
34INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
36HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE
38SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39*******************************************************************************
40*/
41#ifndef H_WJ_DeferredShadingSystem
42#define H_WJ_DeferredShadingSystem
43
44#include "OgreCompositorInstance.h"
45#include "OgreSceneManager.h"
46#include "OgreSceneNode.h"
47#include "OgreMaterial.h"
48class MLight;
49class MaterialGenerator;
50
51/** System to manage Deferred Shading for a camera/render target.
52 */
53class DeferredShadingSystem: public Ogre::CompositorInstance::Listener
54{
55public:
56        DeferredShadingSystem(Ogre::Viewport *vp, Ogre::SceneManager *sm, Ogre::Camera *cam);
57        ~DeferredShadingSystem();
58
59        enum DSMode
60        {
61                DSM_SINGLEPASS = 0,  // Single pass + two lights
62                DSM_MULTIPASS = 1,   // Multi pass
63                DSM_SHOWCOLOUR = 2,  // Show diffuse (for debugging)
64                DSM_SHOWNORMALS = 3, // Show normals (for debugging)
65                DSM_SHOWDSP = 4,         // Show depth and specular channel (for debugging)
66                DSM_COUNT = 5
67        };
68
69        /** Set rendering mode (one of DSMode)
70         */
71        void setMode(DSMode mode);
72
73        /** Activate or deactivate system
74         */
75        void setActive(bool active);
76
77        /** Create a new MiniLight
78         */
79        MLight *createMLight();
80
81        /** Destroy a MiniLight
82         */
83        void destroyMLight(MLight *m);
84
85        /** Update fat (origin) render target
86        */
87        void update();
88
89        /// Visibility mask for scene
90        static const Ogre::uint32 SceneVisibilityMask = 0x00000001;
91        /// Visibility mask for post-processing geometry (lights, unlit particles)
92        static const Ogre::uint32 PostVisibilityMask = 0x00000002;
93
94        /** @copydoc CompositorInstance::Listener::notifyMaterialSetup
95         */
96        virtual void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat);
97protected:
98        Ogre::Viewport *mViewport;
99        Ogre::SceneManager *mSceneMgr;
100        Ogre::Camera *mCamera;
101       
102        // Fat render target
103        Ogre::MultiRenderTarget *rttTex;
104        // Filters
105        Ogre::CompositorInstance *mInstance[DSM_COUNT];
106        // Active/inactive
107        bool mActive;
108        DSMode mCurrentMode;
109
110        std::set<MLight*> mLights;
111        Ogre::TexturePtr mTexture0, mTexture1;
112
113        MaterialGenerator *mLightMaterialGenerator;
114
115    void createResources();
116        void initialiseLightGeometry();
117        void setupMaterial(const Ogre::MaterialPtr &mat);
118};
119
120#endif
Note: See TracBrowser for help on using the repository browser.