Various graphical fixes
This commit is contained in:
@@ -49,7 +49,6 @@ public class AndroidLauncher extends AndroidApplication{
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||||
config.useImmersiveMode = true;
|
config.useImmersiveMode = true;
|
||||||
config.numSamples = 2;
|
|
||||||
config.depth = 0;
|
config.depth = 0;
|
||||||
Platform.instance = new Platform(){
|
Platform.instance = new Platform(){
|
||||||
|
|
||||||
|
|||||||
10
build.gradle
10
build.gradle
@@ -34,7 +34,13 @@ allprojects{
|
|||||||
|
|
||||||
getArcHash = {
|
getArcHash = {
|
||||||
//get latest commit hash from gtihub since JITPack's '-snapshot' version doesn't work correctly
|
//get latest commit hash from gtihub since JITPack's '-snapshot' version doesn't work correctly
|
||||||
if(arcHash == null) arcHash = new JsonSlurper().parseText(new URL("https://api.github.com/repos/Anuken/Arc/commits/master").text)["sha"]
|
if(arcHash == null){
|
||||||
|
try{
|
||||||
|
arcHash = new JsonSlurper().parse(new URL("https://api.github.com/repos/Anuken/Arc/commits/master"))["sha"]
|
||||||
|
}catch(e){ //github can get angry sometimes
|
||||||
|
arcHash = "-SNAPSHOT";
|
||||||
|
}
|
||||||
|
}
|
||||||
return arcHash
|
return arcHash
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +196,7 @@ project(":core"){
|
|||||||
build.finalizedBy(finish)
|
build.finalizedBy(finish)
|
||||||
|
|
||||||
//forces JITPack to compile arc and its submodules
|
//forces JITPack to compile arc and its submodules
|
||||||
if(localArc()) compile "com.github.anuken:arc:${getArcHash()}"
|
if(!localArc()) compile "com.github.anuken:arc:${getArcHash()}"
|
||||||
|
|
||||||
compile arcModule("arc-core")
|
compile arcModule("arc-core")
|
||||||
compile arcModule("extensions:freetype")
|
compile arcModule("extensions:freetype")
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ uniform sampler2D u_texture;
|
|||||||
|
|
||||||
uniform vec4 u_color;
|
uniform vec4 u_color;
|
||||||
uniform vec2 u_texsize;
|
uniform vec2 u_texsize;
|
||||||
|
uniform float u_scl;
|
||||||
|
|
||||||
varying vec4 v_color;
|
varying vec4 v_color;
|
||||||
varying vec2 v_texCoord;
|
varying vec2 v_texCoord;
|
||||||
@@ -17,26 +18,27 @@ void main() {
|
|||||||
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
||||||
|
|
||||||
vec4 c = texture2D(u_texture, v_texCoord.xy);
|
vec4 c = texture2D(u_texture, v_texCoord.xy);
|
||||||
|
float spacing = SPACE * u_scl;
|
||||||
|
|
||||||
gl_FragColor = mix(c * v_color, u_color,
|
gl_FragColor = mix(c * v_color, u_color,
|
||||||
(1.0-step(0.1, texture2D(u_texture, v_texCoord.xy).a)) *
|
(1.0-step(0.1, texture2D(u_texture, v_texCoord.xy).a)) *
|
||||||
step(0.1,
|
step(0.1,
|
||||||
//cardinals
|
//cardinals
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(0, SPACE) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(0, spacing) * v).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(0, -SPACE) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(0, -spacing) * v).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, 0) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(spacing, 0) * v).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, 0) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, 0) * v).a +
|
||||||
|
|
||||||
//cardinal edges
|
//cardinal edges
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, SPACE) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(spacing, spacing) * v).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, -SPACE) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(spacing, -spacing) * v).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, SPACE) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, spacing) * v).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, -SPACE) * v).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, -spacing) * v).a +
|
||||||
|
|
||||||
//cardinals * 2
|
//cardinals * 2
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(0, SPACE) * v*2.0).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(0, spacing) * v*2.0).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(0, -SPACE) * v*2.0).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(0, -spacing) * v*2.0).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, 0) * v*2.0).a +
|
texture2D(u_texture, v_texCoord.xy + vec2(spacing, 0) * v*2.0).a +
|
||||||
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, 0) * v*2.0).a
|
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, 0) * v*2.0).a
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ public class BlockFx extends FxList implements ContentList{
|
|||||||
healBlockFull = new Effect(20, e -> {
|
healBlockFull = new Effect(20, e -> {
|
||||||
Draw.color(e.color);
|
Draw.color(e.color);
|
||||||
Draw.alpha(e.fout());
|
Draw.alpha(e.fout());
|
||||||
Fill.square(e.x, e.y, e.rotation * tilesize);
|
Fill.square(e.x, e.y, e.rotation * tilesize / 2f);
|
||||||
Draw.color();
|
Draw.color();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -277,6 +277,10 @@ public class Renderer implements ApplicationListener{
|
|||||||
EntityDraw.drawWith(group, toDraw, drawer);
|
EntityDraw.drawWith(group, toDraw, drawer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float cameraScale(){
|
||||||
|
return camerascale;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 averagePosition(){
|
public Vector2 averagePosition(){
|
||||||
avgPosition.setZero();
|
avgPosition.setZero();
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ package io.anuke.mindustry.graphics;
|
|||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.Events;
|
import io.anuke.arc.Events;
|
||||||
import io.anuke.arc.collection.Array;
|
import io.anuke.arc.collection.Array;
|
||||||
import io.anuke.arc.collection.IntSet;
|
|
||||||
import io.anuke.arc.collection.Sort;
|
import io.anuke.arc.collection.Sort;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.Color;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.glutils.FrameBuffer;
|
import io.anuke.arc.graphics.glutils.FrameBuffer;
|
||||||
import io.anuke.arc.math.Mathf;
|
|
||||||
import io.anuke.arc.util.Tmp;
|
import io.anuke.arc.util.Tmp;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||||
@@ -18,8 +16,7 @@ import io.anuke.mindustry.world.Block;
|
|||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
import static io.anuke.arc.Core.camera;
|
import static io.anuke.arc.Core.camera;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.world;
|
|
||||||
|
|
||||||
public class BlockRenderer{
|
public class BlockRenderer{
|
||||||
private final static int initialRequests = 32 * 32;
|
private final static int initialRequests = 32 * 32;
|
||||||
@@ -28,12 +25,10 @@ public class BlockRenderer{
|
|||||||
public final FloorRenderer floor = new FloorRenderer();
|
public final FloorRenderer floor = new FloorRenderer();
|
||||||
|
|
||||||
private Array<BlockRequest> requests = new Array<>(true, initialRequests, BlockRequest.class);
|
private Array<BlockRequest> requests = new Array<>(true, initialRequests, BlockRequest.class);
|
||||||
private IntSet teamChecks = new IntSet();
|
|
||||||
private int lastCamX, lastCamY, lastRangeX, lastRangeY;
|
private int lastCamX, lastCamY, lastRangeX, lastRangeY;
|
||||||
private int requestidx = 0;
|
private int requestidx = 0;
|
||||||
private int iterateidx = 0;
|
private int iterateidx = 0;
|
||||||
private FrameBuffer shadows = new FrameBuffer(1, 1);
|
private FrameBuffer shadows = new FrameBuffer(1, 1);
|
||||||
private FrameBuffer shadowWrite = new FrameBuffer(1, 1);
|
|
||||||
|
|
||||||
public BlockRenderer(){
|
public BlockRenderer(){
|
||||||
|
|
||||||
@@ -58,16 +53,30 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawShadows(){
|
public void drawShadows(){
|
||||||
Draw.color(0, 0, 0, 0.15f);
|
if(shadows.getWidth() != Core.graphics.getWidth() || shadows.getHeight() != Core.graphics.getHeight()){
|
||||||
Draw.rect(Draw.wrap(shadowWrite.getTexture()),
|
shadows.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
|
||||||
camera.position.x - camera.position.x % tilesize,
|
}
|
||||||
camera.position.y - camera.position.y % tilesize,
|
|
||||||
shadowWrite.getWidth()*Draw.scl, -shadowWrite.getHeight()*Draw.scl);
|
|
||||||
Draw.color();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTeamShown(Team team){
|
Tmp.tr1.set(shadows.getTexture());
|
||||||
return teamChecks.contains(team.ordinal());
|
Shaders.outline.color.set(0, 0, 0, 0.15f);
|
||||||
|
Shaders.outline.scl = renderer.cameraScale()/3f;
|
||||||
|
Shaders.outline.region = Tmp.tr1;
|
||||||
|
|
||||||
|
Draw.flush();
|
||||||
|
shadows.begin();
|
||||||
|
Core.graphics.clear(Color.CLEAR);
|
||||||
|
Draw.color(Color.BLACK);
|
||||||
|
drawBlocks(Layer.shadow);
|
||||||
|
Draw.color();
|
||||||
|
Draw.flush();
|
||||||
|
shadows.end();
|
||||||
|
|
||||||
|
Draw.shader(Shaders.outline);
|
||||||
|
Draw.rect(Draw.wrap(shadows.getTexture()),
|
||||||
|
camera.position.x,
|
||||||
|
camera.position.y,
|
||||||
|
camera.width, -camera.height);
|
||||||
|
Draw.shader();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Process all blocks to draw, simultaneously updating the block shadow framebuffer.*/
|
/**Process all blocks to draw, simultaneously updating the block shadow framebuffer.*/
|
||||||
@@ -84,25 +93,8 @@ public class BlockRenderer{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int shadowW = (int)(rangex * tilesize*2/Draw.scl), shadowH = (int)(rangey * tilesize*2/Draw.scl);
|
|
||||||
|
|
||||||
teamChecks.clear();
|
|
||||||
requestidx = 0;
|
requestidx = 0;
|
||||||
|
|
||||||
Draw.flush();
|
|
||||||
Draw.proj().setOrtho(
|
|
||||||
Mathf.round(Core.camera.position.x, tilesize)-shadowW/2f*Draw.scl,
|
|
||||||
Mathf.round(Core.camera.position.y, tilesize)-shadowH/2f*Draw.scl,
|
|
||||||
shadowW*Draw.scl, shadowH*Draw.scl);
|
|
||||||
|
|
||||||
if(shadows.getWidth() != shadowW || shadows.getHeight() != shadowH){
|
|
||||||
shadows.resize(shadowW, shadowH);
|
|
||||||
shadowWrite.resize(shadowW, shadowH);
|
|
||||||
}
|
|
||||||
|
|
||||||
shadows.begin();
|
|
||||||
Core.graphics.clear(Color.CLEAR);
|
|
||||||
|
|
||||||
int minx = Math.max(avgx - rangex - expandr, 0);
|
int minx = Math.max(avgx - rangex - expandr, 0);
|
||||||
int miny = Math.max(avgy - rangey - expandr, 0);
|
int miny = Math.max(avgy - rangey - expandr, 0);
|
||||||
int maxx = Math.min(world.width() - 1, avgx + rangex + expandr);
|
int maxx = Math.min(world.width() - 1, avgx + rangex + expandr);
|
||||||
@@ -123,8 +115,8 @@ public class BlockRenderer{
|
|||||||
|
|
||||||
if(block != Blocks.air){
|
if(block != Blocks.air){
|
||||||
if(!expanded){
|
if(!expanded){
|
||||||
|
addRequest(tile, Layer.shadow);
|
||||||
addRequest(tile, Layer.block);
|
addRequest(tile, Layer.block);
|
||||||
teamChecks.add(team.ordinal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(block.expanded || !expanded){
|
if(block.expanded || !expanded){
|
||||||
@@ -141,24 +133,6 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.flush();
|
|
||||||
shadows.end();
|
|
||||||
|
|
||||||
Tmp.tr1.set(shadows.getTexture());
|
|
||||||
Shaders.outline.color.set(Color.BLACK);
|
|
||||||
Shaders.outline.region = Tmp.tr1;
|
|
||||||
|
|
||||||
Draw.shader(Shaders.outline);
|
|
||||||
shadowWrite.begin();
|
|
||||||
Core.graphics.clear(Color.CLEAR);
|
|
||||||
Draw.rect(Draw.wrap(shadows.getTexture()),
|
|
||||||
Mathf.round(Core.camera.position.x, tilesize),
|
|
||||||
Mathf.round(Core.camera.position.y, tilesize),
|
|
||||||
shadows.getTexture().getWidth() * Draw.scl,
|
|
||||||
-shadows.getTexture().getHeight() * Draw.scl);
|
|
||||||
Draw.shader();
|
|
||||||
shadowWrite.end();
|
|
||||||
|
|
||||||
Draw.proj(camera.projection());
|
Draw.proj(camera.projection());
|
||||||
|
|
||||||
Sort.instance().sort(requests.items, 0, requestidx);
|
Sort.instance().sort(requests.items, 0, requestidx);
|
||||||
@@ -180,7 +154,9 @@ public class BlockRenderer{
|
|||||||
BlockRequest req = requests.get(iterateidx);
|
BlockRequest req = requests.get(iterateidx);
|
||||||
Block block = req.tile.block();
|
Block block = req.tile.block();
|
||||||
|
|
||||||
if(req.layer == Layer.block){
|
if(req.layer == Layer.shadow){
|
||||||
|
block.drawShadow(req.tile);
|
||||||
|
}else if(req.layer == Layer.block){
|
||||||
block.draw(req.tile);
|
block.draw(req.tile);
|
||||||
}else if(req.layer == block.layer){
|
}else if(req.layer == block.layer){
|
||||||
block.drawLayer(req.tile);
|
block.drawLayer(req.tile);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package io.anuke.mindustry.graphics;
|
package io.anuke.mindustry.graphics;
|
||||||
|
|
||||||
public enum Layer{
|
public enum Layer{
|
||||||
|
/**Drawn under everything.*/
|
||||||
|
shadow,
|
||||||
/**Base block layer.*/
|
/**Base block layer.*/
|
||||||
block,
|
block,
|
||||||
/**for placement*/
|
/**for placement*/
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ public class Shaders{
|
|||||||
public static class Outline extends LoadShader{
|
public static class Outline extends LoadShader{
|
||||||
public Color color = new Color();
|
public Color color = new Color();
|
||||||
public TextureRegion region = new TextureRegion();
|
public TextureRegion region = new TextureRegion();
|
||||||
|
public float scl;
|
||||||
|
|
||||||
public Outline(){
|
public Outline(){
|
||||||
super("outline", "default");
|
super("outline", "default");
|
||||||
@@ -124,6 +125,7 @@ public class Shaders{
|
|||||||
@Override
|
@Override
|
||||||
public void apply(){
|
public void apply(){
|
||||||
setUniformf("u_color", color);
|
setUniformf("u_color", color);
|
||||||
|
setUniformf("u_scl", scl);
|
||||||
setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
|
setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user