source: OGRE/trunk/ogrenew/OgreMain/include/OgreShadowCaster.h @ 692

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

adding ogre 1.2 and dependencies

RevLine 
[692]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __ShadowCaster_H__
26#define __ShadowCaster_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreRenderable.h"
30
31
32namespace Ogre {
33
34
35    /** Class which represents the renderable aspects of a set of shadow volume faces.
36    @remarks
37        Note that for casters comprised of more than one set of vertex buffers (e.g. SubMeshes each
38        using their own geometry), it will take more than one ShadowRenderable to render the
39        shadow volume. Therefore for shadow caster geometry, it is best to stick to one set of
40        vertex buffers (not necessarily one buffer, but the positions for the entire geometry
41        should come from one buffer if possible)
42    */
43    class _OgreExport ShadowRenderable : public Renderable
44    {
45    protected:
46        MaterialPtr mMaterial;
47        RenderOperation mRenderOp;
48        ShadowRenderable* mLightCap; // used only if isLightCapSeparate == true
49    public:
50        ShadowRenderable() : mMaterial(0), mLightCap(0) {}
51        virtual ~ShadowRenderable() { delete mLightCap; }
52        /** Set the material to be used by the shadow, should be set by the caller
53          before adding to a render queue
54        */
55        void setMaterial(MaterialPtr& mat) { mMaterial = mat; }
56        /// Overridden from Renderable
57        const MaterialPtr& getMaterial(void) const { return mMaterial; }
58        /// Overridden from Renderable
59        void getRenderOperation(RenderOperation& op) { op = mRenderOp; }
60        /// Get the internal render operation for set up
61        RenderOperation* getRenderOperationForUpdate(void) {return &mRenderOp;}
62        /// Overridden from Renderable
63        void getWorldTransforms(Matrix4* xform) const = 0;
64        /// Overridden from Renderable
65        const Quaternion& getWorldOrientation(void) const = 0;
66        /// Overridden from Renderable
67        const Vector3& getWorldPosition(void) const = 0;
68        /// Overridden from Renderable
69        Real getSquaredViewDepth(const Camera* cam) const{ return 0; /* not used */}
70        /// Overridden from Renderable
71        const LightList& getLights(void) const;
72        /** Does this renderable require a separate light cap?
73        @remarks
74            If possible, the light cap (when required) should be contained in the
75            usual geometry of the shadow renderable. However, if for some reason
76            the normal depth function (less than) could cause artefacts, then a
77            separate light cap with a depth function of 'always fail' can be used
78            instead. The primary example of this is when there are floating point
79            inaccuracies caused by calculating the shadow geometry separately from
80            the real geometry.
81        */
82        bool isLightCapSeparate(void) const { return mLightCap != 0; }
83
84        /// Get the light cap version of this renderable
85        ShadowRenderable* getLightCapRenderable(void) { return mLightCap; }
86        /// Should this ShadowRenderable be treated as visible?
87        virtual bool isVisible(void) const { return true; }
88
89    };
90
91    /** A set of flags that can be used to influence ShadowRenderable creation. */
92    enum ShadowRenderableFlags
93    {
94        /// For shadow volume techniques only, generate a light cap on the volume
95        SRF_INCLUDE_LIGHT_CAP = 0x00000001,
96        /// For shadow volume techniques only, generate a dark cap on the volume
97        SRF_INCLUDE_DARK_CAP  = 0x00000002,
98        /// For shadow volume techniques only, indicates volume is extruded to infinity
99        SRF_EXTRUDE_TO_INFINITY  = 0x00000004
100    };
101
102    /** This class defines the interface that must be implemented by shadow casters.
103    */
104    class _OgreExport ShadowCaster
105    {
106    public:
107        virtual ~ShadowCaster() { }
108        /** Returns whether or not this object currently casts a shadow. */
109        virtual bool getCastShadows(void) const = 0;
110
111        /** Returns details of the edges which might be used to determine a silhouette. */
112        virtual EdgeData* getEdgeList(void) = 0;
113
114        /** Get the world bounding box of the caster. */
115        virtual const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const = 0;
116        /** Gets the world space bounding box of the light cap */
117        virtual const AxisAlignedBox& getLightCapBounds(void) const = 0;
118        /** Gets the world space bounding box of the dark cap, as extruded using the light provided */
119        virtual const AxisAlignedBox& getDarkCapBounds(const Light& light, Real dirLightExtrusionDist) const = 0;
120
121        typedef std::vector<ShadowRenderable*> ShadowRenderableList;
122        typedef VectorIterator<ShadowRenderableList> ShadowRenderableListIterator;
123
124        /** Gets an iterator over the renderables required to render the shadow volume.
125        @remarks
126            Shadowable geometry should ideally be designed such that there is only one
127            ShadowRenderable required to render the the shadow; however this is not a necessary
128            limitation and it can be exceeded if required.
129        @param shadowTechnique The technique being used to generate the shadow
130        @param light The light to generate the shadow from
131        @param indexBuffer The index buffer to build the renderables into,
132            the current contents are assumed to be disposable.
133        @param extrudeVertices If true, this means this class should extrude
134            the vertices of the back of the volume in software. If false, it
135            will not be done (a vertex program is assumed).
136        @param extrusionDistance The distance to extrude the shadow volume
137        @param flags Technique-specific flags, see ShadowRenderableFlags
138        */
139        virtual ShadowRenderableListIterator getShadowVolumeRenderableIterator(
140            ShadowTechnique shadowTechnique, const Light* light,
141            HardwareIndexBufferSharedPtr* indexBuffer,
142            bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 ) = 0;
143
144        /** Utility method for extruding vertices based on a light.
145        @remarks
146            Unfortunately, because D3D cannot handle homogenous (4D) position
147            coordinates in the fixed-function pipeline (GL can, but we have to
148            be cross-API), when we extrude in software we cannot extrude to
149            infinity the way we do in the vertex program (by setting w to
150            0.0f). Therefore we extrude by a fixed distance, which may cause
151            some problems with larger scenes. Luckily better hardware (ie
152            vertex programs) can fix this.
153        @param vertexBuffer The vertex buffer containing ONLY xyz position
154        values, which must be originalVertexCount * 2 * 3 floats long.
155        @param originalVertexCount The count of the original number of
156        vertices, ie the number in the mesh, not counting the doubling
157        which has already been done (by VertexData::prepareForShadowVolume)
158        to provide the extruded area of the buffer.
159        @param lightPos 4D light position in object space, when w=0.0f this
160        represents a directional light
161        @param extrudeDist The distance to extrude
162        */
163        static void extrudeVertices(HardwareVertexBufferSharedPtr vertexBuffer,
164            size_t originalVertexCount, const Vector4& lightPos, Real extrudeDist);
165        /** Get the distance to extrude for a point/spot light */
166        virtual Real getPointExtrusionDistance(const Light* l) const = 0;
167    protected:
168        /// Helper moethod for calculating extrusion distance
169        Real getExtrusionDistance(const Vector3& objectPos, const Light* light) const;
170        /** Tells the caster to perform the tasks necessary to update the
171            edge data's light listing. Can be overridden if the subclass needs
172            to do additional things.
173        @param edgeData The edge information to update
174        @param lightPos 4D vector representing the light, a directional light
175            has w=0.0
176       */
177        virtual void updateEdgeListLightFacing(EdgeData* edgeData,
178            const Vector4& lightPos);
179
180        /** Generates the indexes required to render a shadow volume into the
181            index buffer which is passed in, and updates shadow renderables
182            to use it.
183        @param edgeData The edge information to use
184        @param indexBuffer The buffer into which to write data into; current
185            contents are assumed to be discardable.
186        @param light The light, mainly for type info as silhouette calculations
187            should already have been done in updateEdgeListLightFacing
188        @param shadowRenderables A list of shadow renderables which has
189            already been constructed but will need populating with details of
190            the index ranges to be used.
191        @param flags Additional controller flags, see ShadowRenderableFlags
192        */
193        virtual void generateShadowVolume(EdgeData* edgeData,
194            HardwareIndexBufferSharedPtr indexBuffer, const Light* light,
195            ShadowRenderableList& shadowRenderables, unsigned long flags);
196        /** Utility method for extruding a bounding box.
197        @param box Original bounding box, will be updated in-place
198        @param lightPos 4D light position in object space, when w=0.0f this
199        represents a directional light
200        @param extrudeDist The distance to extrude
201        */
202        virtual void extrudeBounds(AxisAlignedBox& box, const Vector4& lightPos,
203            Real extrudeDist) const;
204
205
206    };
207}
208
209#endif
Note: See TracBrowser for help on using the repository browser.