作者:手机用户2602885631_316 | 来源:互联网 | 2023-07-19 12:56
以前游戏水面的做法都是用很多张图的序列帧实现的纹理动画,这种固定渲染管线的方式,在最低画质的时候采用特别好,但是对于更高级别的画质,就应该采用更好效果的水面。水面渲染,Ogre有个插
以前游戏水面的做法都是用很多张图的序列帧实现的纹理动画,这种固定渲染管线的方式,在最低画质的时候采用特别好,但是对于更高级别的画质,就应该采用更好效果的水面。
水面渲染,Ogre有个插件叫Hydrax,效果很不错,但是效率也低的很,没任何实用价值。只好自己做一个。
一个漂亮3D游戏水面的,一般有水波模拟,bump mapping,倒影,折射,菲捏尔效果,水下效果等,我准备做一些取舍,实现高效率。
1)只保留倒影,去掉折射,菲捏尔效果,水下效果,因为2.5D游戏,视角比较固定,也不需要深入到水下。
2)优化倒影的RTT渲染,手动选择哪些物体需要产生倒影,这样就极大减少渲染批次。
3)bump mapping采用法线贴图方式,计算水面光照。
4)水波模拟适合大海,要和不要关系不大,不同位置的多次采样保证了水纹的流动。
5)用浮点处理水深,提高精度,水深过渡自然。
效果比较满意,水深过渡自然,海水颜色,流动方向,纹理大小等可以动态调节,而且效率上很高,只增加了一个倒影的RTT开销,也不需要美术提供海水图片,shader计算也不复杂。
material FresnelReflectionRefraction
{
// 一个pass
technique
{
pass
{
diffuse 0.5 0.5 0.5
specular 1 1 1 512
scene_blend alpha_blend
depth_write off
vertex_program_ref FresnelRefractReflectVP
{
param_named_auto worldViewProjMatrix worldviewproj_matrix
param_named_auto eyePosition camera_position_object_space
param_named_auto lightPosition1 light_position_object_space 1
param_named BumpScale float 0.35
param_named textureScale float2 1 1
param_named bumpSpeed float2 -0.025 0.025
param_named_auto time time_0_x 100.0
param_named waveFreq float 0.028
param_named waveAmp float 1.8
}
fragment_program_ref FresnelRefractReflectFP
{
param_named_auto ambient ambient_light_colour
param_named_auto diffuseParameters surface_diffuse_colour
param_named_auto specularParameters surface_specular_colour
param_named waterColor float4 0 0.6 0.7 1.0
}
// Noise
texture_unit
{
// Perlin noise volume
texture waves.dds
// min / mag filtering, no mip
filtering linear linear none
}
// Reflection
texture_unit Reflection
{
// Will be filled in at runtime
texture Reflection
tex_address_mode clamp
}
}
}
// 2 个 pass, 高光单独计算不受水深影响, 但高光没法被雾遮挡
technique
{
pass
{
scene_blend alpha_blend
depth_check on
depth_write off
vertex_program_ref FresnelRefractReflectVP
{
param_named_auto worldViewProjMatrix worldviewproj_matrix
param_named_auto eyePosition camera_position_object_space
param_named_auto lightPosition1 light_position_object_space 1
param_named BumpScale float 0.2
param_named textureScale float2 1 1
param_named bumpSpeed float2 -0.04 0.04
param_named_auto time time_0_x 100.0
param_named waveFreq float 0.028
param_named waveAmp float 1.8
}
fragment_program_ref FresnelRefractReflectFP_NoSpecular
{
param_named_auto ambient ambient_light_colour
param_named deepColor float4 0 0.3 0.5 1.0
param_named shallowColor float4 0 1 1 1.0
param_named reflectionAmount float 1.0
param_named waterAmount float 0.2
}
// Noise
texture_unit
{
// Perlin noise volume
texture waves.dds
// min / mag filtering, no mip
filtering linear linear none
}
// Reflection
texture_unit Reflection
{
// Will be filled in at runtime
texture Reflection
tex_address_mode clamp
}
}
// 高光单独计算,不受水深影响
pass
{
specular 1 1 1 512
scene_blend add
depth_write off
fog_override true
vertex_program_ref FresnelRefractReflectVP
{
param_named_auto worldViewProjMatrix worldviewproj_matrix
param_named_auto eyePosition camera_position_object_space
param_named_auto lightPosition1 light_position_object_space 1
param_named BumpScale float 0.2
param_named textureScale float2 1 1
param_named bumpSpeed float2 -0.04 0.04
param_named_auto time time_0_x 100.0
param_named waveFreq float 0.028
param_named waveAmp float 1.8
}
fragment_program_ref FresnelRefractReflectFP_Specular
{
param_named_auto specularParameters surface_specular_colour
}
// Noise
texture_unit
{
// Perlin noise volume
texture waves.dds
// min / mag filtering, no mip
filtering linear linear none
}
}
}
// 固定管线
technique
{
pass
{
ambient 0.588235 0.588235 0.588235 1
diffuse 0.588235 0.588235 0.588235 1
specular 0.9 0.9 0.9 20
scene_blend alpha_blend
depth_check on
depth_write off
texture_unit
{
anim_texture jpg_海湖水.dds 28 2
}
texture_unit
{
texture water_depth.tga 1d
colour_op_ex source1 src_current src_texture
colour_op_multipass_fallback one zero
alpha_op_ex modulate src_current src_texture
tex_coord_set 1
tex_address_mode clamp
filtering none none none
}
}
}
}