游戏开发论坛

 找回密码
 立即注册
搜索
查看: 10234|回复: 2

Away3D之--水面效果

[复制链接]

17

主题

44

帖子

271

积分

中级会员

Rank: 3Rank: 3

积分
271
发表于 2015-1-24 15:56:56 | 显示全部楼层 |阅读模式
一. 水面效果:

实现水面效果的原理很简单,只需将水平面绘制作为一个平面,用环境贴图模拟水对环境的反射,同时为水平面增加法线效果模拟水面波光粼粼的效果即可。

具体代码如下:

使用SimpleWaterNormalMethod方法(该方法实际是使用两张法线贴图叠加作为最终法线进而计算发射)绘制该平面的反射效果即可。




二. 利用PixelBender实现水面互动:

PixelBender一般用于实现滤镜或者一些其他的渲染效果,在此可以利用pixelbender计算平面顶点位置信息实现水面的波动效果。

  由于pixelBender的输入参数是三维数据,我们将平面换分为w行l列以该点高度h作为第三维数据,高度默认为0.通过当前帧上一帧等数据计算高度h.   PixelBender代码如下:

void
    evaluatePixel()
    {
float2 coord = outCoord();
float3 point = sampleNearest(currentBuffer, coord);


if(coord.x > 1.0 && coord.y > 1.0 && coord.x < dims.x && coord.y < dims.y)
{
            float3 prev = sampleNearest(previousBuffer, coord);
            float3 right = sampleNearest(currentBuffer, coord + float2(1.0, 0.0));
            float3 left = sampleNearest(currentBuffer, coord + float2(-1.0, 0.0));
            float3 top = sampleNearest(currentBuffer, coord + float2(0.0, -1.0));
            float3 bottom = sampleNearest(currentBuffer, coord + float2(0.0, 1.0));


            dst.z = k1*point.z + k2*prev.z + k3*(right.z + left.z + top.z + bottom.z);
        }
        else
        {
            dst.z = 0.0;
        }


dst.x = point.x;
dst.y = point.y;
    }

通过没帧对高度的计算实现波浪效果。



具体代码: git@code.csdn.net:u012966744/flashgame.git



0

主题

243

帖子

357

积分

中级会员

Rank: 3Rank: 3

积分
357
发表于 2015-2-3 21:33:23 | 显示全部楼层
这论坛的技术贴已经绝迹了,回复鼓励一下,好吧,我承认其实我是被图上那只喵星人逗乐了才回的。。。

0

主题

2

帖子

28

积分

新手上路

Rank: 1

积分
28
发表于 2015-2-9 09:47:16 | 显示全部楼层
DeALLBugs 发表于 2015-2-3 21:33
这论坛的技术贴已经绝迹了,回复鼓励一下,好吧,我承认其实我是被图上那只喵星人逗乐了才回的。。。 ...

明显是熊
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-10-9 01:00

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表