既然图片搞了好多次都不好,那就自己用shader加遮罩吧。
image.png
vert
···
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
varying vec4 v_color;
uniform mat4 u_projTrans;
varying vec2 v_textCoords;
void main() {
v_color = a_color;
v_color.a = v_color.a * (255.0/254.0);
v_textCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
···
frag
#ifdef GL_ES
precision mediump float;
#endif
//input from vertex shader
varying vec4 v_color;
varying vec2 v_textCoords;
uniform sampler2D u_texture;
void main() {
// vec4 tempColor = v_color* texture2D(u_texture,v_textCoords);
// if(tempColor.a>0.1){
// gl_FragColor = vec4(0.3, 0.3, 0.3, tempColor.a);
// }else{
// gl_FragColor = vec4(1, 1, 1, tempColor.a);
// }
vec4 tempColor = v_color* texture2D(u_texture,v_textCoords);
vec3 xx = mix(tempColor.rgb,vec3(0,0,0),0.66) ;
// vec3 xx = tempColor.rgb*vec3(0.4,0.4,0.4) ;
// gl_FragColor = vec4(xx,tempColor.rgba);
gl_FragColor = vec4(xx,tempColor.a);
}
java
public class ShadowGroup extends Group {
ShaderProgram program;
public ShadowGroup(){
program = new ShaderProgram(Gdx.files.internal("shader/hui.vert"),Gdx.files.internal("shader/hui.frag"));
Image image = new Image(new Texture("img/poker1_face.png"));
addActor(image);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.flush();
batch.setShader(program);
super.draw(batch, parentAlpha);
batch.flush();
batch.setShader(null);
}
}
网友评论