Water shader

This commit is contained in:
Anuken
2019-03-09 22:53:16 -05:00
parent 1316c9235a
commit 98212df076
10 changed files with 158 additions and 33 deletions

View File

@@ -44,7 +44,7 @@ public class Renderer implements ApplicationListener{
public final MinimapRenderer minimap = new MinimapRenderer();
public final OverlayRenderer overlays = new OverlayRenderer();
private FrameBuffer shieldBuffer = new FrameBuffer(2, 2);
public FrameBuffer shieldBuffer = new FrameBuffer(2, 2);
private Color clearColor;
private float targetscale = io.anuke.arc.scene.ui.layout.Unit.dp.scl(4);
private float camerascale = targetscale;
@@ -159,6 +159,10 @@ public class Renderer implements ApplicationListener{
graphics.clear(clearColor);
if(graphics.getWidth() >= 2 && graphics.getHeight() >= 2 && (shieldBuffer.getWidth() != graphics.getWidth() || shieldBuffer.getHeight() != graphics.getHeight())){
shieldBuffer.resize(graphics.getWidth(), graphics.getHeight());
}
Draw.proj(camera.projection());
blocks.floor.drawFloor();
@@ -200,10 +204,6 @@ public class Renderer implements ApplicationListener{
drawAndInterpolate(playerGroup, p -> true, Player::drawBuildRequests);
if(EntityDraw.countInBounds(shieldGroup) > 0){
if(graphics.getWidth() >= 2 && graphics.getHeight() >= 2 && (shieldBuffer.getWidth() != graphics.getWidth() || shieldBuffer.getHeight() != graphics.getHeight())){
shieldBuffer.resize(graphics.getWidth(), graphics.getHeight());
}
Draw.flush();
shieldBuffer.begin();
graphics.clear(Color.CLEAR);

View File

@@ -1,7 +1,38 @@
package io.anuke.mindustry.graphics;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import static io.anuke.arc.Core.camera;
import static io.anuke.mindustry.Vars.renderer;
public enum CacheLayer{
water,
water{
@Override
public void begin(){
if(!Core.settings.getBool("animatedwater")) return;
renderer.blocks.floor.endc();
renderer.shieldBuffer.begin();
Core.graphics.clear(Color.CLEAR);
renderer.blocks.floor.beginc();
}
@Override
public void end(){
if(!Core.settings.getBool("animatedwater")) return;
renderer.blocks.floor.endc();
renderer.shieldBuffer.end();
Draw.shader(Shaders.water);
Draw.rect(Draw.wrap(renderer.shieldBuffer.getTexture()), camera.position.x, camera.position.y, camera.width, -camera.height);
Draw.shader();
renderer.blocks.floor.beginc();
}
},
lava,
oil,
space,

View File

@@ -95,6 +95,14 @@ public class FloorRenderer{
endDraw();
}
public void beginc(){
cbatch.beginDraw();
}
public void endc(){
cbatch.endDraw();
}
public void beginDraw(){
if(cache == null){
return;
@@ -124,8 +132,6 @@ public class FloorRenderer{
int crangex = (int) (camera.width / (chunksize * tilesize)) + 1;
int crangey = (int) (camera.height / (chunksize * tilesize)) + 1;
SpriteBatch batch = Core.batch;
Core.batch = cbatch;
layer.begin();
for(int x = -crangex; x <= crangex; x++){
@@ -144,7 +150,6 @@ public class FloorRenderer{
}
layer.end();
Core.batch = batch;
}
private void cacheChunk(int cx, int cy){
@@ -191,6 +196,8 @@ public class FloorRenderer{
tile.block().draw(tile);
}else if(floor.cacheLayer == layer && (world.isAccessible(tile.x,tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
floor.draw(tile);
}else if(floor.cacheLayer.ordinal() < layer.ordinal() && layer != CacheLayer.walls){
floor.drawNonLayer(tile);
}
}
}

View File

@@ -14,6 +14,7 @@ public class Shaders{
public static UnitBuild build;
public static FogShader fog;
public static MenuShader menu;
public static SurfaceShader water;
public static void init(){
shadow = new Shadow();
@@ -22,6 +23,7 @@ public class Shaders{
build = new UnitBuild();
fog = new FogShader();
menu = new MenuShader();
water = new SurfaceShader("water");
}
public static class MenuShader extends LoadShader{
@@ -123,6 +125,20 @@ public class Shaders{
Core.camera.height );
}
}
public static class SurfaceShader extends LoadShader{
public SurfaceShader(String frag){
super(frag, "default");
}
@Override
public void apply(){
setUniformf("camerapos", Core.camera.position.x - Core.camera.width / 2, Core.camera.position.y - Core.camera.height / 2);
setUniformf("screensize", Core.camera.width, Core.camera.height);
setUniformf("time", Time.time());
}
}
public static class LoadShader extends Shader{
public LoadShader(String frag, String vert){

View File

@@ -195,6 +195,7 @@ public class SettingsMenuDialog extends SettingsDialog{
graphics.checkPref("fps", false);
graphics.checkPref("indicators", true);
graphics.checkPref("animatedwater", !mobile);
graphics.checkPref("lasers", true);
}

View File

@@ -114,13 +114,24 @@ public class Floor extends Block{
drawEdges(tile);
}
public void drawNonLayer(Tile tile){
Mathf.random.setSeed(tile.pos());
drawEdges(tile, true);
}
protected void drawEdges(Tile tile){
drawEdges(tile, false);
}
protected void drawEdges(Tile tile, boolean sameLayer){
eq = 0;
for(int i = 0; i < 8; i++){
Point2 point = Geometry.d8[i];
Tile other = tile.getNearby(point);
if(other != null && doEdge(other.floor()) && other.floor().edges() != null){
if(other != null && doEdge(other.floor(), sameLayer) && other.floor().edges() != null){
eq |= (1 << i);
}
}
@@ -140,8 +151,8 @@ public class Floor extends Block{
return ((Floor)blendGroup).edges;
}
protected boolean doEdge(Floor other){
return (other.blendGroup.id > blendGroup.id || edges() == null) && other.edgeOnto(this);
protected boolean doEdge(Floor other, boolean sameLayer){
return (other.blendGroup.id > blendGroup.id || edges() == null) && other.edgeOnto(this) && (other.cacheLayer.ordinal() > this.cacheLayer.ordinal() || !sameLayer);
}
protected boolean edgeOnto(Floor other){

View File

@@ -43,8 +43,8 @@ public class OreBlock extends Floor{
}
@Override
public boolean doEdge(Floor floor){
return floor != base && super.doEdge(floor);
public boolean doEdge(Floor floor, boolean f){
return floor != base && super.doEdge(floor, f);
}
@Override