程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在 Metal, Swift 中为一个点设置圆形大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在 Metal, Swift 中为一个点设置圆形?

开发过程中遇到在 Metal, Swift 中为一个点设置圆形的问题如何解决?下面主要结合日常开发的经验,给出你关于在 Metal, Swift 中为一个点设置圆形的解决方法建议,希望对你解决在 Metal, Swift 中为一个点设置圆形有所启发或帮助;

我正在使用 Metal 创建动画。

Now it looks like this。

I want the shape of every point to be round like this

这是我当前的着色器代码:

struct VertexOut {
  float4 position [[position]];
  float pointSize [[point_size]];
};

struct Uniforms {
  float4x4 ndcMatrix;
  float ptmRatio;
  float pointSize;
};

vertex VertexOut vertex_shader(const device packed_float2 * vertex_array [[buffer(0)]],const device Uniforms& uniforms [[buffer(1)]],unsigned int vID [[vertex_ID]]) {
    VertexOut vertexOut;
    float2 position = vertex_array[vID];
    vertexOut.position = uniforms.ndcMatrix * float4(position.x * uniforms.ptmRatio,position.y * uniforms.ptmRatio * 1.5,1);
    vertexOut.pointSize = uniforms.pointSize * 1.5;
    return vertexOut;
}

fragment half4 fragment_shader(VertexOut fragData [[stage_in]],float2 pointCoord [[point_coord]]) {
    return half4(0.3,0.3,0.1,0.1);
}

之前,我已经使用片段着色器实现了想要的效果。我的代码是:

fragment half4 fragment_shader(VertexOut fragData [[stage_in]],float2 pointCoord [[point_coord]]) {
    float dist = length(pointCoord - float2(0.4));
    float4 color = fragData.color;
    // Marking particles round shaped
    color.a = 1.0 - smoothstep(0.4,0.4,dist);
    // Setting yellow color
    color.b = (0.3,0.1);
    return half4(color);
}

它在形状方面效果很好,但没有提供所需的颜色效果。所以我需要找到另一种方法来正确设置颜色和形状。

我尝试设置两个单独的片段函数,一个用于形状,一个用于颜色,然后将它们传递给 Pipelinestate,但没有奏效。

感谢任何帮助!

解决方法

我已经用一个函数解决了:

.custom-class-or-id:after {
    content: none !important;
}

大佬总结

以上是大佬教程为你收集整理的在 Metal, Swift 中为一个点设置圆形全部内容,希望文章能够帮你解决在 Metal, Swift 中为一个点设置圆形所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: