如何在 Scenekit 中设置雾气遵循一条曲线?

问题描述 投票:-1回答:1

我想让 Scenekit 中的雾从起始距离到结束距离遵循一条曲线,而不是让它呈线性。这就是雾状距离图的样子。

enter image description here

有什么办法可以创建这样一条按体积存储的雾气不透明度曲线?

我知道你可以将密度曲线设置成指数二次方程,也试过,但我也想做出这种类型的曲线。

我试着改变了 fogStartDistancefogEndDistance 但效果并不正确。

ios swift xcode sprite-kit scenekit
1个回答
0
投票

这里是我拥有的一个Metal着色器的一个片段,它执行了一个 "标准 "的雾的外观和感觉。它是在MetalKit场景中使用的,所以在SceneKit中也应该可以使用,但你必须想办法把它注入到场景中。上面提到的碎片着色器将是一个很好的开始寻找的地方。

// Metal Shader Language
float4 fog(float4 position, float4 color){
    float distance = position.z / position.w;
    float density = 0.5;

// the line that does the exponential falloff of the fog as we get closer to camera
    float fog = 1.0 - clamp(exp(-density * distance), 0.0, 1.0);

// the color you want the fog to be
    float4 fogColor = float4(1.0);
    color = mix(color, fogColor, fog);
    return color;
}

我希望这能帮到你


0
投票

您可以使用自定义的 片段着色器修改器 来实现你自己的曲线。


0
投票

这绝对可以做到,但你必须自己实现雾化,因为雾化只是保存出来的ZDepth,然后在最后的渲染通道上乘以。

你可以将你的曲线建模为nurbshermite曲线或方程,然后沿曲线取样点。

Hermite有一个从0到1的时间(范围从0到1),这将对应于ZDepth值[0在摄像机处,1在最远处]。

沿着Hermite(范围0和1之间)的采样点(可以是任何值,取决于你如何建模曲线)将被乘以ZDepth值。

FogStartDistance和FogEndDistance在距离上做线性倍数,可惜你只能指定混合的指数。

© www.soinside.com 2019 - 2024. All rights reserved.