Water shader
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user