Implemented new build shader
Before Width: | Height: | Size: 278 B After Width: | Height: | Size: 247 B |
Before Width: | Height: | Size: 246 B After Width: | Height: | Size: 250 B |
Before Width: | Height: | Size: 255 B After Width: | Height: | Size: 306 B |
53
core/assets/shaders/build.fragment
Normal file
@ -0,0 +1,53 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
uniform float u_time;
|
||||
uniform float u_progress;
|
||||
uniform vec4 u_color;
|
||||
uniform vec2 u_uv;
|
||||
uniform vec2 u_uv2;
|
||||
uniform vec2 u_texsize;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_texCoord;
|
||||
|
||||
float rand(vec2 co){
|
||||
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
bool id(vec4 v){
|
||||
return v.a > 0.1;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 coords = (v_texCoord.xy - u_uv) / (u_uv2 - u_uv);
|
||||
vec2 t = v_texCoord.xy;
|
||||
|
||||
vec4 c = texture2D(u_texture, v_texCoord.xy);
|
||||
|
||||
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
|
||||
float step = 1.0;
|
||||
|
||||
bool outline = texture2D(u_texture, t).a < 0.1 &&
|
||||
(id(texture2D(u_texture, t + vec2(0, step) * v)) || id(texture2D(u_texture, t + vec2(0, -step) * v)) ||
|
||||
id(texture2D(u_texture, t + vec2(step, 0) * v)) || id(texture2D(u_texture, t + vec2(-step, 0) * v)));
|
||||
|
||||
if(1.0-abs(coords.x - 0.5)*2.0 < 1.0-u_progress){
|
||||
c = vec4(0.0);
|
||||
}
|
||||
|
||||
if(c.a > 0.01 || outline){
|
||||
float f = abs(sin(coords.x*2.0 + u_time));
|
||||
if(f > 0.9 || (f > 0.7 && rand(t) > 0.6))
|
||||
f = 1.0;
|
||||
else
|
||||
f = 0.0;
|
||||
c = mix(c, u_color, f);
|
||||
}
|
||||
|
||||
gl_FragColor = c * v_color;
|
||||
}
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 93 KiB |
@ -1,7 +1,7 @@
|
||||
#Autogenerated file. Do not modify.
|
||||
#Sun Mar 25 15:04:04 EDT 2018
|
||||
#Sun Mar 25 16:45:50 EDT 2018
|
||||
version=release
|
||||
androidBuildCode=650
|
||||
androidBuildCode=653
|
||||
name=Mindustry
|
||||
code=3.4
|
||||
build=custom build
|
||||
|
@ -11,7 +11,7 @@ public class UnitBlocks {
|
||||
|
||||
flierFactory = new UnitFactory("flierfactory"){{
|
||||
type = UnitTypes.flier;
|
||||
produceTime = 400;
|
||||
produceTime = 200;
|
||||
size = 2;
|
||||
requirements = new ItemStack[]{
|
||||
new ItemStack(Items.stone, 5)
|
||||
|
@ -2,6 +2,7 @@ package io.anuke.mindustry.graphics;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
import io.anuke.ucore.core.Core;
|
||||
@ -15,10 +16,31 @@ public class Shaders{
|
||||
public static final SurfaceShader water = new SurfaceShader("water");
|
||||
public static final SurfaceShader lava = new SurfaceShader("lava");
|
||||
public static final SurfaceShader oil = new SurfaceShader("oil");
|
||||
public static final Shader hit = new Shader("hit", "default") { protected void apply() {}};
|
||||
public static final UnitBuild build = new UnitBuild();
|
||||
public static final Shader hit = new Shader("hit", "default");
|
||||
|
||||
private static final Vector2 vec = new Vector2();
|
||||
|
||||
public static class UnitBuild extends Shader{
|
||||
public float progress, time;
|
||||
public Color color = new Color();
|
||||
public TextureRegion region;
|
||||
|
||||
public UnitBuild() {
|
||||
super("build", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
shader.setUniformf("u_time", time);
|
||||
shader.setUniformf("u_color", color);
|
||||
shader.setUniformf("u_progress", progress);
|
||||
shader.setUniformf("u_uv", region.getU(), region.getV());
|
||||
shader.setUniformf("u_uv2", region.getU2(), region.getV2());
|
||||
shader.setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Outline extends Shader{
|
||||
public Color color = new Color();
|
||||
|
||||
|
@ -3,12 +3,12 @@ package io.anuke.mindustry.world;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
public enum BarType {
|
||||
health(Color.RED),
|
||||
health(Color.SCARLET),
|
||||
inventory(Color.GREEN),
|
||||
power(Color.YELLOW),
|
||||
power(Color.valueOf("fbeb67")),
|
||||
liquid(Color.ROYAL),
|
||||
heat(Color.CORAL),
|
||||
production(Color.PURPLE);
|
||||
production(Color.valueOf("f4ba6e"));
|
||||
|
||||
public final Color color;
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package io.anuke.mindustry.world.blocks.types.production;
|
||||
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.entities.units.UnitType;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
@ -12,11 +14,11 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.BlockBar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.modules.InventoryModule;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Tmp;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -49,21 +51,22 @@ public class UnitFactory extends Block {
|
||||
UnitFactoryEntity entity = tile.entity();
|
||||
TextureRegion region = Draw.region(unitRegion == null ? type.name : unitRegion);
|
||||
|
||||
int w = (int)(entity.buildTime/produceTime * region.getRegionWidth());
|
||||
|
||||
Draw.rect(name(), tile.drawx(), tile.drawy());
|
||||
|
||||
Draw.alpha(0.2f);
|
||||
//Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
Shaders.build.region = region;
|
||||
Shaders.build.progress = entity.buildTime/produceTime;
|
||||
Shaders.build.color = Colors.get("accent");
|
||||
Shaders.build.time = -entity.time / 10f;
|
||||
|
||||
Tmp.tr1.setRegion(region, region.getRegionWidth() - w, 0, w, region.getRegionHeight());
|
||||
Draw.rect(Tmp.tr1, tile.drawx(), tile.drawy());
|
||||
Graphics.shader(Shaders.build, false);
|
||||
Shaders.build.apply();
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Graphics.shader();
|
||||
|
||||
Draw.color("accent");
|
||||
|
||||
Lines.lineAngleCenter(
|
||||
tile.drawx() + Mathf.sin(Timers.time(), 5f, Vars.tilesize/2f*size - 2f),
|
||||
tile.drawx() + Mathf.sin(entity.time, 6f, Vars.tilesize/2f*size - 2f),
|
||||
tile.drawy(),
|
||||
90,
|
||||
size * Vars.tilesize - 4f);
|
||||
@ -83,17 +86,18 @@ public class UnitFactory extends Block {
|
||||
entity.power.amount >= used){
|
||||
|
||||
entity.buildTime += Timers.delta();
|
||||
entity.time += Timers.delta();
|
||||
entity.power.amount -= used;
|
||||
}
|
||||
|
||||
if(entity.buildTime >= produceTime){
|
||||
BaseUnit unit = new BaseUnit(type, tile.getTeam());
|
||||
unit.set(tile.drawx(), tile.drawy()).add();
|
||||
unit.velocity.y = 4f;
|
||||
entity.buildTime = 0f;
|
||||
if(entity.buildTime >= produceTime){
|
||||
BaseUnit unit = new BaseUnit(type, tile.getTeam());
|
||||
unit.set(tile.drawx(), tile.drawy()).add();
|
||||
unit.velocity.y = 4f;
|
||||
entity.buildTime = 0f;
|
||||
|
||||
for(ItemStack stack : requirements){
|
||||
entity.inventory.removeItem(stack.item, stack.amount);
|
||||
}
|
||||
for(ItemStack stack : requirements){
|
||||
entity.inventory.removeItem(stack.item, stack.amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,6 +128,7 @@ public class UnitFactory extends Block {
|
||||
|
||||
public static class UnitFactoryEntity extends TileEntity{
|
||||
public float buildTime;
|
||||
public float time;
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
|