Hi
Paul, thank you for the idea of the discard, I have tried to write a little shader which seem to work great
(yes, AppGameKit rocks !)
Mask.vs :
// Alpha mask Shader for AGK
uniform vec4 agk_MeshDiffuse;
uniform vec4 uvBounds0;
varying vec2 uvVarying;
varying vec3 posVarying;
attribute vec2 uv;
attribute vec3 position;
uniform mat4 agk_World;
uniform mat4 agk_ViewProj;
void main()
{
vec4 pos = agk_World * vec4(position,1.0);
gl_Position = agk_ViewProj * pos;
posVarying = pos.xyz;
uvVarying = uv* uvBounds0.xy + uvBounds0.zw;
}
Mask.ps :
// shader alpha mask for AGK
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
varying vec2 uvVarying;
uniform vec4 agk_MeshDiffuse;
uniform vec4 MaskColor; // set the r,g,b (from 0.0 to 1.0) for the mask color
void main()
{
gl_FragColor = (texture2D(texture0, uvVarying) * agk_MeshDiffuse);
if (gl_FragColor == MaskColor) discard;
}
How to use it :
// you need to choose the color you want as mask, I have choosen the black (0,0,0)
LoadImage(2,"mask.png")
SetImageMinFilter(2,0) // don't forget mag and min filter to not have some weird border.
SetImageMagFilter(2,0)
LoadShader(1,"mask.vs","mask.ps")
SetShaderConstantByName(1,"MaskColor",0.0,0.0,0.0,1.0)
// on your object :
SetObjectImage(n,2,0)
SetObjectTransparency(n,0)
SetObjectShader(n,1)
// And that's ok !
I will post this shader on the shader thread.
AGK2 tier1 - http://www.dracaena-studio.com