I am trying to make fruit slot machine game. It almost done but I can’t make fruit sprites invisible when it beyond the slot area. The fruit sprites should be partial visible if it just pass the edge of rectangle area. I tried to edit the shader program to make it work. Here are vp and fp code for fruit sprite material.
uniform highp mat4 view_proj;
// positions are in world space
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
varying mediump vec2 var_texcoord0;
varying mediump vec4 var_position;
void main()
{
gl_Position = view_proj * vec4(position.xyz, 1.0);
var_texcoord0 = texcoord0;
var_position = position;
}
varying mediump vec4 var_position;
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
if(var_position.y >= -175.0 && var_position.y <= 175.0) {
gl_FragColor = texture2D(texture_sampler, var_texcoord0.xy) * tint_pm;
} else {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
}
}
Here is the gameobject structure.
The problem is the fruits are all invisible when I run the project. The project will use collectionfactory to create slot collection which contain fruits gameobject like the upper picture I post. When I update the fruits gameobject position, the fruits are all invisible now.
Before I change the material of fruit sprites.
After I change the material of fruit sprites.