在虚幻引擎中使用 Niagara 的平滑粒子流体动力学

如何解决在虚幻引擎中使用 Niagara 的平滑粒子流体动力学

这将是一个很长的帖子,抱歉,但我认为这是值得的,因为它非常复杂,我想很多其他人真的很想能够达到这种效果。这里还有一些关于 SPH 的其他问题,但没有一个与 Niagara 实施有关。我也在 Unreal Engine Answers 上发布了这个问题。

我一直在尝试在 Niagara 中复制流体模拟,如 Asher Zhu 所示:The Art of Illusion - Niagara Simulation Framework Overview。跳到 20:25 以获得我想要的效果。

看到他从渲染它的一些位(就我尚未得到的部分)中根本没有展示 Niagara 系统的任何部分,我遵循了此处的文章:link

现在,我让它看起来或多或少像一种液体。然而,它看起来并不像亚瑟的。它相当不稳定,在爆炸然后安定下来之前,往往会在密度较高的区域停留几秒钟。它也永远不会发展任何深度。所有粒子,除非它们不规则地飞来飞去,否则都坐在地板上。另一个问题是碰撞——我看不出 Asher 是如何设法与环境发生如此干净的碰撞的。我的带符号距离场又大又圆且不均匀,粒子永远不会靠近墙壁。

下面的第四张图显示了它在到达第三张图后就爆炸了,第五张图是它最终稳定下来后的样子(以及粒子最终离墙壁多远)。最后一张图片显示它是完全平坦的(这不是盒子体积的问题;我已经测试过了)。

enter image description here

在这里很难显示 Niagara 系统中的所有内容,但关键是 HLSL 代码:

OutVelocity = Velocity;
OutPosition = Position;
Density = 0;
float Pressure = 0;

float smoothingRadius = 1.0f;
float restDensity = 0.2f;
float viscosity = 0.018f;
float gas = 500.0f;

const float3 gravity = float3(0,-98);
float pi = 3.141593;

int numParticles;
DirectReads.GetNumParticles(numParticles);

const float Poly6_constant = (315 / (64 * pi * pow(smoothingRadius,9)));
const float Spiky_constant = (-45 / (pi * pow(smoothingRadius,6)));

float3 forcePressure = float3(0,0);
float3 forceViscosity = float3(0,0);


#if GPU_SIMULATION

//Calculate the density of this particle based on the proximity of the other particles.
for (int i = 0; i < numParticles; ++i)
{
    bool myBool; //Temporary bool used to catch valid/invalid results for direct reads.

    float OtherMass;
    DirectReads.GetFloatByIndex<Attribute="Mass">(i,myBool,OtherMass);
    float3 OtherPosition;
    DirectReads.GetVectorByIndex<Attribute="Position">(i,OtherPosition);

    // Calculate the distance and direction between the target Particle and itself
    float distanceBetween = distance(OtherPosition,OutPosition);
    
    if (distanceBetween < smoothingRadius)
    {
        Density += OtherMass * Poly6_constant * pow(smoothingRadius - distanceBetween,3);
    }
}

//Avoid negative pressure by clamping density to reference value
Density = max(restDensity,Density);

//Calculate pressure
Pressure = gas * (Density - restDensity);

//Calculate the forces.
for (int i = 0; i < numParticles; ++i)
{
    if (i != InstanceId) //Only calculate the pressure-based force and Laplacian smoothing function if the other particle is not the current particle.)
    {
        bool myBool; //Temporary bool used to catch valid/invalid results for direct reads.

        float OtherMass;
        DirectReads.GetFloatByIndex<Attribute="Mass">(i,OtherMass);
        float OtherDensity;
        DirectReads.GetFloatByIndex<Attribute="Density">(i,OtherDensity);
        float3 OtherPosition;
        DirectReads.GetVectorByIndex<Attribute="Position">(i,OtherPosition);
        float3 OtherVelocity;
        DirectReads.GetVectorByIndex<Attribute="Velocity">(i,OtherVelocity);

        float3 direction = OutPosition - OtherPosition;
        float3 normalisedVector = normalize(direction);
        float distanceBetween = distance(OtherPosition,OutPosition);

        if (distanceBetween > 0 && distanceBetween < smoothingRadius) //distanceBetween must be >0 to avoide a div0 error.
        {
            float OtherPressure = gas * (OtherDensity - restDensity);

            //Calculate particle pressure.
            forcePressure += -1 * Mass * normalisedVector * (Pressure + OtherPressure) / (2 * Density * OtherDensity) * Spiky_constant * pow(smoothingRadius - distanceBetween,2);

            //Viscosity-based force computation with Laplacian smoothing function (W).
               const float W = -(pow(distanceBetween,3) / (2 * pow(smoothingRadius,3))) + (pow(distanceBetween,2) / pow(smoothingRadius,2)) + (smoothingRadius / (2 * distanceBetween)) - 1;
            forceViscosity += viscosity * (OtherMass / Mass) * (1 / OtherDensity) * (OtherVelocity - Velocity) * W * normalisedVector;
            //forceViscosity += viscosity * (OtherMass / Mass) * (1 / OtherDensity) * (OtherVelocity - Velocity) * (45 / (pi * pow(smoothingRadius,6))) * (smoothingRadius - distanceBetween);
        }
    }
}

OutVelocity += DeltaTime * ((forcePressure + forceViscosity) / Density);
OutPosition += DeltaTime * OutVelocity;
#endif

此代码对系统中的所有其他粒子执行两次循环,一次计算压力,另一次计算力。然后它输出速度和位置。就像我上面链接的文章一样,就像我看到的其他一些东西一样。然而,它的行为根本不像那些资源中显示的那样。

我没有应用任何基于网格的优化。为此,我将仅应用 UE 的内容示例项目中的 PBD 示例中使用的网格优化。但就目前而言,这是一个并不真正需要的额外复杂性。即使没有它,它也能在数千个粒子下运行良好。

我查看了一些资源(文章、视频和学术研究论文),并花了两周时间进行试验,包括对代码顶部的值进行反复试验。我显然错过了一些关键的东西。它可以是什么?我现在很沮丧,任何帮助都将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res