如何解决libgdx 帧缓冲区仅在某些机器上获得视觉静态
我有一个系统,我使用 Libgdx 的 ShapeRenderer 在 FrameBuffer 中沿样条线生成一条线,将一些纹理渲染到另一个 FrameBuffer 中,将生成的线应用到平铺纹理作为蒙版,然后最终将最终产品渲染为主摄像头上的纹理样条线。
最终输出看起来像这样,目前看起来有点像字符中间的复选标记: (似乎我需要 10 个声望才能提交图片,所以这里是 expected output 的链接)
直到今天,在我的机器上以及与我共享的大多数人上一切正常。
仅在此人的机器上,我无法重现它或看到类似的东西,它看起来像这样:incorrect output
public void render(SpriteBatch sb) {
//create the mask
sb.end();
TextureRegion mask = createMask();
//create the tiles
HydrologistMod.beginBuffer(tileBuffer);
sb.begin();
sb.setBlendFunction(GL20.GL_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA);
effectsMap.get(current).instructor.instruct();
renderTiles(sb); //uses instructions one line above to render a grid of tiled texture based on the size of the spline
... //section of code where sometimes the texture is combined with another,but there was no effect transition happening at the time
//mask the tiles
sb.setBlendFunction(0,GL20.GL_SRC_ALPHA);
sb.setColor(Color.WHITE.cpy());
sb.draw(mask,0);
//collect the final texture
sb.end();
tileBuffer.end();
TextureRegion texture = HydrologistMod.getBufferTexture(tileBuffer);
sb.setBlendFunction(GL20.GL_ONE,GL20.GL_ONE_MINUS_SRC_ALPHA);
... //section of code where no relevant effects were active
//render the effect on the main camera
sb.begin();
sb.draw(texture,0);
sb.setBlendFunction(GL20.GL_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA);
}
从顶部开始,我定义的方法: createMask() 处理样条的绘制。基本方法是在所有点之间画一个填充的矩形,并以几种不同的方式重复该过程,以更好地填充各种芯片和间隙。
private TextureRegion createMask() {
HydrologistMod.beginBuffer(maskBuffer);
Color color = Color.BLACK.cpy();
color.a = 0.5f;
renderCurve(color,LINE_WIDTH); //half transparent larger outline for anti-aliasing
color.a = 1.0f;
renderCurve(color,LINE_WIDTH - 1);
maskBuffer.end();
return HydrologistMod.getBufferTexture(maskBuffer);
}
private void renderCurve(Color color,int width) {
shape.begin(ShapeRenderer.ShapeType.Filled);
shape.setColor(color);
int linewidth;
for (int i = 0; i < spline.size() - 1; ++i) {
if (i < width) {
linewidth = i + 1;
} else if (i > spline.size() - width) {
linewidth = spline.size() - i;
} else {
linewidth = width;
}
Vector2 start = spline.get(i).toVector();
Vector2 mid = spline.get(i+1).toVector();
shape.rectLine(start,mid,linewidth);
if ((i < spline.size() - 3)) {
Vector2 end = spline.get(i + 2).toVector();
shape.rectLine(start,end,linewidth);
}
}
shape.end();
}
.beginBuffer 是启动和清理帧缓冲区的辅助方法:
public static void beginBuffer(FrameBuffer fbo) {
fbo.begin();
Gdx.gl.glClearColor(0.0F,0.0F,0.0F);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glColorMask(true,true,true);
}
和 .getBufferTexture 是一个辅助方法,可以自动从缓冲区中检索纹理并翻转它,因为 libgdx 帧缓冲区喜欢颠倒
public static TextureRegion getBufferTexture(FrameBuffer fbo) {
TextureRegion texture = new TextureRegion(fbo.getColorBufferTexture());
texture.flip(false,true);
return texture;
}
我已尝试调查此问题,据我所知,这可能发生在样条曲线渲染、缓冲区信息以某种方式损坏以及蒙版应用之间的任何地方。在此过程中的某个地方,引入了大量视觉噪音,但我似乎无法弄清楚可能导致此问题的原因,而且我的搜索没有发现任何人遇到类似问题。
对于任何想要仔细研究的人,我的项目可以在 github 上找到,并且可以找到我处理此逻辑的类here.
感谢任何帮助,我为这种效果感到非常自豪,并且不希望任何人的体验被丑陋的静电破坏
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。