当前位置: 首页 > ops >正文

GPU Gems1-Effective Water Simulation from Physical Models

Chapter 1. Effective Water Simulation from Physical Models | NVIDIA Developer

Game-Programmer-Study-Notes/Content/《GPU Gems 1》全书提炼总结/README.md at master · QianMo/Game-Programmer-Study-Notes · GitHub

这里主要是看上面的内容,我主要写一下我的疑惑点:

首先是下面的方程3,我认为这就是说多个正弦函数叠加近似得到的高度场函数。

UE实现

我们主要关注,法线和位置的偏移

普通的正弦波

普通的正弦波,也就是高度上z的偏移以及法线的变换

WaveLength
Speed
time
direction
aPos_xy
amplitudestruct MyFunction
{float3 calculateNormal(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy){float3 normal = float3(0, 0, 1);float w = 2 / WaveLength;float phi = Speed * w;float x = -1.0f * amplitude * w * direction.x * cos(dot(direction, aPos_xy) * w +time * phi);float y = -1.0f * amplitude * w * direction.y * cos(dot(direction, aPos_xy) * w +time * phi);normal.x = x;normal.y = y;return normal;}float3 calculateGerstner(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy,float Q){float3 res = float3(0, 0, 0);float w = 2 / WaveLength;float phi = Speed * w;float x = Q * amplitude * direction.x * cos(w * dot(direction, aPos_xy) + time * phi);float y = Q * amplitude * direction.y * cos(w * dot(direction, aPos_xy) + time * phi);float z = amplitude * sin(w * dot(direction, aPos_xy) + time * phi);res.x = x;res.y = y;res.z = z;return res;}float calculateHeight(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy){float w = 2 / WaveLength;float phi = Speed * w;float z = amplitude * sin(w * dot(direction, aPos_xy) + time * phi);return z;}
} myFun;
float3 loc = float3(0, 0, 0);
float2 seed = float2(123.456, 789.012);
normal = float3(0, 0, 1);
for(int i = 0; i < 3; i++)
{seed = frac(seed * 123.456);float amplitude = A_min + (A_max - A_min) * seed.x;float WaveLength = WaveLength_min + (WaveLength_max - WaveLength_min) * seed.x;float Speed = Speed_min + (Speed_max - Speed_min) * seed.x;float2 direction = normalize(float2(seed.x, seed.y));normal += myFun.calculateNormal(amplitude, WaveLength, Speed, time, direction, aPos_xy);normal.z = 1.0;loc.z += myFun.calculateHeight(amplitude, WaveLength, Speed, time, direction, aPos_xy);
}
normal = normalize(normal);
return loc;

Geometric Waves

Directional or Circular

WaveLength
Speed
time
direction
aPos_xy
amplitudestruct MyFunction
{float3 calculateNormal(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy){float3 normal = float3(0, 0, 1);float w = 2 / WaveLength;float phi = Speed * w;float x = -1.0f * amplitude * w * direction.x * cos(dot(direction, aPos_xy) * w +time * phi);float y = -1.0f * amplitude * w * direction.y * cos(dot(direction, aPos_xy) * w +time * phi);normal.x = x;normal.y = y;return normal;}float3 calculateGerstner(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy,float Q){float3 res = float3(0, 0, 0);float w = 2 / WaveLength;float phi = Speed * w;float x = Q * amplitude * direction.x * cos(w * dot(direction, aPos_xy) + time * phi);float y = Q * amplitude * direction.y * cos(w * dot(direction, aPos_xy) + time * phi);float z = amplitude * sin(w * dot(direction, aPos_xy) + time * phi);res.x = x;res.y = y;res.z = z;return res;}float calculateHeight(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy){float w = 2 / WaveLength;float phi = Speed * w;float z = amplitude * sin(w * dot(direction, aPos_xy) + time * phi);return z;}
} myFun;
float3 loc = float3(0, 0, 0);
float2 seed = float2(123.456, 789.012);
normal = float3(0, 0, 1);
for(int i = 0; i < 3; i++)
{seed = frac(seed * 123.456);float amplitude = A_min + (A_max - A_min) * seed.x;float WaveLength = WaveLength_min + (WaveLength_max - WaveLength_min) * seed.x;float Speed = Speed_min + (Speed_max - Speed_min) * seed.x;float2 direction = normalize(aPos_xy);normal += myFun.calculateNormal(amplitude, WaveLength, Speed, time, direction, aPos_xy);normal.z = 1.0;loc.z += myFun.calculateHeight(amplitude, WaveLength, Speed, time, direction, aPos_xy);
}
normal = normalize(normal);
return loc;

Gerstner Waves

struct MyFunction
{float3 calculateNormal(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy,float Q){float3 normal = float3(0, 0, 1);float w = 2 / WaveLength;float WA = w * amplitude;float phi = Speed * w;float S = sin(w * dot(direction, aPos_xy) + time * phi);float C = cos(w * dot(direction, aPos_xy) + time * phi);float x = - WA * direction.x * C;float y = - WA * direction.y * C;float z = - WA * S * Q;normal.x = x;normal.x = x;normal.y = y;return normal;}float3 calculateGerstner(float amplitude,float WaveLength,float Speed,float time,float2 direction,float2 aPos_xy,float Q){float3 res = float3(0, 0, 0);float w = 2 / WaveLength;float phi = Speed * w;float x = Q * amplitude * direction.x * cos(w * dot(direction, aPos_xy) + time * phi);float y = Q * amplitude * direction.y * cos(w * dot(direction, aPos_xy) + time * phi);float z = amplitude * sin(w * dot(direction, aPos_xy) + time * phi);res.x = x;res.y = y;res.z = z;return res;}
} myFun;
float3 loc = float3(0, 0, 0);
float2 seed = float2(123.456, 789.012);
normal = float3(0, 0, 1);
for(int i = 0; i < 3; i++)
{seed = frac(seed * 123.456);float amplitude = A_min + (A_max - A_min) * seed.x;float WaveLength = WaveLength_min + (WaveLength_max - WaveLength_min) * seed.x;float Speed = Speed_min + (Speed_max - Speed_min) * seed.x;float2 direction = normalize(float2(seed.x, seed.y));float Q = Q_min + (Q_max - Q_min) * seed.x;normal += myFun.calculateNormal(amplitude, WaveLength, Speed, time, direction, aPos_xy, Q);loc += myFun.calculateGerstner(amplitude, WaveLength, Speed, time, direction, aPos_xy, Q);
}
normal = normalize(normal);
return loc;

http://www.xdnf.cn/news/5461.html

相关文章:

  • RHCSA Linux系统 Web页面 论坛 网盘的搭建
  • 沈燕谈艺:把现代科学基因融入古典笔墨中
  • OrangePi Zero 3学习笔记(Android篇)6 - hid-ft260
  • Redis设计与实现——单机Redis实现
  • 光线传感器BH1750
  • springboot3学习
  • 部署Superset BI(五)连接oracle数据库失败
  • LangChain入门(七) 提取和输出结构化数据
  • 【计算机视觉】基于深度学习的实时情绪检测系统:emotion-detection项目深度解析
  • Day116 | 灵神 | 二叉树 | 二叉搜索树中第K小的元素
  • 软件测试复习第五章
  • 利用类型别名定义复杂联合类型和交叉类型
  • cheat engine: Scan error no readable memory found
  • 学习通刷课稳定版(美化面板+完全免费)
  • 【RP2350】香瓜树莓派RP2350之新建工程
  • JAVA 锁—— synchronized
  • linux 三剑客命令学习
  • C++基本知识 —— 缺省参数·函数重载·引用
  • 蓝桥杯14届国赛 合并数列
  • 【Python 算法零基础 2.模拟 ⑤ 基于栈和队列】
  • 【JEECG 组件扩展】JSwitch开关组件扩展单个多选框样式
  • 【AI智能推荐系统】第八篇:可解释AI在推荐系统中的实践与价值
  • 深度优先与广度优先:如何用算法思维优化学习策略?
  • 250510-Linux离线配置N8N环境+屏蔽外网请求
  • python使用AES进行加密和解密
  • JavaSE基础
  • python: 为项目创建单独的虚拟环境步骤
  • QSS样式表的选择器
  • 蓝牙RFCOMM协议概述
  • 第二十一节:图像金字塔-高斯金字塔