OK so I managed to not KISS this some more
I tried to create two sprites, give them different instances of this shader and overlap them.
Here is the AppGameKit code:
global devW# = 640
global devH# = 480
oneColor()
//twoColors()
function oneColor()
SetWindowTitle( "test" )
SetWindowSize( devW#, devH#, 0 )
// set display properties
SetVirtualResolution( devW#, devH# )
SetOrientationAllowed( 1, 1, 1, 1 )
SetPrintColor(255,255,255)
SetSyncRate(60,0)
RenderImageID=CreateRenderImage(devW#, devH#,0,0)
SpriteID=createsprite(RenderImageID)
SetSpriteSize(SpriteID, devW#, devH#)
SetSpritePosition(SpriteID, 0, 0)
ShaderID=LoadSpriteShader("pixel.ps" )
SetSpriteShader(SpriteID,ShaderID)
x# = 100
y# = 100
do
setShaderConstantByName(ShaderID, "smokeSource",GetPointerX(),GetPointerY(),0.1,0)
SetRenderToImage(RenderImageID,0)
Render2DFront()
SetRenderToScreen()
x# = x# + 1
y# = y# + 1
Print( ScreenFPS() )
Sync()
loop
endfunction
function twoColors()
SetWindowTitle( "test" )
SetWindowSize( devW#, devH#, 0 )
// set display properties
SetVirtualResolution( devW#, devH# )
SetOrientationAllowed( 1, 1, 1, 1 )
SetPrintColor(255,255,255)
SetSyncRate(60,0)
RenderImageID=CreateRenderImage(devW#, devH#,0,0)
SpriteID=createsprite(RenderImageID)
SetSpriteSize(SpriteID, devW#, devH#)
SetSpritePosition(SpriteID, 0, 0)
RenderImageID2=CreateRenderImage(devW#, devH#,0,0)
SpriteID2=createsprite(RenderImageID2)
SetSpriteSize(SpriteID2, devW#, devH#)
SetSpritePosition(SpriteID2, 100, 0)
ShaderID=LoadSpriteShader("pixel.ps" )
SetSpriteShader(SpriteID,ShaderID)
ShaderID2=LoadSpriteShader("pixelg.ps" )
SetSpriteShader(SpriteID2,ShaderID2)
x# = 100
y# = 100
do
setShaderConstantByName(ShaderID2, "smokeSource",GetPointerX(),GetPointerY(),0.1,0)
// setShaderConstantByName(ShaderID2, "smokeSource",x#,y#,1,0)
SetRenderToImage(RenderImageID2,0)
Render2DFront()
setShaderConstantByName(ShaderID, "smokeSource",GetPointerX(),GetPointerY(),0.1,0)
// setShaderConstantByName(ShaderID, "smokeSource",x#,y#,1,0)
SetRenderToImage(RenderImageID,0)
Render2DFront()
SetRenderToScreen()
x# = x# + 1
y# = y# + 1
Print( ScreenFPS() )
Sync()
loop
endfunction
And here are the shaders:
red (pixel.ps):
uniform sampler2D bufferTexture;//Our input texture
uniform vec3 smokeSource;//The x,y are the posiiton. The z is the power/density
uniform float agk_time;
uniform vec2 agk_spritesize;
void main() {
vec2 pixel = gl_FragCoord.xy / agk_spritesize;
//Get the distance of the current pixel from the smoke source
float dist = distance(vec2(smokeSource.x,agk_spritesize.y-smokeSource.y),gl_FragCoord.xy);
//Get the color of the current pixel
gl_FragColor = texture2D( bufferTexture, pixel );
//Generate smoke when mouse is pressed
gl_FragColor.r += smokeSource.z * max(15.0-dist,0.0);
//Generate fixed smoke (this is the little point moving around in the center)
vec2 smokePoint = vec2(agk_spritesize.x/2.0+100.0*sin(agk_time),agk_spritesize.y/2.0+cos(agk_time*3.5)*20.0);
dist = distance(smokePoint,gl_FragCoord.xy);
// gl_FragColor.rgb += 0.01 * max(15.0-dist,0.0);
gl_FragColor.r += 0.01 * max(30.0-dist,0.0);
//Smoke diffuse
float xPixel = 1.0/agk_spritesize.x;//The size of a single pixel
float yPixel = 1.0/agk_spritesize.y;
vec4 rightColor = texture2D(bufferTexture,vec2(pixel.x+xPixel,pixel.y));
vec4 leftColor = texture2D(bufferTexture,vec2(pixel.x-xPixel,pixel.y));
vec4 upColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y+yPixel));
vec4 downColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y-yPixel));
//Handle the bottom boundary
if(pixel.y <= yPixel){
downColor.rgb = vec3(0.0);
}
//Diffuse equation
float factor = 8.0 * 0.016 * (leftColor.r + rightColor.r + downColor.r * 3.0 + upColor.r - 6.0 * gl_FragColor.r);
//Account for low precision of texels
float minimum = 0.003;
if(factor >= -minimum && factor < 0.0) factor = -minimum;
gl_FragColor.r += factor;
gl_FragColor.a = 0.0;
}
green (pixelg.ps):
uniform sampler2D bufferTexture;//Our input texture
uniform vec3 smokeSource;//The x,y are the posiiton. The z is the power/density
uniform float agk_time;
uniform vec2 agk_spritesize;
void main() {
vec2 pixel = gl_FragCoord.xy / agk_spritesize;
//Get the distance of the current pixel from the smoke source
float dist = distance(vec2(smokeSource.x,agk_spritesize.y-smokeSource.y),gl_FragCoord.xy);
//Get the color of the current pixel
gl_FragColor = texture2D( bufferTexture, pixel );
//Generate smoke when mouse is pressed
gl_FragColor.g += smokeSource.z * max(15.0-dist,0.0);
//Generate fixed smoke (this is the little point moving around in the center)
vec2 smokePoint = vec2(agk_spritesize.x/2.0+100.0*sin(agk_time),agk_spritesize.y/2.0+cos(agk_time*3.5)*20.0);
dist = distance(smokePoint,gl_FragCoord.xy);
// gl_FragColor.rgb += 0.01 * max(15.0-dist,0.0);
gl_FragColor.g += 0.01 * max(30.0-dist,0.0);
//Smoke diffuse
float xPixel = 1.0/agk_spritesize.x;//The size of a single pixel
float yPixel = 1.0/agk_spritesize.y;
vec4 rightColor = texture2D(bufferTexture,vec2(pixel.x+xPixel,pixel.y));
vec4 leftColor = texture2D(bufferTexture,vec2(pixel.x-xPixel,pixel.y));
vec4 upColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y+yPixel));
vec4 downColor = texture2D(bufferTexture,vec2(pixel.x,pixel.y-yPixel));
//Handle the bottom boundary
if(pixel.y <= yPixel){
downColor.rgb = vec3(0.0);
}
//Diffuse equation
// float factor = 8.0 * 0.016 * (leftColor.g + rightColor.g + downColor.g + upColor.g * 3.0 - 6.0 * gl_FragColor.g);
float factor = 8.0 * 0.016 * (leftColor.g + rightColor.g + downColor.g * 3.0 + upColor.g - 6.0 * gl_FragColor.g);
//Account for low precision of texels
float minimum = 0.003;
if(factor >= -minimum && factor < 0.0) factor = -minimum;
gl_FragColor.g += factor;
// gl_FragColor.r = 0.5;
// gl_FragColor.b = 0.5;
gl_FragColor.a = 0.0;
}
I attached images showing what the one- and two-color versions look on desktop and android.
The android versions show the problem of the image only appearing at bottom left corner.
The android versions also show a problem of only one shader/sprite appearing on android and the other shader not appearing at all. I tried to move them to not fully overlap but it still did not appear.
The desktop version shows a problem with the green smoke rising twice at the speed of the red smoke. I had to call the Render2DFront() twice to get it to draw so not sure if that causes it..