1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef __SHADOWVOLUMEEXTRUDEPROGRAM_H__ |
---|
31 | #define __SHADOWVOLUMEEXTRUDEPROGRAM_H__ |
---|
32 | |
---|
33 | #include "OgrePrerequisites.h" |
---|
34 | #include "OgreLight.h" |
---|
35 | |
---|
36 | namespace Ogre { |
---|
37 | /** Static class containing source for vertex programs for extruding shadow volumes |
---|
38 | @remarks |
---|
39 | This exists so we don't have to be dependent on an external media files. |
---|
40 | Assembler is used so we don't have to rely on particular plugins. |
---|
41 | The assembler contents of this file were generated from the following Cg: |
---|
42 | @code |
---|
43 | // Point light shadow volume extrude |
---|
44 | void shadowVolumeExtrudePointLight_vp ( |
---|
45 | float4 position : POSITION, |
---|
46 | float wcoord : TEXCOORD0, |
---|
47 | |
---|
48 | out float4 oPosition : POSITION, |
---|
49 | |
---|
50 | uniform float4x4 worldViewProjMatrix, |
---|
51 | uniform float4 lightPos // homogenous, object space |
---|
52 | ) |
---|
53 | { |
---|
54 | // extrusion in object space |
---|
55 | // vertex unmodified if w==1, extruded if w==0 |
---|
56 | float4 newpos = |
---|
57 | (wcoord.xxxx * lightPos) + |
---|
58 | float4(position.xyz - lightPos.xyz, 0); |
---|
59 | |
---|
60 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | // Directional light extrude |
---|
65 | void shadowVolumeExtrudeDirLight_vp ( |
---|
66 | float4 position : POSITION, |
---|
67 | float wcoord : TEXCOORD0, |
---|
68 | |
---|
69 | out float4 oPosition : POSITION, |
---|
70 | |
---|
71 | uniform float4x4 worldViewProjMatrix, |
---|
72 | uniform float4 lightPos // homogenous, object space |
---|
73 | ) |
---|
74 | { |
---|
75 | // extrusion in object space |
---|
76 | // vertex unmodified if w==1, extruded if w==0 |
---|
77 | float4 newpos = |
---|
78 | (wcoord.xxxx * (position + lightPos)) - lightPos; |
---|
79 | |
---|
80 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
81 | |
---|
82 | } |
---|
83 | // Point light shadow volume extrude - FINITE |
---|
84 | void shadowVolumeExtrudePointLightFinite_vp ( |
---|
85 | float4 position : POSITION, |
---|
86 | float wcoord : TEXCOORD0, |
---|
87 | |
---|
88 | out float4 oPosition : POSITION, |
---|
89 | |
---|
90 | uniform float4x4 worldViewProjMatrix, |
---|
91 | uniform float4 lightPos, // homogenous, object space |
---|
92 | uniform float extrusionDistance // how far to extrude |
---|
93 | ) |
---|
94 | { |
---|
95 | // extrusion in object space |
---|
96 | // vertex unmodified if w==1, extruded if w==0 |
---|
97 | float3 extrusionDir = position.xyz - lightPos.xyz; |
---|
98 | extrusionDir = normalize(extrusionDir); |
---|
99 | |
---|
100 | float4 newpos = float4(position.xyz + |
---|
101 | ((1 - wcoord.x) * extrusionDistance * extrusionDir), 1); |
---|
102 | |
---|
103 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | // Directional light extrude - FINITE |
---|
108 | void shadowVolumeExtrudeDirLightFinite_vp ( |
---|
109 | float4 position : POSITION, |
---|
110 | float wcoord : TEXCOORD0, |
---|
111 | |
---|
112 | out float4 oPosition : POSITION, |
---|
113 | |
---|
114 | uniform float4x4 worldViewProjMatrix, |
---|
115 | uniform float4 lightPos, // homogenous, object space |
---|
116 | uniform float extrusionDistance // how far to extrude |
---|
117 | ) |
---|
118 | { |
---|
119 | // extrusion in object space |
---|
120 | // vertex unmodified if w==1, extruded if w==0 |
---|
121 | // -ve lightPos is direction |
---|
122 | float4 newpos = float4(position.xyz - |
---|
123 | (wcoord.x * extrusionDistance * lightPos.xyz), 1); |
---|
124 | |
---|
125 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
126 | |
---|
127 | } |
---|
128 | @endcode |
---|
129 | */ |
---|
130 | class _OgreExport ShadowVolumeExtrudeProgram |
---|
131 | { |
---|
132 | private: |
---|
133 | static String mPointArbvp1; |
---|
134 | static String mPointVs_1_1; |
---|
135 | static String mDirArbvp1; |
---|
136 | static String mDirVs_1_1; |
---|
137 | // same as above, except the color is set to 1 to enable debug volumes to be seen |
---|
138 | static String mPointArbvp1Debug; |
---|
139 | static String mPointVs_1_1Debug; |
---|
140 | static String mDirArbvp1Debug; |
---|
141 | static String mDirVs_1_1Debug; |
---|
142 | |
---|
143 | static String mPointArbvp1Finite; |
---|
144 | static String mPointVs_1_1Finite; |
---|
145 | static String mDirArbvp1Finite; |
---|
146 | static String mDirVs_1_1Finite; |
---|
147 | // same as above, except the color is set to 1 to enable debug volumes to be seen |
---|
148 | static String mPointArbvp1FiniteDebug; |
---|
149 | static String mPointVs_1_1FiniteDebug; |
---|
150 | static String mDirArbvp1FiniteDebug; |
---|
151 | static String mDirVs_1_1FiniteDebug; |
---|
152 | |
---|
153 | static bool mInitialised; |
---|
154 | |
---|
155 | public: |
---|
156 | #define OGRE_NUM_SHADOW_EXTRUDER_PROGRAMS 8 |
---|
157 | enum Programs |
---|
158 | { |
---|
159 | // Point light extruder, infinite distance |
---|
160 | POINT_LIGHT = 0, |
---|
161 | // Point light extruder, infinite distance, debug mode |
---|
162 | POINT_LIGHT_DEBUG = 1, |
---|
163 | // Directional light extruder, infinite distance |
---|
164 | DIRECTIONAL_LIGHT = 2, |
---|
165 | // Directional light extruder, infinite distance, debug mode |
---|
166 | DIRECTIONAL_LIGHT_DEBUG = 3, |
---|
167 | // Point light extruder, finite distance |
---|
168 | POINT_LIGHT_FINITE = 4, |
---|
169 | // Point light extruder, finite distance, debug mode |
---|
170 | POINT_LIGHT_FINITE_DEBUG = 5, |
---|
171 | // Directional light extruder, finite distance |
---|
172 | DIRECTIONAL_LIGHT_FINITE = 6, |
---|
173 | // Directional light extruder, finite distance, debug mode |
---|
174 | DIRECTIONAL_LIGHT_FINITE_DEBUG = 7 |
---|
175 | |
---|
176 | }; |
---|
177 | static const String programNames[OGRE_NUM_SHADOW_EXTRUDER_PROGRAMS]; |
---|
178 | |
---|
179 | /// Initialise the creation of these vertex programs |
---|
180 | static void initialise(void); |
---|
181 | /// Shutdown & destroy the vertex programs |
---|
182 | static void shutdown(void); |
---|
183 | /// Get extruder program source for point lights, compatible with arbvp1 |
---|
184 | static const String& getPointLightExtruderArbvp1(void) { return mPointArbvp1; } |
---|
185 | /// Get extruder program source for point lights, compatible with vs_1_1 |
---|
186 | static const String& getPointLightExtruderVs_1_1(void) { return mPointVs_1_1; } |
---|
187 | /// Get extruder program source for directional lights, compatible with arbvp1 |
---|
188 | static const String& getDirectionalLightExtruderArbvp1(void) { return mDirArbvp1; } |
---|
189 | /// Get extruder program source for directional lights, compatible with vs_1_1 |
---|
190 | static const String& getDirectionalLightExtruderVs_1_1(void) { return mDirVs_1_1; } |
---|
191 | |
---|
192 | /// Get extruder program source for debug point lights, compatible with arbvp1 |
---|
193 | static const String& getPointLightExtruderArbvp1Debug(void) { return mPointArbvp1Debug; } |
---|
194 | /// Get extruder program source for debug point lights, compatible with vs_1_1 |
---|
195 | static const String& getPointLightExtruderVs_1_1Debug(void) { return mPointVs_1_1Debug; } |
---|
196 | /// Get extruder program source for debug directional lights, compatible with arbvp1 |
---|
197 | static const String& getDirectionalLightExtruderArbvp1Debug(void) { return mDirArbvp1Debug; } |
---|
198 | /// Get extruder program source for debug directional lights, compatible with vs_1_1 |
---|
199 | static const String& getDirectionalLightExtruderVs_1_1Debug(void) { return mDirVs_1_1Debug; } |
---|
200 | /// General purpose method to get any of the program sources |
---|
201 | static const String& getProgramSource(Light::LightTypes lightType, const String syntax, |
---|
202 | bool finite, bool debug); |
---|
203 | |
---|
204 | static const String& getProgramName(Light::LightTypes lightType, bool finite, bool debug); |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | /// Get FINITE extruder program source for point lights, compatible with arbvp1 |
---|
211 | static const String& getPointLightExtruderArbvp1Finite(void) { return mPointArbvp1Finite; } |
---|
212 | /// Get FINITE extruder program source for point lights, compatible with vs_1_1 |
---|
213 | static const String& getPointLightExtruderVs_1_1Finite(void) { return mPointVs_1_1Finite; } |
---|
214 | /// Get FINITE extruder program source for directional lights, compatible with arbvp1 |
---|
215 | static const String& getDirectionalLightExtruderArbvp1Finite(void) { return mDirArbvp1Finite; } |
---|
216 | /// Get FINITE extruder program source for directional lights, compatible with vs_1_1 |
---|
217 | static const String& getDirectionalLightExtruderVs_1_1Finite(void) { return mDirVs_1_1Finite; } |
---|
218 | |
---|
219 | /// Get FINITE extruder program source for debug point lights, compatible with arbvp1 |
---|
220 | static const String& getPointLightExtruderArbvp1FiniteDebug(void) { return mPointArbvp1FiniteDebug; } |
---|
221 | /// Get extruder program source for debug point lights, compatible with vs_1_1 |
---|
222 | static const String& getPointLightExtruderVs_1_1FiniteDebug(void) { return mPointVs_1_1FiniteDebug; } |
---|
223 | /// Get FINITE extruder program source for debug directional lights, compatible with arbvp1 |
---|
224 | static const String& getDirectionalLightExtruderArbvp1FiniteDebug(void) { return mDirArbvp1FiniteDebug; } |
---|
225 | /// Get FINITE extruder program source for debug directional lights, compatible with vs_1_1 |
---|
226 | static const String& getDirectionalLightExtruderVs_1_1FiniteDebug(void) { return mDirVs_1_1FiniteDebug; } |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | |
---|
231 | }; |
---|
232 | } |
---|
233 | #endif |
---|