source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreShadowVolumeExtrudeProgram.h @ 1092

Revision 1092, 10.0 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

Line 
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
26#ifndef __SHADOWVOLUMEEXTRUDEPROGRAM_H__
27#define __SHADOWVOLUMEEXTRUDEPROGRAM_H__
28
29#include "OgrePrerequisites.h"
30#include "OgreLight.h"
31
32namespace Ogre {
33    /** Static class containing source for vertex programs for extruding shadow volumes
34    @remarks
35        This exists so we don't have to be dependent on an external media files.
36        Assembler is used so we don't have to rely on particular plugins.
37        The assembler contents of this file were generated from the following Cg:
38    @code
39        // Point light shadow volume extrude
40        void shadowVolumeExtrudePointLight_vp (
41            float4 position                     : POSITION,
42            float  wcoord                       : TEXCOORD0,
43
44            out float4 oPosition        : POSITION,
45
46            uniform float4x4 worldViewProjMatrix,
47            uniform float4   lightPos // homogenous, object space
48            )
49        {
50            // extrusion in object space
51            // vertex unmodified if w==1, extruded if w==0
52            float4 newpos =
53                (wcoord.xxxx * lightPos) +
54                float4(position.xyz - lightPos.xyz, 0);
55
56            oPosition = mul(worldViewProjMatrix, newpos);
57
58        }
59
60        // Directional light extrude
61        void shadowVolumeExtrudeDirLight_vp (
62            float4 position                     : POSITION,
63            float  wcoord                       : TEXCOORD0,
64
65            out float4 oPosition        : POSITION,
66
67            uniform float4x4 worldViewProjMatrix,
68            uniform float4   lightPos // homogenous, object space
69            )
70        {
71            // extrusion in object space
72            // vertex unmodified if w==1, extruded if w==0
73            float4 newpos =
74                (wcoord.xxxx * (position + lightPos)) - lightPos;
75
76            oPosition = mul(worldViewProjMatrix, newpos);
77
78        }
79        // Point light shadow volume extrude - FINITE
80        void shadowVolumeExtrudePointLightFinite_vp (
81            float4 position                     : POSITION,
82            float  wcoord                       : TEXCOORD0,
83
84            out float4 oPosition        : POSITION,
85
86            uniform float4x4 worldViewProjMatrix,
87            uniform float4   lightPos, // homogenous, object space
88                        uniform float    extrusionDistance // how far to extrude
89            )
90        {
91            // extrusion in object space
92            // vertex unmodified if w==1, extruded if w==0
93                        float3 extrusionDir = position.xyz - lightPos.xyz;
94                        extrusionDir = normalize(extrusionDir);
95                       
96            float4 newpos = float4(position.xyz + 
97                ((1 - wcoord.x) * extrusionDistance * extrusionDir), 1);
98
99            oPosition = mul(worldViewProjMatrix, newpos);
100
101        }
102
103        // Directional light extrude - FINITE
104        void shadowVolumeExtrudeDirLightFinite_vp (
105            float4 position                     : POSITION,
106            float  wcoord                       : TEXCOORD0,
107
108            out float4 oPosition        : POSITION,
109
110            uniform float4x4 worldViewProjMatrix,
111            uniform float4   lightPos, // homogenous, object space
112                        uniform float    extrusionDistance // how far to extrude
113            )
114        {
115            // extrusion in object space
116            // vertex unmodified if w==1, extruded if w==0
117                        // -ve lightPos is direction
118            float4 newpos = float4(position.xyz -
119                (wcoord.x * extrusionDistance * lightPos.xyz), 1);
120
121            oPosition = mul(worldViewProjMatrix, newpos);
122
123        }               
124    @endcode
125    */
126    class _OgreExport ShadowVolumeExtrudeProgram
127    {
128    private:
129        static String mPointArbvp1;
130        static String mPointVs_1_1;
131        static String mDirArbvp1;
132        static String mDirVs_1_1;
133        // same as above, except the color is set to 1 to enable debug volumes to be seen
134        static String mPointArbvp1Debug;
135        static String mPointVs_1_1Debug;
136        static String mDirArbvp1Debug;
137        static String mDirVs_1_1Debug;
138               
139        static String mPointArbvp1Finite;
140        static String mPointVs_1_1Finite;
141        static String mDirArbvp1Finite;
142        static String mDirVs_1_1Finite;
143        // same as above, except the color is set to 1 to enable debug volumes to be seen
144        static String mPointArbvp1FiniteDebug;
145        static String mPointVs_1_1FiniteDebug;
146        static String mDirArbvp1FiniteDebug;
147        static String mDirVs_1_1FiniteDebug;
148
149                static bool mInitialised;
150
151        public:
152#define OGRE_NUM_SHADOW_EXTRUDER_PROGRAMS 8
153        enum Programs
154        {
155            // Point light extruder, infinite distance
156            POINT_LIGHT = 0,
157            // Point light extruder, infinite distance, debug mode
158            POINT_LIGHT_DEBUG = 1,
159            // Directional light extruder, infinite distance
160            DIRECTIONAL_LIGHT = 2,
161            // Directional light extruder, infinite distance, debug mode
162            DIRECTIONAL_LIGHT_DEBUG = 3,
163            // Point light extruder, finite distance
164            POINT_LIGHT_FINITE = 4,
165            // Point light extruder, finite distance, debug mode
166            POINT_LIGHT_FINITE_DEBUG = 5,
167            // Directional light extruder, finite distance
168            DIRECTIONAL_LIGHT_FINITE = 6,
169            // Directional light extruder, finite distance, debug mode
170            DIRECTIONAL_LIGHT_FINITE_DEBUG = 7
171
172        };
173        static const String programNames[OGRE_NUM_SHADOW_EXTRUDER_PROGRAMS];
174
175        /// Initialise the creation of these vertex programs
176        static void initialise(void);
177        /// Shutdown & destroy the vertex programs
178        static void shutdown(void);
179        /// Get extruder program source for point lights, compatible with arbvp1
180        static const String& getPointLightExtruderArbvp1(void) { return mPointArbvp1; }
181        /// Get extruder program source for point lights, compatible with vs_1_1
182        static const String& getPointLightExtruderVs_1_1(void) { return mPointVs_1_1; }
183        /// Get extruder program source for directional lights, compatible with arbvp1
184        static const String& getDirectionalLightExtruderArbvp1(void) { return mDirArbvp1; }
185        /// Get extruder program source for directional lights, compatible with vs_1_1
186        static const String& getDirectionalLightExtruderVs_1_1(void) { return mDirVs_1_1; }
187
188        /// Get extruder program source for debug point lights, compatible with arbvp1
189        static const String& getPointLightExtruderArbvp1Debug(void) { return mPointArbvp1Debug; }
190        /// Get extruder program source for debug point lights, compatible with vs_1_1
191        static const String& getPointLightExtruderVs_1_1Debug(void) { return mPointVs_1_1Debug; }
192        /// Get extruder program source for debug directional lights, compatible with arbvp1
193        static const String& getDirectionalLightExtruderArbvp1Debug(void) { return mDirArbvp1Debug; }
194        /// Get extruder program source for debug directional lights, compatible with vs_1_1
195        static const String& getDirectionalLightExtruderVs_1_1Debug(void) { return mDirVs_1_1Debug; }
196        /// General purpose method to get any of the program sources
197        static const String& getProgramSource(Light::LightTypes lightType, const String syntax,
198            bool finite, bool debug);
199
200        static const String& getProgramName(Light::LightTypes lightType, bool finite, bool debug);
201
202
203
204
205
206        /// Get FINITE extruder program source for point lights, compatible with arbvp1
207        static const String& getPointLightExtruderArbvp1Finite(void) { return mPointArbvp1Finite; }
208        /// Get FINITE extruder program source for point lights, compatible with vs_1_1
209        static const String& getPointLightExtruderVs_1_1Finite(void) { return mPointVs_1_1Finite; }
210        /// Get FINITE extruder program source for directional lights, compatible with arbvp1
211        static const String& getDirectionalLightExtruderArbvp1Finite(void) { return mDirArbvp1Finite; }
212        /// Get FINITE extruder program source for directional lights, compatible with vs_1_1
213        static const String& getDirectionalLightExtruderVs_1_1Finite(void) { return mDirVs_1_1Finite; }
214
215        /// Get FINITE extruder program source for debug point lights, compatible with arbvp1
216        static const String& getPointLightExtruderArbvp1FiniteDebug(void) { return mPointArbvp1FiniteDebug; }
217        /// Get extruder program source for debug point lights, compatible with vs_1_1
218        static const String& getPointLightExtruderVs_1_1FiniteDebug(void) { return mPointVs_1_1FiniteDebug; }
219        /// Get FINITE extruder program source for debug directional lights, compatible with arbvp1
220        static const String& getDirectionalLightExtruderArbvp1FiniteDebug(void) { return mDirArbvp1FiniteDebug; }
221        /// Get FINITE extruder program source for debug directional lights, compatible with vs_1_1
222        static const String& getDirectionalLightExtruderVs_1_1FiniteDebug(void) { return mDirVs_1_1FiniteDebug; }
223
224
225
226               
227    };
228}
229#endif
Note: See TracBrowser for help on using the repository browser.