Ich möchte eine Maske in einem Shader drehen, verschieben oder skalieren. Aber ich habe keine Ahnung, wie diese Aktionen ausgeführt werden.
Mein Code:
@Override
public void create() {
batch = new SpriteBatch();
background = new Texture(Gdx.files.internal("images/background.png"));
spritebackgournd = new Sprite(background,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
foreground = new Texture(Gdx.files.internal("images/foreground.png"));
mask = new Texture(Gdx.files.internal("images/mask.png"));
spriteforegournd = new Sprite(foreground,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
shader = new ShaderProgram(Gdx.files.internal("shaders/shader1.vert"), Gdx.files.internal("shaders/shader1.frag"));
}
@Override
public void render() {
batch.begin();
spritebackgournd.draw(batch);
batch.setShader(shader);
Gdx.graphics.getGL20().glActiveTexture(GL20.GL_TEXTURE0);
spriteforegournd.getTexture().bind(0);
//texture.bind(0);
shader.setUniformi("u_texture", 0);
Gdx.graphics.getGL20().glActiveTexture(GL20.GL_TEXTURE1);
//spritemask.getTexture().bind(1);
mask.bind(1);
shader.setUniformi("u_mask", 1);
Gdx.graphics.getGL20().glActiveTexture(GL20.GL_TEXTURE0);
spriteforegournd.draw(batch);
batch.end();
batch.setShader(null);
}
Der Vertex-Shader:
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec2 v_texCoords;
void main() {
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
Der Fragment-Shader:
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform sampler2D u_mask;
uniform mat4 u_projTrans;
void main() {
vec4 texColor = texture2D(u_texture, v_texCoords);
vec4 maskColor = texture2D(u_mask, v_texCoords);
gl_FragColor = texColor * maskColor.a;
}
Ich möchte in der Lage sein, die Maske im Shader zu skalieren, zu drehen und zu bewegen. Wie kann ich das machen?