Various graphical fixes

This commit is contained in:
Anuken 2018-12-29 13:06:17 -05:00
parent 5b2c8ac337
commit 86b35fc43d
8 changed files with 59 additions and 68 deletions

View file

@ -49,7 +49,6 @@ public class AndroidLauncher extends AndroidApplication{
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useImmersiveMode = true;
config.numSamples = 2;
config.depth = 0;
Platform.instance = new Platform(){

View file

@ -34,7 +34,13 @@ allprojects{
getArcHash = {
//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
}
@ -190,7 +196,7 @@ project(":core"){
build.finalizedBy(finish)
//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("extensions:freetype")

View file

@ -9,6 +9,7 @@ uniform sampler2D u_texture;
uniform vec4 u_color;
uniform vec2 u_texsize;
uniform float u_scl;
varying vec4 v_color;
varying vec2 v_texCoord;
@ -17,26 +18,27 @@ void main() {
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
vec4 c = texture2D(u_texture, v_texCoord.xy);
float spacing = SPACE * u_scl;
gl_FragColor = mix(c * v_color, u_color,
(1.0-step(0.1, texture2D(u_texture, v_texCoord.xy).a)) *
step(0.1,
//cardinals
texture2D(u_texture, v_texCoord.xy + vec2(0, SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, 0) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, 0) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(spacing, 0) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, 0) * v).a +
//cardinal edges
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, -SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, SPACE) * 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(spacing, -spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, spacing) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, -spacing) * v).a +
//cardinals * 2
texture2D(u_texture, v_texCoord.xy + vec2(0, SPACE) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -SPACE) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, 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(0, spacing) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -spacing) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(spacing, 0) * v*2.0).a +
texture2D(u_texture, v_texCoord.xy + vec2(-spacing, 0) * v*2.0).a
));
}

View file

@ -309,7 +309,7 @@ public class BlockFx extends FxList implements ContentList{
healBlockFull = new Effect(20, e -> {
Draw.color(e.color);
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();
});

View file

@ -277,6 +277,10 @@ public class Renderer implements ApplicationListener{
EntityDraw.drawWith(group, toDraw, drawer);
}
public float cameraScale(){
return camerascale;
}
public Vector2 averagePosition(){
avgPosition.setZero();

View file

@ -3,12 +3,10 @@ package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.IntSet;
import io.anuke.arc.collection.Sort;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Tmp;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.game.EventType.TileChangeEvent;
@ -18,8 +16,7 @@ import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import static io.anuke.arc.Core.camera;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
import static io.anuke.mindustry.Vars.*;
public class BlockRenderer{
private final static int initialRequests = 32 * 32;
@ -28,12 +25,10 @@ public class BlockRenderer{
public final FloorRenderer floor = new FloorRenderer();
private Array<BlockRequest> requests = new Array<>(true, initialRequests, BlockRequest.class);
private IntSet teamChecks = new IntSet();
private int lastCamX, lastCamY, lastRangeX, lastRangeY;
private int requestidx = 0;
private int iterateidx = 0;
private FrameBuffer shadows = new FrameBuffer(1, 1);
private FrameBuffer shadowWrite = new FrameBuffer(1, 1);
public BlockRenderer(){
@ -58,16 +53,30 @@ public class BlockRenderer{
}
public void drawShadows(){
Draw.color(0, 0, 0, 0.15f);
Draw.rect(Draw.wrap(shadowWrite.getTexture()),
camera.position.x - camera.position.x % tilesize,
camera.position.y - camera.position.y % tilesize,
shadowWrite.getWidth()*Draw.scl, -shadowWrite.getHeight()*Draw.scl);
Draw.color();
}
if(shadows.getWidth() != Core.graphics.getWidth() || shadows.getHeight() != Core.graphics.getHeight()){
shadows.resize(Core.graphics.getWidth(), Core.graphics.getHeight());
}
public boolean isTeamShown(Team team){
return teamChecks.contains(team.ordinal());
Tmp.tr1.set(shadows.getTexture());
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.*/
@ -84,25 +93,8 @@ public class BlockRenderer{
return;
}
int shadowW = (int)(rangex * tilesize*2/Draw.scl), shadowH = (int)(rangey * tilesize*2/Draw.scl);
teamChecks.clear();
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 miny = Math.max(avgy - rangey - expandr, 0);
int maxx = Math.min(world.width() - 1, avgx + rangex + expandr);
@ -123,8 +115,8 @@ public class BlockRenderer{
if(block != Blocks.air){
if(!expanded){
addRequest(tile, Layer.shadow);
addRequest(tile, Layer.block);
teamChecks.add(team.ordinal());
}
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());
Sort.instance().sort(requests.items, 0, requestidx);
@ -180,7 +154,9 @@ public class BlockRenderer{
BlockRequest req = requests.get(iterateidx);
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);
}else if(req.layer == block.layer){
block.drawLayer(req.tile);

View file

@ -1,6 +1,8 @@
package io.anuke.mindustry.graphics;
public enum Layer{
/**Drawn under everything.*/
shadow,
/**Base block layer.*/
block,
/**for placement*/

View file

@ -116,6 +116,7 @@ public class Shaders{
public static class Outline extends LoadShader{
public Color color = new Color();
public TextureRegion region = new TextureRegion();
public float scl;
public Outline(){
super("outline", "default");
@ -124,6 +125,7 @@ public class Shaders{
@Override
public void apply(){
setUniformf("u_color", color);
setUniformf("u_scl", scl);
setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
}
}