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-2013 Torus Knot Software Ltd |
---|
8 | |
---|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
10 | of this software and associated documentation files (the "Software"), to deal |
---|
11 | in the Software without restriction, including without limitation the rights |
---|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
13 | copies of the Software, and to permit persons to whom the Software is |
---|
14 | furnished to do so, subject to the following conditions: |
---|
15 | |
---|
16 | The above copyright notice and this permission notice shall be included in |
---|
17 | all copies or substantial portions of the Software. |
---|
18 | |
---|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
25 | THE SOFTWARE. |
---|
26 | ----------------------------------------------------------------------------- |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef __SHADOWVOLUMEEXTRUDEPROGRAM_H__ |
---|
30 | #define __SHADOWVOLUMEEXTRUDEPROGRAM_H__ |
---|
31 | |
---|
32 | #include "OgrePrerequisites.h" |
---|
33 | #include "OgreLight.h" |
---|
34 | #include "OgreHeaderPrefix.h" |
---|
35 | |
---|
36 | namespace Ogre { |
---|
37 | /** \addtogroup Core |
---|
38 | * @{ |
---|
39 | */ |
---|
40 | /** \addtogroup Scene |
---|
41 | * @{ |
---|
42 | */ |
---|
43 | /** Static class containing source for vertex programs for extruding shadow volumes |
---|
44 | @remarks |
---|
45 | This exists so we don't have to be dependent on an external media files. |
---|
46 | Assembler is used so we don't have to rely on particular plugins. |
---|
47 | The assembler contents of this file were generated from the following Cg: |
---|
48 | @code |
---|
49 | // Point light shadow volume extrude |
---|
50 | void shadowVolumeExtrudePointLight_vp ( |
---|
51 | float4 position : POSITION, |
---|
52 | float wcoord : TEXCOORD0, |
---|
53 | |
---|
54 | out float4 oPosition : POSITION, |
---|
55 | |
---|
56 | uniform float4x4 worldViewProjMatrix, |
---|
57 | uniform float4 lightPos // homogeneous, object space |
---|
58 | ) |
---|
59 | { |
---|
60 | // extrusion in object space |
---|
61 | // vertex unmodified if w==1, extruded if w==0 |
---|
62 | float4 newpos = |
---|
63 | (wcoord.xxxx * lightPos) + |
---|
64 | float4(position.xyz - lightPos.xyz, 0); |
---|
65 | |
---|
66 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | // Directional light extrude |
---|
71 | void shadowVolumeExtrudeDirLight_vp ( |
---|
72 | float4 position : POSITION, |
---|
73 | float wcoord : TEXCOORD0, |
---|
74 | |
---|
75 | out float4 oPosition : POSITION, |
---|
76 | |
---|
77 | uniform float4x4 worldViewProjMatrix, |
---|
78 | uniform float4 lightPos // homogenous, object space |
---|
79 | ) |
---|
80 | { |
---|
81 | // extrusion in object space |
---|
82 | // vertex unmodified if w==1, extruded if w==0 |
---|
83 | float4 newpos = |
---|
84 | (wcoord.xxxx * (position + lightPos)) - lightPos; |
---|
85 | |
---|
86 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
87 | |
---|
88 | } |
---|
89 | // Point light shadow volume extrude - FINITE |
---|
90 | void shadowVolumeExtrudePointLightFinite_vp ( |
---|
91 | float4 position : POSITION, |
---|
92 | float wcoord : TEXCOORD0, |
---|
93 | |
---|
94 | out float4 oPosition : POSITION, |
---|
95 | |
---|
96 | uniform float4x4 worldViewProjMatrix, |
---|
97 | uniform float4 lightPos, // homogeneous, object space |
---|
98 | uniform float extrusionDistance // how far to extrude |
---|
99 | ) |
---|
100 | { |
---|
101 | // extrusion in object space |
---|
102 | // vertex unmodified if w==1, extruded if w==0 |
---|
103 | float3 extrusionDir = position.xyz - lightPos.xyz; |
---|
104 | extrusionDir = normalize(extrusionDir); |
---|
105 | |
---|
106 | float4 newpos = float4(position.xyz + |
---|
107 | ((1 - wcoord.x) * extrusionDistance * extrusionDir), 1); |
---|
108 | |
---|
109 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | // Directional light extrude - FINITE |
---|
114 | void shadowVolumeExtrudeDirLightFinite_vp ( |
---|
115 | float4 position : POSITION, |
---|
116 | float wcoord : TEXCOORD0, |
---|
117 | |
---|
118 | out float4 oPosition : POSITION, |
---|
119 | |
---|
120 | uniform float4x4 worldViewProjMatrix, |
---|
121 | uniform float4 lightPos, // homogeneous, object space |
---|
122 | uniform float extrusionDistance // how far to extrude |
---|
123 | ) |
---|
124 | { |
---|
125 | // extrusion in object space |
---|
126 | // vertex unmodified if w==1, extruded if w==0 |
---|
127 | // -ve lightPos is direction |
---|
128 | float4 newpos = float4(position.xyz - |
---|
129 | (wcoord.x * extrusionDistance * lightPos.xyz), 1); |
---|
130 | |
---|
131 | oPosition = mul(worldViewProjMatrix, newpos); |
---|
132 | |
---|
133 | } |
---|
134 | @endcode |
---|
135 | */ |
---|
136 | class _OgreExport ShadowVolumeExtrudeProgram : public ShadowDataAlloc |
---|
137 | { |
---|
138 | private: |
---|
139 | static String mPointArbvp1; |
---|
140 | static String mPointVs_1_1; |
---|
141 | static String mPointVs_4_0; |
---|
142 | static String mPointVs_glsl; |
---|
143 | static String mPointVs_glsles; |
---|
144 | static String mDirArbvp1; |
---|
145 | static String mDirVs_1_1; |
---|
146 | static String mDirVs_4_0; |
---|
147 | static String mDirVs_glsl; |
---|
148 | static String mDirVs_glsles; |
---|
149 | // same as above, except the color is set to 1 to enable debug volumes to be seen |
---|
150 | static String mPointArbvp1Debug; |
---|
151 | static String mPointVs_1_1Debug; |
---|
152 | static String mPointVs_4_0Debug; |
---|
153 | static String mPointVs_glslDebug; |
---|
154 | static String mPointVs_glslesDebug; |
---|
155 | static String mDirArbvp1Debug; |
---|
156 | static String mDirVs_1_1Debug; |
---|
157 | static String mDirVs_4_0Debug; |
---|
158 | static String mDirVs_glslDebug; |
---|
159 | static String mDirVs_glslesDebug; |
---|
160 | |
---|
161 | static String mPointArbvp1Finite; |
---|
162 | static String mPointVs_1_1Finite; |
---|
163 | static String mPointVs_4_0Finite; |
---|
164 | static String mPointVs_glslFinite; |
---|
165 | static String mPointVs_glslesFinite; |
---|
166 | static String mDirArbvp1Finite; |
---|
167 | static String mDirVs_1_1Finite; |
---|
168 | static String mDirVs_4_0Finite; |
---|
169 | static String mDirVs_glslFinite; |
---|
170 | static String mDirVs_glslesFinite; |
---|
171 | // same as above, except the color is set to 1 to enable debug volumes to be seen |
---|
172 | static String mPointArbvp1FiniteDebug; |
---|
173 | static String mPointVs_1_1FiniteDebug; |
---|
174 | static String mPointVs_4_0FiniteDebug; |
---|
175 | static String mPointVs_glslFiniteDebug; |
---|
176 | static String mPointVs_glslesFiniteDebug; |
---|
177 | static String mDirArbvp1FiniteDebug; |
---|
178 | static String mDirVs_1_1FiniteDebug; |
---|
179 | static String mDirVs_4_0FiniteDebug; |
---|
180 | static String mDirVs_glslFiniteDebug; |
---|
181 | static String mDirVs_glslesFiniteDebug; |
---|
182 | |
---|
183 | static String mGeneralFs_4_0; |
---|
184 | static String mGeneralFs_glsl; |
---|
185 | static String mGeneralFs_glsles; |
---|
186 | |
---|
187 | static bool mInitialised; |
---|
188 | |
---|
189 | public: |
---|
190 | #define OGRE_NUM_SHADOW_EXTRUDER_PROGRAMS 8 |
---|
191 | enum Programs |
---|
192 | { |
---|
193 | // Point light extruder, infinite distance |
---|
194 | POINT_LIGHT = 0, |
---|
195 | // Point light extruder, infinite distance, debug mode |
---|
196 | POINT_LIGHT_DEBUG = 1, |
---|
197 | // Directional light extruder, infinite distance |
---|
198 | DIRECTIONAL_LIGHT = 2, |
---|
199 | // Directional light extruder, infinite distance, debug mode |
---|
200 | DIRECTIONAL_LIGHT_DEBUG = 3, |
---|
201 | // Point light extruder, finite distance |
---|
202 | POINT_LIGHT_FINITE = 4, |
---|
203 | // Point light extruder, finite distance, debug mode |
---|
204 | POINT_LIGHT_FINITE_DEBUG = 5, |
---|
205 | // Directional light extruder, finite distance |
---|
206 | DIRECTIONAL_LIGHT_FINITE = 6, |
---|
207 | // Directional light extruder, finite distance, debug mode |
---|
208 | DIRECTIONAL_LIGHT_FINITE_DEBUG = 7 |
---|
209 | |
---|
210 | }; |
---|
211 | static const String programNames[OGRE_NUM_SHADOW_EXTRUDER_PROGRAMS]; |
---|
212 | static String frgProgramName; |
---|
213 | |
---|
214 | /// Initialise the creation of these vertex programs |
---|
215 | static void initialise(void); |
---|
216 | /// Shutdown & destroy the vertex programs |
---|
217 | static void shutdown(void); |
---|
218 | /// Get extruder program source for point lights, compatible with arbvp1 |
---|
219 | static const String& getPointLightExtruderArbvp1(void) { return mPointArbvp1; } |
---|
220 | /// Get extruder program source for point lights, compatible with vs_1_1 |
---|
221 | static const String& getPointLightExtruderVs_1_1(void) { return mPointVs_1_1; } |
---|
222 | /// Get extruder program source for point lights, compatible with vs_4_0 |
---|
223 | static const String& getPointLightExtruderVs_4_0(void) { return mPointVs_4_0; } |
---|
224 | /// Get extruder program source for point lights, compatible with glsl |
---|
225 | static const String& getPointLightExtruderVs_glsl(void) { return mPointVs_glsl; } |
---|
226 | /// Get extruder program source for point lights, compatible with glsles |
---|
227 | static const String& getPointLightExtruderVs_glsles(void) { return mPointVs_glsles; } |
---|
228 | /// Get extruder program source for directional lights, compatible with arbvp1 |
---|
229 | static const String& getDirectionalLightExtruderArbvp1(void) { return mDirArbvp1; } |
---|
230 | /// Get extruder program source for directional lights, compatible with vs_1_1 |
---|
231 | static const String& getDirectionalLightExtruderVs_1_1(void) { return mDirVs_1_1; } |
---|
232 | /// Get extruder program source for directional lights, compatible with vs_4_0 |
---|
233 | static const String& getDirectionalLightExtruderVs_4_0(void) { return mDirVs_4_0; } |
---|
234 | /// Get extruder program source for directional lights, compatible with glsl |
---|
235 | static const String& getDirectionalLightExtruderVs_glsl(void) { return mDirVs_glsl; } |
---|
236 | /// Get extruder program source for directional lights, compatible with glsles |
---|
237 | static const String& getDirectionalLightExtruderVs_glsles(void) { return mDirVs_glsles; } |
---|
238 | |
---|
239 | /// Get extruder program source for debug point lights, compatible with arbvp1 |
---|
240 | static const String& getPointLightExtruderArbvp1Debug(void) { return mPointArbvp1Debug; } |
---|
241 | /// Get extruder program source for debug point lights, compatible with vs_1_1 |
---|
242 | static const String& getPointLightExtruderVs_1_1Debug(void) { return mPointVs_1_1Debug; } |
---|
243 | /// Get extruder program source for debug point lights, compatible with vs_4_0 |
---|
244 | static const String& getPointLightExtruderVs_4_0Debug(void) { return mPointVs_4_0Debug; } |
---|
245 | /// Get extruder program source for debug point lights, compatible with glsl |
---|
246 | static const String& getPointLightExtruderVs_glslDebug(void) { return mPointVs_glslDebug; } |
---|
247 | /// Get extruder program source for debug point lights, compatible with glsles |
---|
248 | static const String& getPointLightExtruderVs_glslesDebug(void) { return mPointVs_glslesDebug; } |
---|
249 | /// Get extruder program source for debug directional lights, compatible with arbvp1 |
---|
250 | static const String& getDirectionalLightExtruderArbvp1Debug(void) { return mDirArbvp1Debug; } |
---|
251 | /// Get extruder program source for debug directional lights, compatible with vs_1_1 |
---|
252 | static const String& getDirectionalLightExtruderVs_1_1Debug(void) { return mDirVs_1_1Debug; } |
---|
253 | /// Get extruder program source for debug directional lights, compatible with vs_4_0 |
---|
254 | static const String& getDirectionalLightExtruderVs_4_0Debug(void) { return mDirVs_4_0Debug; } |
---|
255 | /// Get extruder program source for debug directional lights, compatible with glsl |
---|
256 | static const String& getDirectionalLightExtruderVs_glslDebug(void) { return mDirVs_glslDebug; } |
---|
257 | /// Get extruder program source for debug directional lights, compatible with glsles |
---|
258 | static const String& getDirectionalLightExtruderVs_glslesDebug(void) { return mDirVs_glslesDebug; } |
---|
259 | /// General purpose method to get any of the program sources |
---|
260 | static const String& getProgramSource(Light::LightTypes lightType, const String syntax, |
---|
261 | bool finite, bool debug); |
---|
262 | |
---|
263 | static const String& getProgramName(Light::LightTypes lightType, bool finite, bool debug); |
---|
264 | |
---|
265 | |
---|
266 | /// Get FINITE extruder program source for point lights, compatible with arbvp1 |
---|
267 | static const String& getPointLightExtruderArbvp1Finite(void) { return mPointArbvp1Finite; } |
---|
268 | /// Get FINITE extruder program source for point lights, compatible with vs_1_1 |
---|
269 | static const String& getPointLightExtruderVs_1_1Finite(void) { return mPointVs_1_1Finite; } |
---|
270 | /// Get FINITE extruder program source for point lights, compatible with vs_4_0 |
---|
271 | static const String& getPointLightExtruderVs_4_0Finite(void) { return mPointVs_4_0Finite; } |
---|
272 | /// Get FINITE extruder program source for point lights, compatible with glsl |
---|
273 | static const String& getPointLightExtruderVs_glslFinite(void) { return mPointVs_glslFinite; } |
---|
274 | /// Get FINITE extruder program source for point lights, compatible with glsles |
---|
275 | static const String& getPointLightExtruderVs_glslesFinite(void) { return mPointVs_glslesFinite; } |
---|
276 | /// Get FINITE extruder program source for directional lights, compatible with arbvp1 |
---|
277 | static const String& getDirectionalLightExtruderArbvp1Finite(void) { return mDirArbvp1Finite; } |
---|
278 | /// Get FINITE extruder program source for directional lights, compatible with vs_1_1 |
---|
279 | static const String& getDirectionalLightExtruderVs_1_1Finite(void) { return mDirVs_1_1Finite; } |
---|
280 | /// Get FINITE extruder program source for directional lights, compatible with vs_4_0 |
---|
281 | static const String& getDirectionalLightExtruderVs_4_0Finite(void) { return mDirVs_4_0Finite; } |
---|
282 | /// Get FINITE extruder program source for directional lights, compatible with glsl |
---|
283 | static const String& getDirectionalLightExtruderVs_glslFinite(void) { return mDirVs_glslFinite; } |
---|
284 | /// Get FINITE extruder program source for directional lights, compatible with glsles |
---|
285 | static const String& getDirectionalLightExtruderVs_glslesFinite(void) { return mDirVs_glslesFinite; } |
---|
286 | |
---|
287 | /// Get FINITE extruder program source for debug point lights, compatible with arbvp1 |
---|
288 | static const String& getPointLightExtruderArbvp1FiniteDebug(void) { return mPointArbvp1FiniteDebug; } |
---|
289 | /// Get extruder program source for debug point lights, compatible with vs_1_1 |
---|
290 | static const String& getPointLightExtruderVs_1_1FiniteDebug(void) { return mPointVs_1_1FiniteDebug; } |
---|
291 | /// Get extruder program source for debug point lights, compatible with vs_4_0 |
---|
292 | static const String& getPointLightExtruderVs_4_0FiniteDebug(void) { return mPointVs_4_0FiniteDebug; } |
---|
293 | /// Get extruder program source for debug point lights, compatible with glsl |
---|
294 | static const String& getPointLightExtruderVs_glslFiniteDebug(void) { return mPointVs_glslFiniteDebug; } |
---|
295 | /// Get extruder program source for debug point lights, compatible with glsles |
---|
296 | static const String& getPointLightExtruderVs_glslesFiniteDebug(void) { return mPointVs_glslesFiniteDebug; } |
---|
297 | /// Get FINITE extruder program source for debug directional lights, compatible with arbvp1 |
---|
298 | static const String& getDirectionalLightExtruderArbvp1FiniteDebug(void) { return mDirArbvp1FiniteDebug; } |
---|
299 | /// Get FINITE extruder program source for debug directional lights, compatible with vs_1_1 |
---|
300 | static const String& getDirectionalLightExtruderVs_1_1FiniteDebug(void) { return mDirVs_1_1FiniteDebug; } |
---|
301 | /// Get FINITE extruder program source for debug directional lights, compatible with vs_4_0 |
---|
302 | static const String& getDirectionalLightExtruderVs_4_0FiniteDebug(void) { return mDirVs_4_0FiniteDebug; } |
---|
303 | /// Get FINITE extruder program source for debug directional lights, compatible with glsl |
---|
304 | static const String& getDirectionalLightExtruderVs_glslFiniteDebug(void) { return mDirVs_glslFiniteDebug; } |
---|
305 | /// Get FINITE extruder program source for debug directional lights, compatible with glsles |
---|
306 | static const String& getDirectionalLightExtruderVs_glslesFiniteDebug(void) { return mDirVs_glslesFiniteDebug; } |
---|
307 | |
---|
308 | }; |
---|
309 | /** @} */ |
---|
310 | /** @} */ |
---|
311 | } |
---|
312 | |
---|
313 | #include "OgreHeaderSuffix.h" |
---|
314 | |
---|
315 | #endif |
---|