大佬教程收集整理的这篇文章主要介绍了在 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,请注明来意。