I am using a custom fragment shader to create a color gradient along the circular path of an SKShapeNode
. Here is the result:
What can I do, in SpriteKit or in the custom shader, to eliminate the aliasing?
P.S. I'll want this to work on watchOS as well.
Fragment shader:
void main() {
float normalizedPosition = v_path_distance / u_path_length;
gl_FragColor = vec4(normalizedPosition, normalizedPosition, normalizedPosition, 1.0);
}
ViewController:
import UIKit
import SpriteKit
class ViewController: UIViewController {
var skView: SKView {
return view as! SKView
}
var scene: SKScene!
override func viewDidLoad() {
super.viewDidLoad()
scene = SKScene(size: view.frame.size)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
skView.presentScene(scene)
// Create node
let ringNode = SKShapeNode(circleOfRadius: scene.size.width / 4)
ringNode.position = CGPoint(x: scene.frame.midX, y: scene.frame.midY)
ringNode.lineWidth = 30
// Apply shader
ringNode.strokeShader = SKShader(fileNamed: "fragment.fsh")
// Add node to scene
scene.addChild(ringNode)
}
}