Experimenting with light
This commit is contained in:
@@ -33,6 +33,7 @@ public class Renderer implements ApplicationListener{
|
||||
public final BlockRenderer blocks = new BlockRenderer();
|
||||
public final MinimapRenderer minimap = new MinimapRenderer();
|
||||
public final OverlayRenderer overlays = new OverlayRenderer();
|
||||
public final LightRenderer lights = new LightRenderer();
|
||||
public final Pixelator pixelator = new Pixelator();
|
||||
|
||||
public FrameBuffer shieldBuffer = new FrameBuffer(2, 2);
|
||||
@@ -297,6 +298,8 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
playerGroup.draw(p -> !p.isDead(), Player::drawName);
|
||||
|
||||
lights.draw();
|
||||
|
||||
drawLanding();
|
||||
|
||||
Draw.color();
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.anuke.mindustry.entities.bullet.*;
|
||||
import io.anuke.mindustry.entities.effect.*;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.graphics.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -294,6 +295,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
||||
@Override
|
||||
public void draw(){
|
||||
type.draw(this);
|
||||
renderer.lights.add(x, y, 16f, Pal.powerLight, 0.3f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -341,6 +341,8 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
|
||||
renderer.lights.add(x, y, 100f, Pal.powerLight, 0.6f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
47
core/src/io/anuke/mindustry/graphics/LightRenderer.java
Normal file
47
core/src/io/anuke/mindustry/graphics/LightRenderer.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.graphics.glutils.*;
|
||||
|
||||
public class LightRenderer{
|
||||
private static final int scaling = 4;
|
||||
private FrameBuffer buffer = new FrameBuffer(2, 2);
|
||||
private Array<Runnable> lights = new Array<>();
|
||||
|
||||
public void add(Runnable run){
|
||||
lights.add(run);
|
||||
}
|
||||
|
||||
public void add(float x, float y, float radius, Color color, float opacity){
|
||||
add(() -> {
|
||||
Draw.color(color, opacity);
|
||||
Draw.rect("circle-shadow", x, y, radius * 2, radius * 2);
|
||||
});
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
if(buffer.getWidth() != Core.graphics.getWidth()/scaling || buffer.getHeight() != Core.graphics.getHeight()/scaling){
|
||||
buffer.resize(Core.graphics.getWidth()/scaling, Core.graphics.getHeight()/scaling);
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
buffer.beginDraw(Color.clear);
|
||||
Draw.blend(Blending.additive);
|
||||
for(Runnable run : lights){
|
||||
run.run();
|
||||
}
|
||||
Draw.reset();
|
||||
Draw.blend();
|
||||
buffer.endDraw();
|
||||
|
||||
Draw.color();
|
||||
Draw.shader(Shaders.light);
|
||||
Draw.rect(Draw.wrap(buffer.getTexture()), Core.camera.position.x, Core.camera.position.y, Core.camera.width, -Core.camera.height);
|
||||
Draw.shader();
|
||||
|
||||
lights.clear();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class Shaders{
|
||||
public static UnitBuild build;
|
||||
public static FogShader fog;
|
||||
public static MenuShader menu;
|
||||
public static LightShader light;
|
||||
public static SurfaceShader water, tar;
|
||||
|
||||
public static void init(){
|
||||
@@ -30,10 +31,25 @@ public class Shaders{
|
||||
build = new UnitBuild();
|
||||
fog = new FogShader();
|
||||
menu = new MenuShader();
|
||||
light = new LightShader();
|
||||
water = new SurfaceShader("water");
|
||||
tar = new SurfaceShader("tar");
|
||||
}
|
||||
|
||||
public static class LightShader extends LoadShader{
|
||||
public Color ambient = new Color(0.01f, 0.01f, 0.04f, 0.99f);
|
||||
|
||||
public LightShader(){
|
||||
super("light", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
setUniformf("u_ambient", ambient);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class MenuShader extends LoadShader{
|
||||
float time = 0f;
|
||||
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.graphics.*;
|
||||
import io.anuke.arc.graphics.g2d.*;
|
||||
import io.anuke.arc.math.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.content.*;
|
||||
import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.consumers.*;
|
||||
import io.anuke.mindustry.world.meta.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
/**
|
||||
* Power generation block which can use items, liquids or both as input sources for power production.
|
||||
@@ -157,6 +152,8 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
renderer.lights.add(tile.drawx(), tile.drawy(), (60f + Mathf.absin(10f, 5f)) * entity.productionEfficiency * size, Color.orange, 0.5f);
|
||||
}
|
||||
|
||||
protected float getItemEfficiency(Item item){
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.renderer;
|
||||
|
||||
/** A GenericCrafter with a new glowing region drawn on top. */
|
||||
public class GenericSmelter extends GenericCrafter{
|
||||
protected Color flameColor = Color.valueOf("ffc999");
|
||||
@@ -43,6 +45,8 @@ public class GenericSmelter extends GenericCrafter{
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 1.9f + Mathf.absin(Time.time(), 5f, 1f) + cr);
|
||||
|
||||
Draw.color();
|
||||
|
||||
renderer.lights.add(tile.drawx(), tile.drawy(), (60f + Mathf.absin(10f, 5f)) * entity.warmup * size, flameColor, 0.65f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user