我在使用舞臺動作在文本(着色器)中應用alpha有一些麻煩。我正在使用添加窗口角色和窗口添加標籤角色的組。我的另一個演員在組中工作正常,應用Actions alpha但我的標籤(使用着色器繪製)不工作,與其他小部件的不同之處在於我的文本標籤正在應用着色器。Libgdx,Alpha文本使用着色器不起作用
font.frag uniform sampler2D u_texture;
varying vec4 v_color;
varying vec2 v_texCoord;
const float smoothing = 0.2;
void main() {
float distance = texture2D(u_texture, v_texCoord).a;
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
gl_FragColor = vec4(texture2D(u_texture, v_texCoord).rgb, alpha);
}
font.vert
uniform mat4 u_projTrans;
attribute vec4 a_position;
attribute vec2 a_texCoord0;
attribute vec4 a_color;
varying vec4 v_color;
varying vec2 v_texCoord;
void main() {
gl_Position = u_projTrans * a_position;
v_texCoord = a_texCoord0;
v_color = a_color;
}
我的標籤延伸從Libgdx標籤應用的着色器,
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label {
boolean shaderActive = false;
public Label(CharSequence text, LabelStyle style) {
super(text, style);
if(style.font.getScaleX() > 1f)
shaderActive = true;
}
@Override
public void draw(Batch batch, float parentAlpha) {
if(shaderActive) {
batch.setShader(Assets.assetFont.fontShader);
}
super.draw(batch, parentAlpha);
batch.setShader(null);
}
}
工作代碼
private void initStage() {
// TODO Stage Here
stage = new Stage();
stage.setViewport(viewport);
Window w2 = new Window("",
new WindowStyle(Assets.assetFont.blackBoldVSmall, Color.BLACK,
new Image(Assets.assetHUD.windowFrame).getDrawable()));
w2.setSize(1200, 675);
w2.setPosition(40, 0);
Label lbl2 = new Label("Touch here to Jump !", new LabelStyle(Assets.assetFont.goldBoldNormal, Color.GRAY));
lbl2.setPosition(Settings.width/2, Settings.height/2);
w2.add(lbl2);
groupTouchHere.addActor(w2);
stage.addActor(groupTouchHere);
// sequence of action
SequenceAction sequence = new SequenceAction(
Actions.fadeIn(0.4f, Interpolation.circleOut),
Actions.fadeOut(0.4f, Interpolation.circleIn));
SequenceAction sequenceTotal = new SequenceAction(sequence, Actions.repeat(4, sequence));
groupTouchHere.addAction(sequenceTotal);
}
public void update(float deltaTime){
stage.act();
}
確定它適用於alpha着色器,但現在我遇到了麻煩,我的所有精靈都使用相同的着色器覆蓋1着色器中的alpha。 – RaditzLawliet 2014-09-09 08:51:55
即1個標籤我想0.5f阿爾法,另一個我想要1f阿爾法(但它不能)它覆蓋所有標籤有0.5f阿爾法。 – RaditzLawliet 2014-09-09 08:52:39
好吧,現在它工作,即時通訊使用 'Assets.assetFont.fontShader.setUniformf(「u_newAlpha」,parentAlpha);' 字體使用着色器。感謝:D – RaditzLawliet 2014-09-09 14:45:31