I made a shader that takes the mouse position and radius as parameters to create a mask for the image. Tell me how you can save the results of previous clicks.
main.agc
sprite=LoadSprite("layer.png")
SetSpriteSize(sprite, 500, 500)
image=LoadImage("image.jpg")
SetSpriteAdditionalImage(sprite, image, 1 )
shader=LoadSpriteShader("shader.ps")
SetSpriteShader(sprite,shader)
SetShaderConstantByName( shader, "setup", -1.0, -1.0, 0, 0 )
do
If GetPointerPressed()=1
x_shader#=GetPointerXShader(sprite, GetPointerX())
y_shader#=GetPointerYShader(sprite, GetPointerY())
radius_shader#=80
SetShaderConstantByName( shader, "setup", x_shader#, y_shader#, radius_shader#, 0 )
endif
Sync()
loop
function GetPointerXShader( SpriteID, x# )
result#=(x#/(GetSpriteWidth(SpriteID)/100.0))/100.0
endfunction result#
function GetPointerYShader( SpriteID, y# )
result#=GetVirtualHeight()/GetSpriteHeight(spriteID) - (y#/(GetSpriteHeight(SpriteID)/100.0))/100.0
endfunction result#
shader.ps
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uvVarying;
uniform vec2 agk_spritesize;
uniform vec3 setup;
vec4 circle(vec2 uv, vec2 pos, float rad, vec3 color) {
float d = length(pos - uv) - rad;
float t = clamp(d, 0.0, 1.0);
return vec4(color, 1.0 - t);
}
void main()
{
vec2 uv = gl_FragCoord.xy;
// background layer
vec4 layer1 = vec4(texture2D(texture0, uvVarying ));
//image layer
vec4 color = vec4(texture2D(texture1, uvVarying ));
//setup
float radius = setup.z;
vec2 position = vec2 (agk_spritesize.x * setup.x, agk_spritesize.y * setup.y);
//circle
vec4 layer2 = circle(uv, position, radius, color.rgb);
//blend the two
gl_FragColor = mix(layer1, layer2, layer2.a);
}