1 | |
---|
2 | /* |
---|
3 | ----------------------------------------------------------------------------- |
---|
4 | This source file is part of OGRE |
---|
5 | (Object-oriented Graphics Rendering Engine) |
---|
6 | For the latest info, see http://www.ogre3d.org/ |
---|
7 | |
---|
8 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
9 | Also see acknowledgements in Readme.html |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under |
---|
12 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
13 | Foundation; either version 2 of the License, or (at your option) any later |
---|
14 | version. |
---|
15 | |
---|
16 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU Lesser General Public License along with |
---|
21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
23 | http://www.gnu.org/copyleft/lesser.txt. |
---|
24 | |
---|
25 | You may alternatively use this source under the terms of a specific version of |
---|
26 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
27 | Torus Knot Software Ltd. |
---|
28 | ----------------------------------------------------------------------------- |
---|
29 | */ |
---|
30 | |
---|
31 | #include "OgreTerrainVertexProgram.h" |
---|
32 | |
---|
33 | namespace Ogre { |
---|
34 | |
---|
35 | String TerrainVertexProgram::mNoFogArbvp1 = |
---|
36 | "!!ARBvp1.0\n" |
---|
37 | "PARAM c5 = { 1, 1, 1, 1 };\n" |
---|
38 | "#var float4x4 worldViewProj : : c[0], 4 : 8 : 1\n" |
---|
39 | "#var float morphFactor : : c[4] : 9 : 1\n" |
---|
40 | "TEMP R0;\n" |
---|
41 | "ATTRIB v17 = vertex.attrib[1];\n" |
---|
42 | "ATTRIB v25 = vertex.texcoord[1];\n" |
---|
43 | "ATTRIB v24 = vertex.texcoord[0];\n" |
---|
44 | "ATTRIB v16 = vertex.position;\n" |
---|
45 | "PARAM c0[4] = { program.local[0..3] };\n" |
---|
46 | "PARAM c4 = program.local[4];\n" |
---|
47 | " MOV result.texcoord[0], v24;\n" |
---|
48 | " MOV result.texcoord[1], v25;\n" |
---|
49 | " MOV R0, v16;\n" |
---|
50 | " MAD R0.y, v17.x, c4.x, R0.y;\n" |
---|
51 | " DP4 result.position.x, c0[0], R0;\n" |
---|
52 | " DP4 result.position.y, c0[1], R0;\n" |
---|
53 | " DP4 result.position.z, c0[2], R0;\n" |
---|
54 | " DP4 result.position.w, c0[3], R0;\n" |
---|
55 | " MOV result.color.front.primary, c5.x;\n" |
---|
56 | "END\n"; |
---|
57 | |
---|
58 | String TerrainVertexProgram::mShadowReceiverArbvp1 = |
---|
59 | "!!ARBvp1.0\n" |
---|
60 | "PARAM c[14] = { program.local[0..12], { 1 } };\n" |
---|
61 | "TEMP R0;\n" |
---|
62 | "TEMP R1;\n" |
---|
63 | "TEMP R2;\n" |
---|
64 | "MOV result.color, c[13].x;\n" |
---|
65 | "MUL R0.x, vertex.attrib[1], c[12];\n" |
---|
66 | "ADD R1.y, R0.x, vertex.position;\n" |
---|
67 | "MOV R1.xzw, vertex.position;\n" |
---|
68 | "DP4 result.position.w, R1, c[3];\n" |
---|
69 | "DP4 result.position.z, R1, c[2];\n" |
---|
70 | "DP4 R0.w, R1, c[7];\n" |
---|
71 | "DP4 R0.z, R1, c[6];\n" |
---|
72 | "DP4 R0.y, R1, c[5];\n" |
---|
73 | "DP4 R0.x, R1, c[4];\n" |
---|
74 | "DP4 result.position.y, R1, c[1];\n" |
---|
75 | "DP4 R2.y, R0, c[9];\n" |
---|
76 | "DP4 R2.z, R0, c[11];\n" |
---|
77 | "DP4 R2.x, R0, c[8];\n" |
---|
78 | "RCP R0.x, R2.z;\n" |
---|
79 | "DP4 result.position.x, R1, c[0];\n" |
---|
80 | "MUL result.texcoord[0].xy, R2, R0.x;\n" |
---|
81 | "END\n"; |
---|
82 | String TerrainVertexProgram::mLinearFogArbvp1 = |
---|
83 | "!!ARBvp1.0\n" |
---|
84 | "PARAM c5 = { 1, 1, 1, 1 };\n" |
---|
85 | "#var float4x4 worldViewProj : : c[0], 4 : 9 : 1\n" |
---|
86 | "#var float morphFactor : : c[4] : 10 : 1\n" |
---|
87 | "TEMP R0, R1;\n" |
---|
88 | "ATTRIB v17 = vertex.attrib[1];\n" |
---|
89 | "ATTRIB v25 = vertex.texcoord[1];\n" |
---|
90 | "ATTRIB v24 = vertex.texcoord[0];\n" |
---|
91 | "ATTRIB v16 = vertex.position;\n" |
---|
92 | "PARAM c0[4] = { program.local[0..3] };\n" |
---|
93 | "PARAM c4 = program.local[4];\n" |
---|
94 | " MOV result.texcoord[0], v24;\n" |
---|
95 | " MOV result.texcoord[1], v25;\n" |
---|
96 | " MOV R1, v16;\n" |
---|
97 | " MAD R1.y, v17.x, c4.x, R1.y;\n" |
---|
98 | " DP4 R0.x, c0[0], R1;\n" |
---|
99 | " DP4 R0.y, c0[1], R1;\n" |
---|
100 | " DP4 R0.z, c0[2], R1;\n" |
---|
101 | " DP4 R0.w, c0[3], R1;\n" |
---|
102 | " MOV result.fogcoord.x, R0.z;\n" |
---|
103 | " MOV result.position, R0;\n" |
---|
104 | " MOV result.color.front.primary, c5.x;\n" |
---|
105 | "END\n"; |
---|
106 | String TerrainVertexProgram::mExpFogArbvp1 = |
---|
107 | "!!ARBvp1.0\n" |
---|
108 | "PARAM c6 = { 1, 1, 1, 1 };\n" |
---|
109 | "PARAM c7 = { 2.71828, 0, 0, 0 };\n" |
---|
110 | "#var float4x4 worldViewProj : : c[0], 4 : 9 : 1\n" |
---|
111 | "#var float morphFactor : : c[4] : 10 : 1\n" |
---|
112 | "#var float fogDensity : : c[5] : 11 : 1\n" |
---|
113 | "TEMP R0, R1;\n" |
---|
114 | "ATTRIB v17 = vertex.attrib[1];\n" |
---|
115 | "ATTRIB v25 = vertex.texcoord[1];\n" |
---|
116 | "ATTRIB v24 = vertex.texcoord[0];\n" |
---|
117 | "ATTRIB v16 = vertex.position;\n" |
---|
118 | "PARAM c5 = program.local[5];\n" |
---|
119 | "PARAM c0[4] = { program.local[0..3] };\n" |
---|
120 | "PARAM c4 = program.local[4];\n" |
---|
121 | " MOV result.texcoord[0], v24;\n" |
---|
122 | " MOV result.texcoord[1], v25;\n" |
---|
123 | " MOV R1, v16;\n" |
---|
124 | " MAD R1.y, v17.x, c4.x, R1.y;\n" |
---|
125 | " DP4 R0.x, c0[0], R1;\n" |
---|
126 | " DP4 R0.y, c0[1], R1;\n" |
---|
127 | " DP4 R0.z, c0[2], R1;\n" |
---|
128 | " DP4 R0.w, c0[3], R1;\n" |
---|
129 | " MOV result.position, R0;\n" |
---|
130 | " MOV result.color.front.primary, c6.x;\n" |
---|
131 | " MUL R0.zw, R0.z, c5.x;\n" |
---|
132 | " MOV R0.xy, c7.x;\n" |
---|
133 | " LIT R0.z, R0;\n" |
---|
134 | " RCP result.fogcoord.x, R0.z;\n" |
---|
135 | "END\n"; |
---|
136 | String TerrainVertexProgram::mExp2FogArbvp1 = |
---|
137 | "!!ARBvp1.0\n" |
---|
138 | "PARAM c6 = { 1, 1, 1, 1 };\n" |
---|
139 | "PARAM c7 = { 0.002, 2.71828, 0, 0 };\n" |
---|
140 | "#var float4x4 worldViewProj : : c[0], 4 : 9 : 1\n" |
---|
141 | "#var float morphFactor : : c[4] : 10 : 1\n" |
---|
142 | "#var float fogDensity : : c[5] : 11 : 1\n" |
---|
143 | "TEMP R0, R1;\n" |
---|
144 | "ATTRIB v17 = vertex.attrib[1];\n" |
---|
145 | "ATTRIB v25 = vertex.texcoord[1];\n" |
---|
146 | "ATTRIB v24 = vertex.texcoord[0];\n" |
---|
147 | "ATTRIB v16 = vertex.position;\n" |
---|
148 | "PARAM c0[4] = { program.local[0..3] };\n" |
---|
149 | "PARAM c4 = program.local[4];\n" |
---|
150 | " MOV result.texcoord[0], v24;\n" |
---|
151 | " MOV result.texcoord[1], v25;\n" |
---|
152 | " MOV R1, v16;\n" |
---|
153 | " MAD R1.y, v17.x, c4.x, R1.y;\n" |
---|
154 | " DP4 R0.x, c0[0], R1;\n" |
---|
155 | " DP4 R0.y, c0[1], R1;\n" |
---|
156 | " DP4 R0.z, c0[2], R1;\n" |
---|
157 | " DP4 R0.w, c0[3], R1;\n" |
---|
158 | " MOV result.position, R0;\n" |
---|
159 | " MOV result.color.front.primary, c6.x;\n" |
---|
160 | " MUL R0.x, R0.z, c7.x;\n" |
---|
161 | " MUL R0.zw, R0.x, R0.x;\n" |
---|
162 | " MOV R0.xy, c7.y;\n" |
---|
163 | " LIT R0.z, R0;\n" |
---|
164 | " RCP result.fogcoord.x, R0.z;\n" |
---|
165 | "END\n"; |
---|
166 | |
---|
167 | String TerrainVertexProgram::mNoFogVs_1_1 = |
---|
168 | "vs_1_1\n" |
---|
169 | "def c5, 1, 1, 1, 1\n" |
---|
170 | "//var float4x4 worldViewProj : : c[0], 4 : 8 : 1\n" |
---|
171 | "//var float morphFactor : : c[4] : 9 : 1\n" |
---|
172 | "dcl_blendweight v1\n" |
---|
173 | "dcl_texcoord1 v8\n" |
---|
174 | "dcl_texcoord0 v7\n" |
---|
175 | "dcl_position v0\n" |
---|
176 | " mov oT0.xy, v7\n" |
---|
177 | " mov oT1.xy, v8\n" |
---|
178 | " mov r0, v0\n" |
---|
179 | " mad r0.y, v1.x, c4.x, r0.y\n" |
---|
180 | " dp4 oPos.x, c0, r0\n" |
---|
181 | " dp4 oPos.y, c1, r0\n" |
---|
182 | " dp4 oPos.z, c2, r0\n" |
---|
183 | " dp4 oPos.w, c3, r0\n" |
---|
184 | " mov oD0, c5.x\n"; |
---|
185 | String TerrainVertexProgram::mLinearFogVs_1_1 = |
---|
186 | "vs_1_1\n" |
---|
187 | "def c5, 1, 1, 1, 1\n" |
---|
188 | "//var float4x4 worldViewProj : : c[0], 4 : 9 : 1\n" |
---|
189 | "//var float morphFactor : : c[4] : 10 : 1\n" |
---|
190 | "dcl_blendweight v1\n" |
---|
191 | "dcl_texcoord1 v8\n" |
---|
192 | "dcl_texcoord0 v7\n" |
---|
193 | "dcl_position v0\n" |
---|
194 | " mov oT0.xy, v7\n" |
---|
195 | " mov oT1.xy, v8\n" |
---|
196 | " mov r1, v0\n" |
---|
197 | " mad r1.y, v1.x, c4.x, r1.y\n" |
---|
198 | " dp4 r0.x, c0, r1\n" |
---|
199 | " dp4 r0.y, c1, r1\n" |
---|
200 | " dp4 r0.z, c2, r1\n" |
---|
201 | " dp4 r0.w, c3, r1\n" |
---|
202 | " mov oFog, r0.z\n" |
---|
203 | " mov oPos, r0\n" |
---|
204 | " mov oD0, c5.x\n"; |
---|
205 | |
---|
206 | String TerrainVertexProgram::mShadowReceiverVs_1_1 = |
---|
207 | "vs_1_1\n" |
---|
208 | "def c13, 1, 1, 1, 1\n" |
---|
209 | "dcl_blendweight v1\n" |
---|
210 | "dcl_texcoord1 v8\n" |
---|
211 | "dcl_texcoord0 v7\n" |
---|
212 | "dcl_position v0\n" |
---|
213 | "mov r1, v0\n" |
---|
214 | "mad r1.y, v1.x, c12.x, r1.y\n" |
---|
215 | "dp4 oPos.x, c0, r1\n" |
---|
216 | "dp4 oPos.y, c1, r1\n" |
---|
217 | "dp4 oPos.z, c2, r1\n" |
---|
218 | "dp4 oPos.w, c3, r1\n" |
---|
219 | "dp4 r0.x, c4, r1\n" |
---|
220 | "dp4 r0.y, c5, r1\n" |
---|
221 | "dp4 r0.z, c6, r1\n" |
---|
222 | "dp4 r0.w, c7, r1\n" |
---|
223 | "dp4 r1.x, c8, r0\n" |
---|
224 | "dp4 r1.y, c9, r0\n" |
---|
225 | "dp4 r1.w, c11, r0\n" |
---|
226 | "rcp r0.x, r1.w\n" |
---|
227 | "mul oT0.xy, r1.xy, r0.x\n" |
---|
228 | "mov oD0, c13\n"; |
---|
229 | String TerrainVertexProgram::mExpFogVs_1_1 = |
---|
230 | "vs_1_1\n" |
---|
231 | "def c6, 1, 1, 1, 1\n" |
---|
232 | "def c7, 2.71828, 0, 0, 0\n" |
---|
233 | "//var float4x4 worldViewProj : : c[0], 4 : 9 : 1\n" |
---|
234 | "//var float morphFactor : : c[4] : 10 : 1\n" |
---|
235 | "//var float fogDensity : : c[5] : 11 : 1\n" |
---|
236 | "dcl_blendweight v1\n" |
---|
237 | "dcl_texcoord1 v8\n" |
---|
238 | "dcl_texcoord0 v7\n" |
---|
239 | "dcl_position v0\n" |
---|
240 | " mov oT0.xy, v7\n" |
---|
241 | " mov oT1.xy, v8\n" |
---|
242 | " mov r1, v0\n" |
---|
243 | " mad r1.y, v1.x, c4.x, r1.y\n" |
---|
244 | " dp4 r0.x, c0, r1\n" |
---|
245 | " dp4 r0.y, c1, r1\n" |
---|
246 | " dp4 r0.z, c2, r1\n" |
---|
247 | " dp4 r0.w, c3, r1\n" |
---|
248 | " mov oPos, r0\n" |
---|
249 | " mov oD0, c6.x\n" |
---|
250 | " mul r0.zw, r0.z, c5.x\n" |
---|
251 | " mov r0.xy, c7.x\n" |
---|
252 | " lit r0.z, r0\n" |
---|
253 | " rcp oFog, r0.z\n"; |
---|
254 | String TerrainVertexProgram::mExp2FogVs_1_1 = |
---|
255 | "vs_1_1\n" |
---|
256 | "def c6, 1, 1, 1, 1\n" |
---|
257 | "def c7, 0.002, 2.71828, 0, 0\n" |
---|
258 | "//var float4x4 worldViewProj : : c[0], 4 : 9 : 1\n" |
---|
259 | "//var float morphFactor : : c[4] : 10 : 1\n" |
---|
260 | "//var float fogDensity : : c[5] : 11 : 1\n" |
---|
261 | "dcl_blendweight v1\n" |
---|
262 | "dcl_texcoord1 v8\n" |
---|
263 | "dcl_texcoord0 v7\n" |
---|
264 | "dcl_position v0\n" |
---|
265 | " mov oT0.xy, v7\n" |
---|
266 | " mov oT1.xy, v8\n" |
---|
267 | " mov r1, v0\n" |
---|
268 | " mad r1.y, v1.x, c4.x, r1.y\n" |
---|
269 | " dp4 r0.x, c0, r1\n" |
---|
270 | " dp4 r0.y, c1, r1\n" |
---|
271 | " dp4 r0.z, c2, r1\n" |
---|
272 | " dp4 r0.w, c3, r1\n" |
---|
273 | " mov oPos, r0\n" |
---|
274 | " mov oD0, c6.x\n" |
---|
275 | " mul r0.x, r0.z, c7.x\n" |
---|
276 | " mul r0.zw, r0.x, r0.x\n" |
---|
277 | " mov r0.xy, c7.y\n" |
---|
278 | " lit r0.z, r0\n" |
---|
279 | " rcp oFog, r0.z\n"; |
---|
280 | |
---|
281 | const String& TerrainVertexProgram::getProgramSource( |
---|
282 | FogMode fogMode, const String syntax, bool shadowReceiver) |
---|
283 | { |
---|
284 | if (shadowReceiver) |
---|
285 | { |
---|
286 | if (syntax == "arbvp1") |
---|
287 | { |
---|
288 | return mShadowReceiverArbvp1; |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | return mShadowReceiverVs_1_1; |
---|
293 | } |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | |
---|
298 | switch(fogMode) |
---|
299 | { |
---|
300 | case FOG_NONE: |
---|
301 | if (syntax == "arbvp1") |
---|
302 | { |
---|
303 | return mNoFogArbvp1; |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | return mNoFogVs_1_1; |
---|
308 | } |
---|
309 | break; |
---|
310 | case FOG_LINEAR: |
---|
311 | if (syntax == "arbvp1") |
---|
312 | { |
---|
313 | return mLinearFogArbvp1; |
---|
314 | } |
---|
315 | else |
---|
316 | { |
---|
317 | return mLinearFogVs_1_1; |
---|
318 | } |
---|
319 | break; |
---|
320 | case FOG_EXP: |
---|
321 | if (syntax == "arbvp1") |
---|
322 | { |
---|
323 | return mExpFogArbvp1; |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | return mExpFogVs_1_1; |
---|
328 | } |
---|
329 | break; |
---|
330 | case FOG_EXP2: |
---|
331 | if (syntax == "arbvp1") |
---|
332 | { |
---|
333 | return mExp2FogArbvp1; |
---|
334 | } |
---|
335 | else |
---|
336 | { |
---|
337 | return mExp2FogVs_1_1; |
---|
338 | } |
---|
339 | break; |
---|
340 | }; |
---|
341 | } |
---|
342 | // default |
---|
343 | return StringUtil::BLANK; |
---|
344 | |
---|
345 | } |
---|
346 | } |
---|