Hi everyone,
Running Xcode 12, I'm developing a standalone WatchOS App using Spritekit.
I'm using a simple Palette-swap shader using a SKShader with several SKAttributes.
The shader seems to work fine, however I get the following message in the console: [Metal Compiler Warning] Warning: Compilation succeeded with:
program_source:3:19: warning: unused variable 's'
constexpr sampler s(coord::normalized,
I have no idea what this means, there is no variable 's' in my code so I guess this is an issue because GLGS shader code gets compiled to Metal in the background and it goes wrong there? How do I verify this? It seems there is a memory leak associated with this error so I'm prone to solve it. Any help would be appreciated, even if it's just pointing me in a direction. (Like, should I write a new palette shader in Metal?) Thanks in advance!
The function that adds the SKShader (an extension to SKSpriteNode):
func addMultiColorShader(strokeColor: UIColor, colors:[UIColor]) {
let useColors:[UIColor] = shaderColors(colors)
var attributes:[SKAttribute] = [SKAttribute(name: "a_size", type: .vectorFloat2),
SKAttribute(name: "a_scale", type: .vectorFloat2),
SKAttribute(name: "a_alpha", type: .float)]
let colorNames:[String] = ["a_color0","a_color1","a_color2","a_color3"]
for i in 0..<colorNames.count {
attributes += [SKAttribute(name: colorNames[i], type: .vectorFloat4)]
}
let shader = SKShader(fromFile: "SKHMultiColorize", attributes: attributes)
setShaderAttributes(size: self.size, scale: CGSize(width: self.xScale, height: self.yScale), alpha: self.alpha)
setShaderColors(strokeColor: strokeColor, color1: useColors[0], color2: useColors[1], color3: useColors[2])
self.shader = shader
}
The actual shader code (OpenGL GS):
vec2 nearestNeighbor(vec2 loc, vec2 size) {
vec2 onePixel = vec2(1.0, 1.0) / size;
vec2 coordinate = floor(loc * size) / size; // round
return coordinate + (onePixel * 0.5);
}
void main()
{
vec4 colors[4];
colors[0] = a_color0;
colors[1] = a_color1;
colors[2] = a_color2;
colors[3] = a_color3;
vec4 currentColor = texture2D(u_texture, nearestNeighbor(v_tex_coord, a_size));
int colorIndex = int((currentColor.r * 5.1));
vec4 refColor = colors[colorIndex];
gl_FragColor = refColor * currentColor.a;
}