Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreTerrainVertexProgram.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 #ifndef __TERRAINVERTEXPROGRAM_H__
00027 #define __TERRAINVERTEXPROGRAM_H__
00028 
00029 #include "OgrePrerequisites.h"
00030 #include "OgreCommon.h"
00031 #include "OgreString.h"
00032 
00033 namespace Ogre {
00034 
00035     /*
00036     Static class containing the source to vertex programs used to 
00037     morph the terrain LOD levels. The programs are generated from 
00038     the following Cg:
00039     @code   
00040     // No fog morphing terrain
00041     void terrain_vp(
00042         float4 position : POSITION,
00043         float2 uv1      : TEXCOORD0,
00044         float2 uv2      : TEXCOORD1,
00045         float delta     : BLENDWEIGHT,
00046 
00047         out float4 oPosition : POSITION,
00048         out float2 oUv1      : TEXCOORD0,
00049         out float2 oUv2      : TEXCOORD1,
00050         out float4 colour    : COLOR,
00051         uniform float4x4 worldViewProj,
00052         uniform float morphFactor
00053         )
00054     {
00055         // Apply morph
00056         position.y = position.y + (delta.x * morphFactor);
00057         // world / view / projection
00058         oPosition = mul(worldViewProj, position);
00059         // Main texture coords
00060         oUv1 = uv1;
00061         // Detail texture coords
00062         oUv2 = uv2;
00063         // Full bright (no lighting)
00064         colour = float4(1,1,1,1);
00065     }
00066 
00067 
00068     // Linear fogged morphing terrain
00069     void terrain_vp_linear(
00070         float4 position : POSITION,
00071         float2 uv1      : TEXCOORD0,
00072         float2 uv2      : TEXCOORD1,
00073         float delta     : BLENDWEIGHT,
00074 
00075         out float4 oPosition : POSITION,
00076         out float2 oUv1      : TEXCOORD0,
00077         out float2 oUv2      : TEXCOORD1,
00078         out float4 colour    : COLOR,
00079         out float fog        : FOG,
00080         uniform float4x4 worldViewProj,
00081         uniform float morphFactor
00082         )
00083     {
00084         // Apply morph
00085         position.y = position.y + (delta.x * morphFactor);
00086         // world / view / projection
00087         oPosition = mul(worldViewProj, position);
00088         // Main texture coords
00089         oUv1 = uv1;
00090         // Detail texture coords
00091         oUv2 = uv2;
00092         // Full bright (no lighting)
00093         colour = float4(1,1,1,1);
00094         // Fog 
00095         // f = end - camz / end - start
00096         // when start / end has been set, fog value is distance
00097         fog = oPosition.z;
00098     }
00099 
00100 
00101     // Exp fogged morphing terrain
00102     void terrain_vp_exp(
00103         float4 position : POSITION,
00104         float2 uv1      : TEXCOORD0,
00105         float2 uv2      : TEXCOORD1,
00106         float delta     : BLENDWEIGHT,
00107 
00108         out float4 oPosition : POSITION,
00109         out float2 oUv1      : TEXCOORD0,
00110         out float2 oUv2      : TEXCOORD1,
00111         out float4 colour    : COLOR,
00112         out float fog        : FOG,
00113         uniform float4x4 worldViewProj,
00114         uniform float morphFactor,
00115         uniform float fogDensity)
00116     {
00117         // Apply morph
00118         position.y = position.y + (delta.x * morphFactor);
00119         // world / view / projection
00120         oPosition = mul(worldViewProj, position);
00121         // Main texture coords
00122         oUv1 = uv1;
00123         // Detail texture coords
00124         oUv2 = uv2;
00125         // Full bright (no lighting)
00126         colour = float4(1,1,1,1);
00127         // Fog 
00128         // f = 1 / e ^ (camz x density)
00129         // note pow = exp(src1 * log(src0)).
00130         fog = 1 / (exp((oPosition.z * fogDensity) * log(2.718281828)));
00131     }
00132 
00133 
00134     // Exp2 fogged morphing terrain
00135     void terrain_vp_exp2(
00136         float4 position : POSITION,
00137         float2 uv1      : TEXCOORD0,
00138         float2 uv2      : TEXCOORD1,
00139         float delta     : BLENDWEIGHT,
00140 
00141         out float4 oPosition : POSITION,
00142         out float2 oUv1      : TEXCOORD0,
00143         out float2 oUv2      : TEXCOORD1,
00144         out float4 colour    : COLOR,
00145         out float fog        : FOG,
00146         uniform float4x4 worldViewProj,
00147         uniform float morphFactor,
00148         uniform float fogDensity)
00149     {
00150         // Apply morph
00151         position.y = position.y + (delta.x * morphFactor);
00152         // world / view / projection
00153         oPosition = mul(worldViewProj, position);
00154         // Main texture coords
00155         oUv1 = uv1;
00156         // Detail texture coords
00157         oUv2 = uv2;
00158         // Full bright (no lighting)
00159         colour = float4(1,1,1,1);
00160         // Fog 
00161         // f = 1 / e ^ (camz x density)^2
00162         // note pow = exp(src1 * log(src0)).
00163         float src1 = oPosition.z * 0.002;
00164         fog = 1 / (exp((src1*src1) * log(2.718281828f)));
00165     }
00166 
00167     // Shadow receiver vertex program
00168     void terrain_shadow_receiver_vp(
00169         float4 position : POSITION,
00170         float2 uv1      : TEXCOORD0,
00171         float2 uv2      : TEXCOORD1,
00172         float delta     : BLENDWEIGHT,
00173 
00174         out float4 oPosition : POSITION,
00175         out float2 oUv1      : TEXCOORD0,
00176         out float4 colour    : COLOR,
00177         uniform float4x4 worldViewProj,
00178         uniform float4x4 world,
00179         uniform float4x4 textureViewProj,
00180         uniform float morphFactor
00181         )
00182     {
00183         // Apply morph
00184         position.y = position.y + (delta.x * morphFactor);
00185         // world / view / projection
00186         oPosition = mul(worldViewProj, position);
00187         
00188         // Main texture coords
00189         float4 worldpos = mul(world, position);
00190         float4 projuv = mul(textureViewProj, worldpos);
00191         oUv1.xy = projuv.xy / projuv.w;
00192         // Full bright (no lighting)
00193         colour = float4(1,1,1,1);
00194     }
00195 
00196     @endcode
00197     */
00198     class TerrainVertexProgram
00199     {
00200     private:
00201         static String mNoFogArbvp1;
00202         static String mLinearFogArbvp1;
00203         static String mExpFogArbvp1;
00204         static String mExp2FogArbvp1;
00205         static String mShadowReceiverArbvp1;
00206 
00207         static String mNoFogVs_1_1;
00208         static String mLinearFogVs_1_1;
00209         static String mExpFogVs_1_1;
00210         static String mExp2FogVs_1_1;
00211         static String mShadowReceiverVs_1_1;
00212 
00213     public:
00215         static const String& getProgramSource(FogMode fogMode, 
00216             const String syntax, bool shadowReceiver = false);
00217 
00218 
00219     };
00220 }
00221 
00222 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:53 2006