Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/PlugIns/OctreeSceneManager/include/OgreTerrainVertexProgram.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 6.6 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29
30#ifndef __TERRAINVERTEXPROGRAM_H__
31#define __TERRAINVERTEXPROGRAM_H__
32
33#include "OgrePrerequisites.h"
34#include "OgreCommon.h"
35#include "OgreString.h"
36
37namespace Ogre {
38
39    /*
40    Static class containing the source to vertex programs used to
41    morph the terrain LOD levels. The programs are generated from
42    the following Cg:
43    @code       
44    // No fog morphing terrain
45    void terrain_vp(
46            float4 position : POSITION,
47            float2 uv1          : TEXCOORD0,
48            float2 uv2          : TEXCOORD1,
49            float delta     : BLENDWEIGHT,
50
51            out float4 oPosition : POSITION,
52            out float2 oUv1              : TEXCOORD0,
53            out float2 oUv2              : TEXCOORD1,
54            out float4 colour    : COLOR,
55            uniform float4x4 worldViewProj,
56            uniform float morphFactor
57            )
58    {
59            // Apply morph
60            position.y = position.y + (delta.x * morphFactor);
61            // world / view / projection
62            oPosition = mul(worldViewProj, position);
63            // Main texture coords
64            oUv1 = uv1;
65            // Detail texture coords
66            oUv2 = uv2;
67            // Full bright (no lighting)
68            colour = float4(1,1,1,1);
69    }
70
71
72    // Linear fogged morphing terrain
73    void terrain_vp_linear(
74            float4 position : POSITION,
75            float2 uv1          : TEXCOORD0,
76            float2 uv2          : TEXCOORD1,
77            float delta     : BLENDWEIGHT,
78
79            out float4 oPosition : POSITION,
80            out float2 oUv1              : TEXCOORD0,
81            out float2 oUv2              : TEXCOORD1,
82            out float4 colour    : COLOR,
83            out float fog                : FOG,
84            uniform float4x4 worldViewProj,
85            uniform float morphFactor
86            )
87    {
88            // Apply morph
89            position.y = position.y + (delta.x * morphFactor);
90            // world / view / projection
91            oPosition = mul(worldViewProj, position);
92            // Main texture coords
93            oUv1 = uv1;
94            // Detail texture coords
95            oUv2 = uv2;
96            // Full bright (no lighting)
97            colour = float4(1,1,1,1);
98            // Fog
99            // f = end - camz / end - start
100            // when start / end has been set, fog value is distance
101            fog = oPosition.z;
102    }
103
104
105    // Exp fogged morphing terrain
106    void terrain_vp_exp(
107            float4 position : POSITION,
108            float2 uv1          : TEXCOORD0,
109            float2 uv2          : TEXCOORD1,
110            float delta     : BLENDWEIGHT,
111
112            out float4 oPosition : POSITION,
113            out float2 oUv1              : TEXCOORD0,
114            out float2 oUv2              : TEXCOORD1,
115            out float4 colour    : COLOR,
116            out float fog                : FOG,
117            uniform float4x4 worldViewProj,
118            uniform float morphFactor,
119            uniform float fogDensity)
120    {
121            // Apply morph
122            position.y = position.y + (delta.x * morphFactor);
123            // world / view / projection
124            oPosition = mul(worldViewProj, position);
125            // Main texture coords
126            oUv1 = uv1;
127            // Detail texture coords
128            oUv2 = uv2;
129            // Full bright (no lighting)
130            colour = float4(1,1,1,1);
131            // Fog
132            // f = 1 / e ^ (camz x density)
133            // note pow = exp(src1 * log(src0)).
134            fog = 1 / (exp((oPosition.z * fogDensity) * log(2.718281828)));
135    }
136
137
138    // Exp2 fogged morphing terrain
139    void terrain_vp_exp2(
140            float4 position : POSITION,
141            float2 uv1          : TEXCOORD0,
142            float2 uv2          : TEXCOORD1,
143            float delta     : BLENDWEIGHT,
144
145            out float4 oPosition : POSITION,
146            out float2 oUv1              : TEXCOORD0,
147            out float2 oUv2              : TEXCOORD1,
148            out float4 colour    : COLOR,
149            out float fog                : FOG,
150            uniform float4x4 worldViewProj,
151            uniform float morphFactor,
152            uniform float fogDensity)
153    {
154            // Apply morph
155            position.y = position.y + (delta.x * morphFactor);
156            // world / view / projection
157            oPosition = mul(worldViewProj, position);
158            // Main texture coords
159            oUv1 = uv1;
160            // Detail texture coords
161            oUv2 = uv2;
162            // Full bright (no lighting)
163            colour = float4(1,1,1,1);
164            // Fog
165            // f = 1 / e ^ (camz x density)^2
166            // note pow = exp(src1 * log(src0)).
167            float src1 = oPosition.z * 0.002;
168            fog = 1 / (exp((src1*src1) * log(2.718281828f)));
169    }
170
171        // Shadow receiver vertex program
172    void terrain_shadow_receiver_vp(
173            float4 position : POSITION,
174            float2 uv1          : TEXCOORD0,
175            float2 uv2          : TEXCOORD1,
176            float delta     : BLENDWEIGHT,
177
178            out float4 oPosition : POSITION,
179            out float2 oUv1              : TEXCOORD0,
180            out float4 colour    : COLOR,
181            uniform float4x4 worldViewProj,
182                uniform float4x4 world,
183            uniform float4x4 textureViewProj,
184            uniform float morphFactor
185            )
186    {
187            // Apply morph
188            position.y = position.y + (delta.x * morphFactor);
189            // world / view / projection
190            oPosition = mul(worldViewProj, position);
191               
192            // Main texture coords
193                float4 worldpos = mul(world, position);
194            float4 projuv = mul(textureViewProj, worldpos);
195                oUv1.xy = projuv.xy / projuv.w;
196            // Full bright (no lighting)
197            colour = float4(1,1,1,1);
198    }
199
200    @endcode
201    */
202    class TerrainVertexProgram
203    {
204    private:
205        static String mNoFogArbvp1;
206        static String mLinearFogArbvp1;
207        static String mExpFogArbvp1;
208        static String mExp2FogArbvp1;
209                static String mShadowReceiverArbvp1;
210
211        static String mNoFogVs_1_1;
212        static String mLinearFogVs_1_1;
213        static String mExpFogVs_1_1;
214        static String mExp2FogVs_1_1;
215                static String mShadowReceiverVs_1_1;
216
217    public:
218        /// General purpose method to get any of the program sources
219        static const String& getProgramSource(FogMode fogMode, 
220                        const String syntax, bool shadowReceiver = false);
221
222
223    };
224}
225
226#endif
Note: See TracBrowser for help on using the repository browser.