Per pixel lighting using GLSL in LibGDXAsk Question

问题:

I'm currently trying to implement dynamic lighting into my game. This is the way I have it set up now:

public ComponentTexture(ComponentTileMap tileMap) {
    int r = tileMap.getWidth()/2;
    Pixmap pixMap = new Pixmap(r*2, r*2, Format.RGBA8888);
    for(int x = -r; x < r; x++)
        for(int y = -r; y < r; y++) {
            if(!tileMap.hasTileAt(x, y))
                continue;
            pixMap.setColor(Color.BLACK.cpy().lerp(tileMap.getTile(x, y).color, tileMap.getLight(x, y)));
            pixMap.drawPixel(x + r, r - y - 1);
        }
    this.texture = new Texture(pixMap);
}

it looks like this

While this does work, it also uses a lot of processing power since it is ran every frame.

I think the correct way to solve this issue is to use a GLSL shader. But how do I pass the brightness for every pixel of the texture to the shader?

标签: libgdx glsl
© 2014 TuiCode, Inc.