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