iOS、RealityKit、金属着色器 API。确定片段距相机的距离

发布于 2025-01-18 01:30:19 字数 1086 浏览 1 评论 0原文

使用新的 Metal Custom Shader API,我创建了随时间移动的草模型。

有没有办法确定模型片段和相机之间的距离?

我尝试搜索surface_parameters.uniforms()

有一些潜在的属性,例如 model_to_viewprojection_to_view 但我不知道该怎么做。

任何提示表示赞赏。

编辑:: 这是grasGreenShader 的代码

[[visible]]
void grassGreenShader(realitykit::surface_parameters params)
{
    params.surface().set_base_color(half3(0.094, 0.697, 0.088));
    params.surface().set_opacity(1);
    respondToCameraDistanceShader(params);
}

这是更改片段基色的代码。这部分是错误的:

void respondToCameraDistanceShader(realitykit::surface_parameters params)
{
    float3 distanceToCamera = params.geometry().world_position();
    
    if (distanceToCamera.z < 0.3 && distanceToCamera.z > -0.3)
    {
        params.surface().set_opacity(distanceToCamera.z);
        params.surface().set_base_color(half3(0.934, 0.902, 0.355));
    }
}

移动的草

Using the new Metal Custom Shader API, I've created Grass models that move over time.

Is there a way to determine the distance between the model's fragment and the camera?

I've tried to search through surface_parameters.uniforms().

There are a few potential properties such as model_to_view, projection_to_view but I don't know what to do further.

Any tips appreciated.

Edit:: Here is the code for the grassGreenShader

[[visible]]
void grassGreenShader(realitykit::surface_parameters params)
{
    params.surface().set_base_color(half3(0.094, 0.697, 0.088));
    params.surface().set_opacity(1);
    respondToCameraDistanceShader(params);
}

Here is the code to change the base colour of the fragment. This part is wrong:

void respondToCameraDistanceShader(realitykit::surface_parameters params)
{
    float3 distanceToCamera = params.geometry().world_position();
    
    if (distanceToCamera.z < 0.3 && distanceToCamera.z > -0.3)
    {
        params.surface().set_opacity(distanceToCamera.z);
        params.surface().set_base_color(half3(0.934, 0.902, 0.355));
    }
}

Moving grass

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文