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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 |
|
---|
26 | #ifndef __BiTerrainVertexProgram_H__
|
---|
27 | #define __BiTerrainVertexProgram_H__
|
---|
28 |
|
---|
29 | #include "OgrePrerequisites.h"
|
---|
30 | #include "OgreCommon.h"
|
---|
31 | #include "OgreString.h"
|
---|
32 |
|
---|
33 | namespace Ogre {
|
---|
34 |
|
---|
35 | /*
|
---|
36 | Static class containing the source to vertex programs used to
|
---|
37 | morph the terrain LOD levels. The programs are generated from
|
---|
38 | the following Cg:
|
---|
39 | @code
|
---|
40 | // No fog morphing terrain
|
---|
41 | void terrain_vp(
|
---|
42 | float4 position : POSITION,
|
---|
43 | float2 uv1 : TEXCOORD0,
|
---|
44 | float2 uv2 : TEXCOORD1,
|
---|
45 | float delta : BLENDWEIGHT,
|
---|
46 |
|
---|
47 | out float4 oPosition : POSITION,
|
---|
48 | out float2 oUv1 : TEXCOORD0,
|
---|
49 | out float2 oUv2 : TEXCOORD1,
|
---|
50 | out float4 colour : COLOR,
|
---|
51 | uniform float4x4 worldViewProj,
|
---|
52 | uniform float morphFactor
|
---|
53 | )
|
---|
54 | {
|
---|
55 | // Apply morph
|
---|
56 | position.y = position.y + (delta.x * morphFactor);
|
---|
57 | // world / view / projection
|
---|
58 | oPosition = mul(worldViewProj, position);
|
---|
59 | // Main texture coords
|
---|
60 | oUv1 = uv1;
|
---|
61 | // Detail texture coords
|
---|
62 | oUv2 = uv2;
|
---|
63 | // Full bright (no lighting)
|
---|
64 | colour = float4(1,1,1,1);
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | // Linear fogged morphing terrain
|
---|
69 | void terrain_vp_linear(
|
---|
70 | float4 position : POSITION,
|
---|
71 | float2 uv1 : TEXCOORD0,
|
---|
72 | float2 uv2 : TEXCOORD1,
|
---|
73 | float delta : BLENDWEIGHT,
|
---|
74 |
|
---|
75 | out float4 oPosition : POSITION,
|
---|
76 | out float2 oUv1 : TEXCOORD0,
|
---|
77 | out float2 oUv2 : TEXCOORD1,
|
---|
78 | out float4 colour : COLOR,
|
---|
79 | out float fog : FOG,
|
---|
80 | uniform float4x4 worldViewProj,
|
---|
81 | uniform float morphFactor
|
---|
82 | )
|
---|
83 | {
|
---|
84 | // Apply morph
|
---|
85 | position.y = position.y + (delta.x * morphFactor);
|
---|
86 | // world / view / projection
|
---|
87 | oPosition = mul(worldViewProj, position);
|
---|
88 | // Main texture coords
|
---|
89 | oUv1 = uv1;
|
---|
90 | // Detail texture coords
|
---|
91 | oUv2 = uv2;
|
---|
92 | // Full bright (no lighting)
|
---|
93 | colour = float4(1,1,1,1);
|
---|
94 | // Fog
|
---|
95 | // f = end - camz / end - start
|
---|
96 | // when start / end has been set, fog value is distance
|
---|
97 | fog = oPosition.z;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | // Exp fogged morphing terrain
|
---|
102 | void terrain_vp_exp(
|
---|
103 | float4 position : POSITION,
|
---|
104 | float2 uv1 : TEXCOORD0,
|
---|
105 | float2 uv2 : TEXCOORD1,
|
---|
106 | float delta : BLENDWEIGHT,
|
---|
107 |
|
---|
108 | out float4 oPosition : POSITION,
|
---|
109 | out float2 oUv1 : TEXCOORD0,
|
---|
110 | out float2 oUv2 : TEXCOORD1,
|
---|
111 | out float4 colour : COLOR,
|
---|
112 | out float fog : FOG,
|
---|
113 | uniform float4x4 worldViewProj,
|
---|
114 | uniform float morphFactor,
|
---|
115 | uniform float fogDensity)
|
---|
116 | {
|
---|
117 | // Apply morph
|
---|
118 | position.y = position.y + (delta.x * morphFactor);
|
---|
119 | // world / view / projection
|
---|
120 | oPosition = mul(worldViewProj, position);
|
---|
121 | // Main texture coords
|
---|
122 | oUv1 = uv1;
|
---|
123 | // Detail texture coords
|
---|
124 | oUv2 = uv2;
|
---|
125 | // Full bright (no lighting)
|
---|
126 | colour = float4(1,1,1,1);
|
---|
127 | // Fog
|
---|
128 | // f = 1 / e ^ (camz x density)
|
---|
129 | // note pow = exp(src1 * log(src0)).
|
---|
130 | fog = 1 / (exp((oPosition.z * fogDensity) * log(2.718281828)));
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | // Exp2 fogged morphing terrain
|
---|
135 | void terrain_vp_exp2(
|
---|
136 | float4 position : POSITION,
|
---|
137 | float2 uv1 : TEXCOORD0,
|
---|
138 | float2 uv2 : TEXCOORD1,
|
---|
139 | float delta : BLENDWEIGHT,
|
---|
140 |
|
---|
141 | out float4 oPosition : POSITION,
|
---|
142 | out float2 oUv1 : TEXCOORD0,
|
---|
143 | out float2 oUv2 : TEXCOORD1,
|
---|
144 | out float4 colour : COLOR,
|
---|
145 | out float fog : FOG,
|
---|
146 | uniform float4x4 worldViewProj,
|
---|
147 | uniform float morphFactor,
|
---|
148 | uniform float fogDensity)
|
---|
149 | {
|
---|
150 | // Apply morph
|
---|
151 | position.y = position.y + (delta.x * morphFactor);
|
---|
152 | // world / view / projection
|
---|
153 | oPosition = mul(worldViewProj, position);
|
---|
154 | // Main texture coords
|
---|
155 | oUv1 = uv1;
|
---|
156 | // Detail texture coords
|
---|
157 | oUv2 = uv2;
|
---|
158 | // Full bright (no lighting)
|
---|
159 | colour = float4(1,1,1,1);
|
---|
160 | // Fog
|
---|
161 | // f = 1 / e ^ (camz x density)^2
|
---|
162 | // note pow = exp(src1 * log(src0)).
|
---|
163 | float src1 = oPosition.z * 0.002;
|
---|
164 | fog = 1 / (exp((src1*src1) * log(2.718281828f)));
|
---|
165 | }
|
---|
166 |
|
---|
167 | // Shadow receiver vertex program
|
---|
168 | void terrain_shadow_receiver_vp(
|
---|
169 | float4 position : POSITION,
|
---|
170 | float2 uv1 : TEXCOORD0,
|
---|
171 | float2 uv2 : TEXCOORD1,
|
---|
172 | float delta : BLENDWEIGHT,
|
---|
173 |
|
---|
174 | out float4 oPosition : POSITION,
|
---|
175 | out float2 oUv1 : TEXCOORD0,
|
---|
176 | out float4 colour : COLOR,
|
---|
177 | uniform float4x4 worldViewProj,
|
---|
178 | uniform float4x4 world,
|
---|
179 | uniform float4x4 textureViewProj,
|
---|
180 | uniform float morphFactor
|
---|
181 | )
|
---|
182 | {
|
---|
183 | // Apply morph
|
---|
184 | position.y = position.y + (delta.x * morphFactor);
|
---|
185 | // world / view / projection
|
---|
186 | oPosition = mul(worldViewProj, position);
|
---|
187 |
|
---|
188 | // Main texture coords
|
---|
189 | float4 worldpos = mul(world, position);
|
---|
190 | float4 projuv = mul(textureViewProj, worldpos);
|
---|
191 | oUv1.xy = projuv.xy / projuv.w;
|
---|
192 | // Full bright (no lighting)
|
---|
193 | colour = float4(1,1,1,1);
|
---|
194 | }
|
---|
195 |
|
---|
196 | @endcode
|
---|
197 | */
|
---|
198 | class BiTerrainVertexProgram
|
---|
199 | {
|
---|
200 | private:
|
---|
201 | static String mNoFogArbvp1;
|
---|
202 | static String mLinearFogArbvp1;
|
---|
203 | static String mExpFogArbvp1;
|
---|
204 | static String mExp2FogArbvp1;
|
---|
205 | static String mShadowReceiverArbvp1;
|
---|
206 |
|
---|
207 | static String mNoFogVs_1_1;
|
---|
208 | static String mLinearFogVs_1_1;
|
---|
209 | static String mExpFogVs_1_1;
|
---|
210 | static String mExp2FogVs_1_1;
|
---|
211 | static String mShadowReceiverVs_1_1;
|
---|
212 |
|
---|
213 | public:
|
---|
214 | /// General purpose method to get any of the program sources
|
---|
215 | static const String& getProgramSource(FogMode fogMode,
|
---|
216 | const String syntax, bool shadowReceiver = false);
|
---|
217 |
|
---|
218 |
|
---|
219 | };
|
---|
220 | }
|
---|
221 |
|
---|
222 | #endif
|
---|