Experimenting with light
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
#ifdef GL_ES
|
||||||
|
precision mediump float;
|
||||||
|
precision mediump int;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define steprad 0.13
|
||||||
|
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
uniform vec4 u_ambient;
|
||||||
|
|
||||||
|
varying vec4 v_color;
|
||||||
|
varying vec2 v_texCoord;
|
||||||
|
|
||||||
|
float stepped(float inp){
|
||||||
|
return inp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
vec4 color = texture2D(u_texture, v_texCoord.xy);
|
||||||
|
float rounded = stepped(color.a);
|
||||||
|
gl_FragColor = clamp(vec4(mix(u_ambient.rgb, color.rgb, rounded), u_ambient.a - rounded), 0.0, 1.0);
|
||||||
|
}
|
||||||
@@ -33,6 +33,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
public final BlockRenderer blocks = new BlockRenderer();
|
public final BlockRenderer blocks = new BlockRenderer();
|
||||||
public final MinimapRenderer minimap = new MinimapRenderer();
|
public final MinimapRenderer minimap = new MinimapRenderer();
|
||||||
public final OverlayRenderer overlays = new OverlayRenderer();
|
public final OverlayRenderer overlays = new OverlayRenderer();
|
||||||
|
public final LightRenderer lights = new LightRenderer();
|
||||||
public final Pixelator pixelator = new Pixelator();
|
public final Pixelator pixelator = new Pixelator();
|
||||||
|
|
||||||
public FrameBuffer shieldBuffer = new FrameBuffer(2, 2);
|
public FrameBuffer shieldBuffer = new FrameBuffer(2, 2);
|
||||||
@@ -297,6 +298,8 @@ public class Renderer implements ApplicationListener{
|
|||||||
|
|
||||||
playerGroup.draw(p -> !p.isDead(), Player::drawName);
|
playerGroup.draw(p -> !p.isDead(), Player::drawName);
|
||||||
|
|
||||||
|
lights.draw();
|
||||||
|
|
||||||
drawLanding();
|
drawLanding();
|
||||||
|
|
||||||
Draw.color();
|
Draw.color();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import io.anuke.mindustry.entities.bullet.*;
|
|||||||
import io.anuke.mindustry.entities.effect.*;
|
import io.anuke.mindustry.entities.effect.*;
|
||||||
import io.anuke.mindustry.entities.traits.*;
|
import io.anuke.mindustry.entities.traits.*;
|
||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
|
import io.anuke.mindustry.graphics.*;
|
||||||
import io.anuke.mindustry.world.*;
|
import io.anuke.mindustry.world.*;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
@@ -294,6 +295,7 @@ public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Pool
|
|||||||
@Override
|
@Override
|
||||||
public void draw(){
|
public void draw(){
|
||||||
type.draw(this);
|
type.draw(this);
|
||||||
|
renderer.lights.add(x, y, 16f, Pal.powerLight, 0.3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -341,6 +341,8 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
|
renderer.lights.add(x, y, 100f, Pal.powerLight, 0.6f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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 UnitBuild build;
|
||||||
public static FogShader fog;
|
public static FogShader fog;
|
||||||
public static MenuShader menu;
|
public static MenuShader menu;
|
||||||
|
public static LightShader light;
|
||||||
public static SurfaceShader water, tar;
|
public static SurfaceShader water, tar;
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
@@ -30,10 +31,25 @@ public class Shaders{
|
|||||||
build = new UnitBuild();
|
build = new UnitBuild();
|
||||||
fog = new FogShader();
|
fog = new FogShader();
|
||||||
menu = new MenuShader();
|
menu = new MenuShader();
|
||||||
|
light = new LightShader();
|
||||||
water = new SurfaceShader("water");
|
water = new SurfaceShader("water");
|
||||||
tar = new SurfaceShader("tar");
|
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{
|
public static class MenuShader extends LoadShader{
|
||||||
float time = 0f;
|
float time = 0f;
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,19 @@
|
|||||||
package io.anuke.mindustry.world.blocks.power;
|
package io.anuke.mindustry.world.blocks.power;
|
||||||
|
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.*;
|
||||||
import io.anuke.arc.graphics.Color;
|
import io.anuke.arc.graphics.*;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.*;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.math.*;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.util.*;
|
||||||
import io.anuke.arc.util.Time;
|
import io.anuke.mindustry.content.*;
|
||||||
import io.anuke.mindustry.content.Fx;
|
import io.anuke.mindustry.entities.*;
|
||||||
import io.anuke.mindustry.entities.Effects;
|
import io.anuke.mindustry.entities.type.*;
|
||||||
import io.anuke.mindustry.entities.type.TileEntity;
|
import io.anuke.mindustry.type.*;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.world.*;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.world.consumers.*;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.meta.*;
|
||||||
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 static io.anuke.mindustry.Vars.content;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.tilesize;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Power generation block which can use items, liquids or both as input sources for power production.
|
* 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.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||||
Draw.color();
|
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){
|
protected float getItemEfficiency(Item item){
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import io.anuke.arc.math.Mathf;
|
|||||||
import io.anuke.arc.util.Time;
|
import io.anuke.arc.util.Time;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.Vars.renderer;
|
||||||
|
|
||||||
/** A GenericCrafter with a new glowing region drawn on top. */
|
/** A GenericCrafter with a new glowing region drawn on top. */
|
||||||
public class GenericSmelter extends GenericCrafter{
|
public class GenericSmelter extends GenericCrafter{
|
||||||
protected Color flameColor = Color.valueOf("ffc999");
|
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);
|
Fill.circle(tile.drawx(), tile.drawy(), 1.9f + Mathf.absin(Time.time(), 5f, 1f) + cr);
|
||||||
|
|
||||||
Draw.color();
|
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