看了海洋的例子之后,我们知道其实水的效果关键就在于材质中各个属性的调节。所以我就以例子中的材质制做了一个可以加载和保存的水编辑器。
另外通过修改HLSL文件和material文件加上了透明度调节。
要修改的部分为:
PS声明:
fragment_program HLSL/Ocean2FS hlsl
{
source Ocean2HLSL_Cg.frag
entry_point main
target ps_2_0
default_params
{
param_named vertexcolor float4 1.0 1.0 1.0 1.0
}
}
材质中的定义
fragment_program_ref HLSL/Ocean2FS
{
param_named deepColor float4 0 0.3 0.5 1.0
param_named shallowColor float4 0 1 1 1.0
param_named reflectionColor float4 0.95 1 1 1.0
param_named reflectionAmount float 1.0
param_named reflectionBlur float 0.0
param_named waterAmount float 0.3
param_named fresnelPower float 5.0
param_named fresnelBias float 0.328
param_named hdrMultiplier float 0.471
param_named_auto vertexcolor custom 1
}
Ocean2HLSL_Cg.frag
/*********************************************************************NVMH3****
Copyright NVIDIA Corporation 2003
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Comments:
Simple ocean shader with animated bump map and geometric waves
Based partly on "Effective Water Simulation From Physical Models", GPU Gems
11 Aug 05: heavily modified by Jeff Doyle (nfz) for Ogre
******************************************************************************/
struct v2f {
float4 Position : POSITION; // in clip space
float3 rotMatrix1 : TEXCOORD0; // first row of the 3x3 transform from tangent to obj space
float3 rotMatrix2 : TEXCOORD1; // second row of the 3x3 transform from tangent to obj space
float3 rotMatrix3 : TEXCOORD2; // third row of the 3x3 transform from tangent to obj space
float2 bumpCoord0 : TEXCOORD3;
float2 bumpCoord1 : TEXCOORD4;
float2 bumpCoord2 : TEXCOORD5;
float3 eyeVector : TEXCOORD6;
};
float4 main(v2f IN,
uniform sampler2D NormalMap,
uniform samplerCUBE EnvironmentMap,
uniform float4 deepColor,
uniform float4 shallowColor,
uniform float4 reflectionColor,
uniform float reflectionAmount,
uniform float reflectionBlur,
uniform float waterAmount,
uniform float fresnelPower,
uniform float fresnelBias,
uniform float hdrMultiplier,
uniform float4 vertexcolor
) : COLOR
{
// sum normal maps
// sample from 3 different points so no texture repetition is noticeable
float4 t0 = tex2D(NormalMap, IN.bumpCoord0) * 2.0 - 1.0;
float4 t1 = tex2D(NormalMap, IN.bumpCoord1) * 2.0 - 1.0;
float4 t2 = tex2D(NormalMap, IN.bumpCoord2) * 2.0 - 1.0;
float3 N = t0.xyz + t1.xyz + t2.xyz;
float3x3 m; // tangent to world matrix
m[0] = IN.rotMatrix1;
m[1] = IN.rotMatrix2;
m[2] = IN.rotMatrix3;
N = normalize( mul( N, m ) );
// reflection
float3 E = normalize(IN.eyeVector);
float4 R;
R.xyz = reflect(E, N);
// Ogre conversion for cube map lookup
R.z = -R.z;
R.w = reflectionBlur;
float4 reflection = texCUBEbias(EnvironmentMap, R);
// cheap hdr effect
reflection.rgb *= (reflection.r + reflection.g + reflection.b) * hdrMultiplier;
// fresnel
float facing = 1.0 - max(dot(-E, N), 0);
float fresnel = saturate(fresnelBias + pow(facing, fresnelPower));
float4 waterColor = lerp(shallowColor, deepColor, facing) * waterAmount;
reflection = lerp(waterColor, reflection * reflectionColor, fresnel) * reflectionAmount;
return (waterColor + reflection)*vertexcolor;
}
分享到:
相关推荐
ogre的海洋效果的编辑器,带有全部源代码,效果和速度都很不错.值得用一下啊
ogre开发的简单场景编辑器 xgEditorogre开发的简单场景编辑器 xgEditor
ogre 场景 编辑器
ogre材质编辑器OgreMaterialEditorogre材质编辑器OgreMaterialEditor
OGRE粒子编辑器.rar。OGRE粒子编辑器。特效编辑器。
Ogre3D场景编辑器,自制软件开源,使用Ogre 3D渲染引擎
自制软件开源,使用Ogre 3D渲染引擎,BCG界面库。
ogre地图编辑器EchoChamber 天气caelum 地形ETM 分页pagedgeometry 海水hydrax
ogre 海水编辑器.可以自己编辑应用到OGR游戏引擎的各种海水特效
采用ogre开发的场景编辑器,用c#做的界面。键盘的asdf和方向键可以控制照相机的走动。 交互性的实时3D地形编辑和生成工具。从简单的游戏阶段到大规模的户外环境,你都可以任意创作。owEditor并不需要你用大量的时间...
Ogre 3D Beginners Guide 例子中的代码。
ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水ogre水
c# 实现的OGRE场景编辑器 OgreStudio
自己参照flyingpig做的地图编辑器,里面只有一个mesh,可以自己用ogremax exporter 导出mesh添加到编辑器的model和material文件夹里进行扩充. 源码会在我的博客里进行开发式的展示 一个问题。。。缺少一个DLL,...
Ogre开发的一个小例子,有些美术资源,不过没源码哦,可以看看
ogre经典例子 magicofstonehenge ogre1.72 + vs2008修改版,修改过程见里面胡说明.txt
ogre粒子编写器ParticleEditorogre粒子编写器ParticleEditor
基于OGRE开发的一个小场景编辑器tecnofreak_editor
OGRE(Object-Oriented Graphics Rendering Engine,即:面向对象图形渲染引擎)是一个用C++开发的面向场景、非常灵活的3D引擎,它旨在让开发人员更容易、更直接地利用硬件加速的3D图形系统开发应用。这个类库隐藏了...
ogre和qt相结合的例子。可以相应鼠标和qt的按钮。并可以动态调整shader的参数。