Java – unexpected results of implementing simple motion blur in libgdx

In the attached two photos, the desktop screenshot function of libgdx is as expected Unfortunately, my Galaxy nexus screenshot was not as expected I'm trying to create a simple motion blur or footstep effect

Render my expectations on my desktop

It doesn't render on my Galaxy nexus as I expected

During rendering, the circular texture is drawn in the for loop, and the pixel map of 0,0f RGBA drawn before the circle is used to achieve the effect

Screenclearsprite create

Pixmap screenClearPixmap = new Pixmap(256,256,Format.RGBA8888);
screenClearPixmap.setColor(Color.rgba8888(0,0.1f));
screenClearPixmap.fillRectangle(0,256);
screenClearTexture = new Texture(screenClearPixmap);
screenClearSprite = new Sprite(screenClearTexture);
screenClearSprite.setSize(screenWidth,screenHeight);
screenClearPixmap.dispose();

give

batch.begin();
font.draw(batch,"fps:" + Gdx.graphics.getFramesPerSecond(),20);
screenClearSprite.draw(batch);
for (int i = 0; i < circleBodies.size(); i++) {
    tempPos = circleBodies.get(i).getPosition();
    batch.draw(circleTexture,(tempPos.x * SCALE) + screenWidthHalf
            - circleSizeHalf,(tempPos.y * SCALE) + screenHeightHalf
            - circleSizeHalf);
}
batch.end();

What did I do wrong? Maybe there is a better way to get the "motion blur" effect of motion?

Solution

Here's a different way to clear the screen every time you use solid color and no alpha

This means you have to modify your code The good thing about this is that what you do has some disadvantages: it blurs all the motion, not just the ball Unless you are careful, it will produce ugly results / artifacts soon

>Do what you do now, instead of painting balls to batch, paint them to texture / bitmap / anything Then an alpha blend image is added to the ball image at each frame, and the ball is drawn in the current position Then add the image to your screen I like what you are doing now very much. Keep it except what you draw This way, you don't have to rely on the viewport you're drawing, and you can separate everything This method is similar to drawing to the accumulation buffer Instead of doing it your way, you can track the latest position of each ball Then draw all of each frame, with a different alpha This is easy to achieve If you have many balls or large N, it may cause many drawing calls, but if not too many, you should not limit your FPS and give good control

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>