Mr. Pie Guy
Mr. Pie Guy

Reputation: 119

Creating custom shaders with SpriteKit and Swift

For my game, I am trying to implement a custom shader that creates a zoom blur effect (I am quite new at using shaders so bear with me if I use improper terms). I have the .fsh shader file in my project, and I'm trying to apply it using SKShader.

I create the shader with this:

let testShader = SKShader(fileNamed: "ZoomBlur.fsh");

My shader takes two uniforms as input, blurCenter (vec2) and blurSize (float), so I try adding them to my shader:

testShader.addUniform(SKUniform(name: "blurSize", float: 50);

When trying to add blurCenter, there doesn't appear to be an initializer for a vec2, just float and texture. Looking at the class reference, it looks like I should be able to use this:

testShader.addUniform(SKUniform(name: "blurCenter", floatVector2: ...);

...But Xcode throws this error:

Incorrect argument label in call (have 'name:floatVector2:', expected 'name:float:')

How can I add a vec2 uniform? Am I completely missing something?

Upvotes: 0

Views: 1196

Answers (1)

rickster
rickster

Reputation: 126117

GLKVector2 is a union type, and Swift doesn't import those as of Beta 2. Any API that requires use of a non-imported type is itself not imported. Might not be a bad idea to file a bug.

For now, you'll need to work around this by writing your own C/ObjC functions/methods that forward to the non-imported API, and calling those from Swift via a bridging header.

Upvotes: 2

Related Questions