Found a workaround. I can use SetSpriteAdditionalImage() to send information to the shader using the image as a type of 2D array. Only problem is that I would have to piece each component together if I need values outside of the 0.0-1.0 range. The performance is slightly slower than using SetShaderConstantByName, but far better than any of the other solutions I tried.
For those who are interested, here is an example I created showing this solution.
check.ps
uniform sampler2D texture0;
uniform sampler2D texture1;
varying mediump vec2 uvVarying;
varying mediump vec4 colorVarying;
void main()
{
vec4 numBoxes = texture2D(texture1, vec2(0.5,0.5));
float divx = 1.0/(numBoxes.r*255);
float divy = 1.0/(numBoxes.g*255);
int x = int(uvVarying.x/divx);
int y = int(uvVarying.y/divy);
if ((x & 1) != (y & 1))
{
discard;
}
else
{
gl_FragColor = texture2D(texture0, uvVarying)*colorVarying;
}
}
AGK code
// Project: testshader
// Created: 2018-12-19
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "testshader" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
shader as integer
shader = LoadSpriteShader("check.ps")
image = createimagecolor(255,255,255,255)
for i = 0 to 63
y = i / 8
x = mod(i,8)
createsprite(i+1,image)
SetSpriteSize(i+1,96,96)
SetSpriteColor(i+1,Random(64,255),Random(64,255),Random(64,255),255)
SetSpritePosition(i+1,96*x+128,96*y)
SetSpriteShader(i+1,shader)
SetSpriteAdditionalImage(i+1,CreateImageColor(i*2+2,i*2+2,i*2+2,i*2+2),1)
next
do
Print( ScreenFPS() )
Sync()
loop