I'll preface this by saying that this is my first time ever touching shader code so I'm sure there will be plenty wrong with my wording.
I'm working on a SpriteKit game and want to be able to generate sprites instead of manually creating/changing/adding assets. My idea was to have a "base" asset, make note of all the different colors that exist within the asset, then programmatically create uniforms representing both the asset's colors and the colors that I want to replace them with. From there, my shader could compare each rgb value with the uniforms representing the asset's colors and determine which color to replace it with. Essentially, I'm building a mapping from old colors to new colors and performing a color swap.
This works fine, as long as I use less than 30 uniforms in my "mapping." When I exceed 30, I get the following error (note that the "u_base_" and "u_new_" names are my generated uniforms):
program_source:49:1883: error: 'buffer' attribute parameter is out of bounds: must be between 0 and 30 fragment float4 SKShader_FragFunc( texture2d u_texture [[texture(0)]], const device float *u_time [[buffer(0)]], const device float *u_path_length [[buffer(1)]], const device float4 * u_base_skinDark [[buffer(2)]],const device float4 * u_base_eyesColor [[buffer(3)]],const device float4 * u_new_shirtMediumLight [[buffer(4)]],const device float4 * u_base_eyesDark [[buffer(5)]],const device float4 * u_new_shoes [[buffer(6)]],const device float4 * u_new_hairDark [[buffer(7)]],const device float4 * u_new_eyesWhite [[buffer(8)]],const device float4 * u_new_skinMediumDark [[buffer(9)]],const device float4 * u_base_skinMediumLight [[buffer(10)]],const device float2 * u_sprite_size [[buffer(11)]],const device float4 * u_base_shirtMediumLight [[buffer(12)]],const device float4 * u_new_eyesColor [[buffer(13)]],const device float4 * u_base_shirtDark [[buffer(14)]],const device float4 * u_base_shirtMediumDark [[buffer(15)]],const device float4 * u_new_hairMedium [[buffer(16)]],const device float4 * u_base_eyesBrow [[buffer(17)]],const device float4 * u_base_hairDark [[buffer(18)]],const device float4 * u_new_shirtMediumDark [[buffer(19)]],const device float4 * u_new_skinDark [[buffer(20)]],const device float4 * u_new_eyesDark [[buffer(21)]],const device float4 * u_new_eyesBrow [[buffer(22)]],const device float4 * u_new_hairLight [[buffer(23)]],const device float4 * u_new_skinLight [[buffer(24)]],const device float4 * u_base_skinLight [[buffer(25)]],const device float4 * u_new_skinMediumLight [[buffer(26)]],const device float4 * u_base_hairLight [[buffer(27)]],const device float4 * u_base_shoes [[buffer(28)]],const device float4 * u_base_eyesWhite [[buffer(29)]],const device float4 * u_new_shirtDark [[buffer(30)]],const device float4 * u_base_skinMediumDark [[buffer(31)]],const device float4 * u_base_hairMedium [[buffer(32)]], SKShader_VertexOut interpolated [[stage_in]]) {
I've found almost no references to the error message so finding a fix has been difficult. I've since discovered that this isn't really the right way to use shaders since these types of comparisons aren't very performant, but I'd still like to understand the error. Is there anyway to increase the size of this buffer? Is this just a limitation of SpriteKit? Also, is the only way to accomplish this color swap by using a "swap texture"?