why is metal shader gradient lighter as a SCNProgram applied to a SceneKit Node than it is as a MTKView?

前端 未结 3 849
鱼传尺愫
鱼传尺愫 2020-12-05 21:43

I have a gradient, generated by a Metal fragment shader that I\'ve applied to a SCNNode defined by a plane geometry.

It looks like this:

When I use

3条回答
  •  [愿得一人]
    2020-12-05 22:22

    I'm not sure, but it looks to me like your calculation of the size of the node is off, leading your .uv to be off, depending on the position of the node.

    You have:

    int width = abs(scn_node.boundingBox[0].x) + abs(scn_node.boundingBox[1].x);
    int height = abs(scn_node.boundingBox[0].y) + abs(scn_node.boundingBox[1].y);
    

    I would think that should be:

    int width = abs(scn_node.boundingBox[0].x - scn_node.boundingBox[1].x);
    int height = abs(scn_node.boundingBox[0].y - scn_node.boundingBox[1].y);
    

    You want the absolute difference between the two extremes, not the sum. The sum gets larger as the node moves right and down, because it effectively includes the position.

    All of that said, isn't the desired (u, v) already provided to you in in.texCoords?

提交回复
热议问题