Shader cleanup

This commit is contained in:
Anuken
2019-02-26 13:11:49 -05:00
parent 0cb14461ba
commit 964d1a0d87
36 changed files with 1344 additions and 2321 deletions

View File

@@ -206,16 +206,13 @@ public class Mechs implements ContentList{
public void draw(Player player){
if(player.shootHeat <= 0.01f) return;
float alpha = Draw.getColor().a;
Shaders.build.progress = player.shootHeat;
Shaders.build.region = armorRegion;
Shaders.build.time = Time.time() / 10f;
Shaders.build.color.set(Pal.accent).a = player.shootHeat;
Draw.shader(Shaders.build);
Draw.alpha(1f);
Draw.rect(armorRegion, player.x, player.y, player.rotation);
Draw.shader(Shaders.mix);
Draw.color(1f, 1f, 1f, alpha);
Draw.shader();
}
};
@@ -295,16 +292,11 @@ public class Mechs implements ContentList{
public void draw(Player player){
float scl = scld(player);
if(scl < 0.01f) return;
float alpha = Draw.getColor().a;
Draw.shader();
Draw.color(Pal.lancerLaser);
Draw.alpha(scl/2f);
Draw.blend(Blending.additive);
Draw.rect(shield, player.x + Mathf.range(scl/2f), player.y + Mathf.range(scl/2f), player.rotation - 90);
Draw.blend();
Draw.shader(Shaders.mix);
Draw.color();
Draw.alpha(alpha);
}
float scld(Player player){

View File

@@ -342,7 +342,7 @@ public class Control implements ApplicationListener{
}
if(!mobile && Core.input.keyTap(Binding.screenshot) && !(scene.getKeyboardFocus() instanceof TextField) && !ui.chatfrag.chatOpen()){
renderer.takeMapScreenshot();
//renderer.takeMapScreenshot();
}
}else{

View File

@@ -2,10 +2,13 @@ package io.anuke.mindustry.core;
import io.anuke.arc.ApplicationListener;
import io.anuke.arc.Core;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.function.Predicate;
import io.anuke.arc.graphics.Camera;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.Pixmap;
import io.anuke.arc.graphics.PixmapIO;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.Lines;
import io.anuke.arc.graphics.g2d.SpriteBatch;
@@ -13,9 +16,7 @@ import io.anuke.arc.graphics.glutils.FrameBuffer;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.ScreenRecorder;
import io.anuke.arc.util.Time;
import io.anuke.arc.util.Tmp;
import io.anuke.arc.util.*;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.core.GameState.State;
@@ -256,12 +257,8 @@ public class Renderer implements ApplicationListener{
drawAndInterpolate(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawUnder);
drawAndInterpolate(playerGroup, p -> p.isFlying() == flying && p.getTeam() == team && !p.isDead(), Unit::drawUnder);
Shaders.mix.color.set(Color.WHITE);
Draw.shader(Shaders.mix, true);
drawAndInterpolate(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawAll);
drawAndInterpolate(playerGroup, p -> p.isFlying() == flying && p.getTeam() == team, Unit::drawAll);
Draw.shader();
blocks.drawTeamBlocks(Layer.turret, team);
drawAndInterpolate(unitGroups[team.ordinal()], u -> u.isFlying() == flying && !u.isDead(), Unit::drawOver);
@@ -296,31 +293,38 @@ public class Renderer implements ApplicationListener{
}
public void takeMapScreenshot(){
//TODO fix/implement
/*
//TODO implement properly
float vpW = camera.width, vpH = camera.height;
int w = world.width()*tilesize, h = world.height()*tilesize;
int pw = pixelSurface.width(), ph = pixelSurface.height();
disableUI = true;
pixelSurface.setSize(w, h, true);
Graphics.getEffectSurface().setSize(w, h, true);
FrameBuffer buffer = new FrameBuffer(w, h);
Vector2 prev = camera.position.cpy();
camera.width = w;
camera.height = h;
camera.position.x = w/2f + tilesize/2f;
camera.position.y = h/2f + tilesize/2f;
buffer.begin();
draw();
blocks.drawShadows();
buffer.end();
disableUI = false;
camera.width = vpW;
camera.height = vpH;
pixelSurface.getBuffer().begin();
buffer.begin();
byte[] lines = ScreenUtils.getFrameBufferPixels(0, 0, w, h, true);
for(int i = 0; i < lines.length; i+= 4){
lines[i + 3] = (byte)255;
}
pixelSurface.getBuffer().end();
buffer.end();
Pixmap fullPixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
@@ -329,10 +333,10 @@ public class Renderer implements ApplicationListener{
PixmapIO.writePNG(file, fullPixmap);
fullPixmap.dispose();
pixelSurface.setSize(pw, ph, false);
Graphics.getEffectSurface().setSize(pw, ph, false);
buffer.dispose();
camera.position.set(prev);
ui.showInfoFade(Core.bundle.format("screenshot", file.toString()));*/
ui.showInfoFade(Core.bundle.format("screenshot", file.toString()));
}
}

View File

@@ -13,7 +13,6 @@ import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.units.UnitState;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.meta.BlockFlag;
@@ -113,13 +112,13 @@ public abstract class FlyingUnit extends BaseUnit{
@Override
public void draw(){
Draw.alpha(Draw.getShader() != Shaders.mix ? 1f : hitTime / hitDuration);
Draw.mixcol(Color.WHITE, hitTime / hitDuration);
Draw.rect(type.region, x, y, rotation - 90);
drawWeapons();
drawItems();
Draw.alpha(1f);
Draw.mixcol();
}
public void drawWeapons(){

View File

@@ -12,7 +12,6 @@ import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.entities.units.UnitState;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
@@ -109,14 +108,14 @@ public abstract class GroundUnit extends BaseUnit{
@Override
public void draw(){
Draw.alpha(Draw.getShader() != Shaders.mix ? 1f : hitTime / hitDuration);
Draw.mixcol(Color.WHITE, hitTime / hitDuration);
float ft = Mathf.sin(walkTime * type.speed*5f, 6f, 2f + type.hitsize/15f);
Floor floor = getFloorOn();
if(floor.isLiquid){
Draw.tint(Color.WHITE, floor.liquidColor, 0.5f);
Draw.color(Color.WHITE, floor.liquidColor, 0.5f);
}
for(int i : Mathf.signs){
@@ -127,9 +126,9 @@ public abstract class GroundUnit extends BaseUnit{
}
if(floor.isLiquid){
Draw.tint(Color.WHITE, floor.liquidColor, drownTime * 0.4f);
Draw.color(Color.WHITE, floor.liquidColor, drownTime * 0.4f);
}else{
Draw.tint(Color.WHITE);
Draw.color(Color.WHITE);
}
Draw.rect(type.baseRegion, x, y, baseRotation - 90);
@@ -146,7 +145,7 @@ public abstract class GroundUnit extends BaseUnit{
drawItems();
Draw.alpha(1f);
Draw.mixcol();
}
@Override

View File

@@ -23,7 +23,6 @@ import io.anuke.mindustry.entities.traits.TargetTrait;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.input.Binding;
import io.anuke.mindustry.io.TypeIO;
import io.anuke.mindustry.net.Net;
@@ -285,11 +284,11 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
Floor floor = getFloorOn();
Draw.color();
Draw.alpha(Draw.getShader() != Shaders.mix ? 1f : hitTime / hitDuration);
Draw.mixcol(Color.WHITE, hitTime / hitDuration);
if(!mech.flying){
if(floor.isLiquid){
Draw.tint(Color.WHITE, floor.liquidColor, 0.5f);
Draw.color(Color.WHITE, floor.liquidColor, 0.5f);
}
float boostTrnsY = -boostHeat * 3f;
@@ -309,9 +308,9 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
}
if(floor.isLiquid){
Draw.tint(Color.WHITE, floor.liquidColor, drownTime);
Draw.color(Color.WHITE, floor.liquidColor, drownTime);
}else{
Draw.tint(Color.WHITE);
Draw.color(Color.WHITE);
}
Draw.rect(mech.region, x, y, rotation - 90);
@@ -344,13 +343,12 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
}
}
Draw.alpha(1f);
Draw.reset();
}
@Override
public void drawStats(){
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Time.time(), healthf() * 5f, 1f - healthf()));
Draw.alpha(hitTime / hitDuration);
Draw.rect(getPowerCellRegion(), x + Angles.trnsx(rotation, mech.cellTrnsY, 0f), y + Angles.trnsy(rotation, mech.cellTrnsY, 0f), rotation - 90);
Draw.color();
}

View File

@@ -365,7 +365,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
public void drawStats(){
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Time.time(), healthf()*5f, 1f - healthf()));
Draw.alpha(hitTime);
Draw.rect(getPowerCellRegion(), x, y, rotation - 90);
Draw.color();
}

View File

@@ -9,12 +9,43 @@ import io.anuke.arc.graphics.glutils.Shader;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.Matrix3;
import io.anuke.arc.util.Disposable;
import io.anuke.arc.util.Strings;
//TODO this class is a trainwreck, remove it
public class IndexedRenderer implements Disposable{
private final static int vsize = 5;
private Shader program = BatchShader.create();
private Shader program = new Shader(
Strings.join("\n",
"attribute vec4 " + Shader.POSITION_ATTRIBUTE + ";",
"attribute vec4 " + Shader.COLOR_ATTRIBUTE + ";",
"attribute vec2 " + Shader.TEXCOORD_ATTRIBUTE + "0;",
"uniform mat4 u_projTrans;",
"varying vec4 v_color;",
"varying vec2 v_texCoords;",
"",
"void main(){",
" v_color = " + Shader.COLOR_ATTRIBUTE + ";",
" v_color.a = v_color.a * (255.0/254.0);",
" v_texCoords = " + Shader.TEXCOORD_ATTRIBUTE + "0;",
" gl_Position = u_projTrans * " + Shader.POSITION_ATTRIBUTE + ";",
"}"),
Strings.join("\n",
"#ifdef GL_ES",
"#define LOWP lowp",
"precision mediump float;",
"#else",
"#define LOWP ",
"#endif",
"",
"varying LOWP vec4 v_color;",
"varying vec2 v_texCoords;",
"uniform sampler2D u_texture;",
"",
"void main(){",
" gl_FragColor = v_color * texture2D(u_texture, v_texCoords);",
"}"
));
private Mesh mesh;
private float[] tmpVerts = new float[vsize * 6];
private float[] vertices;

View File

@@ -10,23 +10,17 @@ import io.anuke.arc.util.Time;
public class Shaders{
public static Shadow shadow;
public static BlockBuild blockbuild;
public static BlockPreview blockpreview;
public static Shield shield;
public static UnitBuild build;
public static MixShader mix;
public static Shader fullMix;
public static FogShader fog;
public static MenuShader menu;
public static void init(){
shadow = new Shadow();
blockbuild = new BlockBuild();
blockpreview = new BlockPreview();
shield = new Shield();
build = new UnitBuild();
mix = new MixShader();
fog = new FogShader();
fullMix = new LoadShader("fullmix", "default");
menu = new MenuShader();
}
@@ -55,27 +49,13 @@ public class Shaders{
}
}
public static class MixShader extends LoadShader{
public Color color = new Color(Color.WHITE);
public MixShader(){
super("mix", "default");
}
@Override
public void apply(){
super.apply();
setUniformf("u_color", color);
}
}
public static class UnitBuild extends LoadShader{
public float progress, time;
public Color color = new Color();
public TextureRegion region;
public UnitBuild(){
super("build", "default");
super("unitbuild", "default");
}
@Override
@@ -126,23 +106,6 @@ public class Shaders{
}
}
public static class BlockPreview extends LoadShader{
public Color color = new Color();
public TextureRegion region = new TextureRegion();
public BlockPreview(){
super("blockpreview", "default");
}
@Override
public void apply(){
setUniformf("u_color", color);
setUniformf("u_uv", region.getU(), region.getV());
setUniformf("u_uv2", region.getU2(), region.getV2());
setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().getHeight());
}
}
public static class Shield extends LoadShader{
public Shield(){

View File

@@ -29,7 +29,6 @@ import io.anuke.mindustry.entities.type.Player;
import io.anuke.mindustry.entities.type.TileEntity;
import io.anuke.mindustry.entities.type.Unit;
import io.anuke.mindustry.graphics.Pal;
import io.anuke.mindustry.graphics.Shaders;
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
@@ -175,7 +174,7 @@ public class MobileInput extends InputHandler implements GestureListener{
float offset = request.block.offset();
TextureRegion region = request.block.icon(Icon.full);
Draw.alpha(Mathf.clamp((1f - request.scale) / 0.5f));
Draw.mixcol(Pal.accent, Mathf.clamp((1f - request.scale) / 0.5f));
Draw.tint(Color.WHITE, Pal.breakInvalid, request.redness);
Draw.rect(region, tile.worldx() + offset, tile.worldy() + offset,
@@ -183,7 +182,7 @@ public class MobileInput extends InputHandler implements GestureListener{
region.getHeight() * request.scale * Draw.scl,
request.block.rotate ? request.rotation * 90 : 0);
Draw.alpha(1f);
Draw.mixcol(Pal.accent, 1f);
for(int i = 0; i < 4; i++){
Point2 p = Geometry.d8edge[i];
float poffset = -Math.max(request.block.size-1, 0)/2f * tilesize;
@@ -194,7 +193,7 @@ public class MobileInput extends InputHandler implements GestureListener{
Draw.color();
}else{
float rad = (tile.block().size * tilesize / 2f - 1) * request.scale;
Draw.alpha(0f);
Draw.mixcol();
//draw removing request
Draw.tint(Pal.removeBack);
Lines.square(tile.drawx(), tile.drawy()-1, rad);
@@ -289,9 +288,6 @@ public class MobileInput extends InputHandler implements GestureListener{
public void drawOutlined(){
Lines.stroke(1f);
Shaders.mix.color.set(Pal.accent);
Draw.shader(Shaders.mix);
//draw removals
for(PlaceRequest request : removals){
Tile tile = request.tile();
@@ -323,13 +319,12 @@ public class MobileInput extends InputHandler implements GestureListener{
//draw last placed request
if(!request.remove && request == lastPlaced && request.block != null){
Draw.alpha(0f);
Draw.mixcol();
request.block.drawPlace(tile.x, tile.y, rotation, validPlace(tile.x, tile.y, request.block, rotation));
}
}
Draw.shader();
Draw.mixcol();
Draw.color(Pal.accent);
//Draw lines

View File

@@ -148,7 +148,7 @@ public class MechPad extends Block{
TextureRegion region = mech.iconRegion;
if(entity.player.mech == mech){
region = (entity.player.isMobile ? Mechs.starterMobile : Mechs.starterDesktop).iconRegion;
region = (entity.player.mech == Mechs.starterDesktop ? Mechs.starterMobile : Mechs.starterDesktop).iconRegion;
}
Shaders.build.region = region;