如何在 scenekit 中设置雾以跟随曲线?
How can I set fog in scenekit to follow a curve?
我试图让 Scenekit 中的雾从起始距离到结束距离遵循一条曲线,而不是让它成为线性的。这就是雾距离图的样子:
像这样创建体积存储的雾不透明度曲线的最佳方法是什么?
我知道你可以设置密度曲线来制作它exponential/quadratic,我也试过了,但我也想制作这种类型的曲线。
我尝试更改 fogStartDistance
和 fogEndDistance
但效果不正确。
您可以使用自定义 fragment shader modifier 来实现您自己的曲线。
这当然可以做到,但您必须自己实现雾,因为雾只是保存的 ZDepth,然后乘以最终渲染通道。
您可以将曲线建模为 nurbs/hermite 曲线或方程,然后沿曲线采样点。
Hermite有一个时间从0到1(范围从0到1),这将对应ZDepth值[0在相机,1在最远点]。
然后将沿 hermite(在范围 0 和 1 之间)的采样点(可以是任何值,具体取决于您如何对曲线建模)与 ZDepth 值相乘。
FogStartDistance 和 FogEndDistance 在距离上做线性倍数,遗憾的是你只能指定混合的指数。
这是我拥有的 Metal 着色器的片段,它执行 "standard" 雾的外观和感觉。它被用在 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;
}
希望对您有所帮助
我试图让 Scenekit 中的雾从起始距离到结束距离遵循一条曲线,而不是让它成为线性的。这就是雾距离图的样子:
像这样创建体积存储的雾不透明度曲线的最佳方法是什么?
我知道你可以设置密度曲线来制作它exponential/quadratic,我也试过了,但我也想制作这种类型的曲线。
我尝试更改 fogStartDistance
和 fogEndDistance
但效果不正确。
您可以使用自定义 fragment shader modifier 来实现您自己的曲线。
这当然可以做到,但您必须自己实现雾,因为雾只是保存的 ZDepth,然后乘以最终渲染通道。
您可以将曲线建模为 nurbs/hermite 曲线或方程,然后沿曲线采样点。
Hermite有一个时间从0到1(范围从0到1),这将对应ZDepth值[0在相机,1在最远点]。
然后将沿 hermite(在范围 0 和 1 之间)的采样点(可以是任何值,具体取决于您如何对曲线建模)与 ZDepth 值相乘。
FogStartDistance 和 FogEndDistance 在距离上做线性倍数,遗憾的是你只能指定混合的指数。
这是我拥有的 Metal 着色器的片段,它执行 "standard" 雾的外观和感觉。它被用在 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;
}
希望对您有所帮助