Reputation: 101
I already have a lightmap and lighting algorithm that is functional: tiles w/ lightmap
I am not using OpenGl, I do not need raycasted shadows, I just want the lightmap to blend in a gradient between the vertices of the lightmap so it is smooth instead of blocky. One way I saw this done was as follows: draw an image one pixel for each tile that contains the lightmap data, then scale it up using the size of the tiles and interpolation. However I don't understand how to do this and using this
lightmapimage.getScaledInstance(w,h,Image.SCALE_SMOOTH)
simply produces the same effect as in the image above only incredibly slower.
How do I go about smoothing the lighting in a resource-efficient way?
Upvotes: 1
Views: 275
Reputation: 101
I figured it out. For anyone interested in 2D tile-based smooth lighting, here is my solution: after drawing the lightmap to a small scale image where each pixel represents one tile, use an AffineTransformOp
of type bilinear.(the tile size is 10x10)
BufferedImage after = new BufferedImage(lightmap.getWidth()*10, lightmap.getHeight()*10, BufferedImage.TYPE_INT_ARGB);
AffineTransform at = new AffineTransform();
at.scale(10, 10);
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
after = scaleOp.filter(lightmap, after);
g.drawImage(after,0,0,null);
Upvotes: 1