Animated oil blocks as well

This commit is contained in:
Anuken
2018-03-14 12:57:30 -04:00
parent 3056e9e79c
commit 99c12595a9
7 changed files with 243 additions and 34 deletions

View File

@ -0,0 +1,88 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define s2 vec4(255.0, 165.0, 0.0, 255.0) / 255.0
#define s1 vec4(255.0, 121.0, 62.0, 255.0) / 255.0
uniform sampler2D u_texture;
uniform vec2 camerapos;
uniform vec2 screensize;
uniform float time;
varying vec4 v_color;
varying vec2 v_texCoord;
float round(float num, float f){
return float(int(num / f)) * f;
}
vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
float snoise(vec2 v){
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
-0.577350269189626, 0.024390243902439);
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod(i, 289.0);
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),
dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
void main() {
vec2 c = v_texCoord.xy;
vec4 color = texture2D(u_texture, c);
vec2 v = vec2(1.0/screensize.x, 1.0/screensize.y);
ivec2 icoords = ivec2(int(c.x / v.x + camerapos.x), int(c.y / v.y + camerapos.y));
vec2 coords = vec2(float(icoords.x), float(icoords.y));
float stime = time / 5.0;
float mscl = 30.0;
float mth = 5.0;
//if there's something actually there
if(color.r > 0.01){
vec4 old = color;
color = texture2D(u_texture, c + vec2(sin(stime/3.0 + coords.y/0.75) * v.x, 0.0)) * vec4(0.9, 0.9, 1, 1.0);
color.a = 1.0;
if(color.r < 0.01){
color = old;
}
float n1 = snoise(coords / 20.0 + vec2(time) / 250.0);
float n2 = snoise((coords + vec2(632.0)) / 9.0 + vec2(0.0, -time) / 220.0);
float r = (n1 + n2) / 2.0;
if(r < -0.6){
color = s2;
}else if(r < -0.2 && r > -0.6){
color = s1;
}
}
gl_FragColor = color;
}

View File

@ -0,0 +1,86 @@
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define s1 vec4(63.0, 63.0, 63.0, 255.0) / 255.0
uniform sampler2D u_texture;
uniform vec2 camerapos;
uniform vec2 screensize;
uniform float time;
varying vec4 v_color;
varying vec2 v_texCoord;
float round(float num, float f){
return float(int(num / f)) * f;
}
vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
float snoise(vec2 v){
const vec4 C = vec4(0.211324865405187, 0.366025403784439,
-0.577350269189626, 0.024390243902439);
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);
vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;
i = mod(i, 289.0);
vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));
vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),
dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
void main() {
vec2 c = v_texCoord.xy;
vec4 color = texture2D(u_texture, c);
vec2 v = vec2(1.0/screensize.x, 1.0/screensize.y);
ivec2 icoords = ivec2(int(c.x / v.x + camerapos.x), int(c.y / v.y + camerapos.y));
vec2 coords = vec2(float(icoords.x), float(icoords.y));
float stime = time / 5.0;
float mscl = 30.0;
float mth = 5.0;
//if there's something actually there
if(color.r > 0.01){
vec4 old = color;
color = texture2D(u_texture, c + vec2(sin(stime/3.0 + coords.y/0.75) * v.x, 0.0)) * vec4(0.9, 0.9, 1, 1.0);
color.a = 1.0;
if(color.r < 0.01){
color = old;
}
float n1 = snoise(coords / 20.0 + vec2(-time) / 340.0);
float n2 = snoise((coords + vec2(632.0)) / 7.0 + vec2(0.0, time) / 310.0);
float r = (n1 + n2) / 2.0;
if(r < -0.3 && r > -0.6){
color *= 1.3;
color.a = 1.0;
}
}
gl_FragColor = color;
}

View File

@ -1,5 +1,5 @@
#Autogenerated file. Do not modify.
#Tue Mar 13 22:34:33 EDT 2018
#Wed Mar 14 12:49:40 EDT 2018
version=release
androidBuildCode=491
name=Mindustry

View File

@ -1,9 +1,11 @@
package io.anuke.mindustry.graphics;
import com.badlogic.gdx.graphics.Color;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.graphics.CacheBatch;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Shader;
import static io.anuke.mindustry.Vars.renderer;
@ -11,26 +13,34 @@ public enum DrawLayer {
water{
@Override
public void begin(CacheBatch batch){
batch.setProjectionMatrix(Core.camera.combined);
Graphics.useBatch(batch.drawBatch());
Graphics.begin();
Graphics.surface(renderer.waterSurface);
beginShader(batch);
}
@Override
public void end(CacheBatch batch){
Graphics.surface();
Graphics.end();
endShader(batch, Shaders.water);
}
},
lava{
@Override
public void begin(CacheBatch batch){
beginShader(batch);
}
Graphics.popBatch();
@Override
public void end(CacheBatch batch){
endShader(batch, Shaders.lava);
}
},
oil{
@Override
public void begin(CacheBatch batch){
beginShader(batch);
}
Graphics.shader(Shaders.water);
Graphics.begin();
Draw.rect(renderer.waterSurface.texture(), Core.camera.position.x, Core.camera.position.y,
Core.camera.viewportWidth * Core.camera.zoom, -Core.camera.viewportHeight * Core.camera.zoom);
Graphics.end();
Graphics.shader();
@Override
public void end(CacheBatch batch){
endShader(batch, Shaders.oil);
}
},
normal,
@ -48,4 +58,27 @@ public enum DrawLayer {
Graphics.popBatch();
}
protected void beginShader(CacheBatch batch){
batch.setProjectionMatrix(Core.camera.combined);
Graphics.useBatch(batch.drawBatch());
Graphics.begin();
Graphics.surface(renderer.waterSurface);
Graphics.clear(Color.CLEAR);
}
public void endShader(CacheBatch batch, Shader shader){
Graphics.surface();
Graphics.end();
Graphics.popBatch();
Graphics.shader(shader);
Graphics.begin();
Draw.rect(renderer.waterSurface.texture(), Core.camera.position.x, Core.camera.position.y,
Core.camera.viewportWidth * Core.camera.zoom, -Core.camera.viewportHeight * Core.camera.zoom);
Graphics.end();
Graphics.shader();
}
}

View File

@ -13,25 +13,12 @@ import io.anuke.ucore.scene.ui.layout.Unit;
public class Shaders{
public static final Outline outline = new Outline();
public static final Shield shield = new Shield();
public static final Water water = new Water();
public static final SurfaceShader water = new SurfaceShader("water");
public static final SurfaceShader lava = new SurfaceShader("lava");
public static final SurfaceShader oil = new SurfaceShader("oil");
private static final Vector2 vec = new Vector2();
public static class Water extends Shader{
public Water(){
super("water", "default");
}
@Override
public void apply(){
shader.setUniformf("camerapos", Core.camera.position.x + Core.camera.zoom, Core.camera.position.y);
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
shader.setUniformf("time", Timers.time());
}
}
public static class Outline extends Shader{
public Color color = new Color();
public float lighten = 0f;
@ -46,7 +33,6 @@ public class Shaders{
shader.setUniformf("u_lighten", lighten);
shader.setUniformf("u_texsize", vec.set(region.getTexture().getWidth(), region.getTexture().getHeight()));
}
}
public static class Shield extends Shader{
@ -74,6 +60,20 @@ public class Shaders{
shader.setUniformf("u_texsize", vec.set(region.getTexture().getWidth() / scale,
region.getTexture().getHeight() / scale));
}
}
public static class SurfaceShader extends Shader{
public SurfaceShader(String frag){
super(frag, "default");
}
@Override
public void apply(){
shader.setUniformf("camerapos", Core.camera.position.x + Core.camera.zoom, Core.camera.position.y);
shader.setUniformf("screensize", Gdx.graphics.getWidth() / Core.cameraScale * Core.camera.zoom,
Gdx.graphics.getHeight() / Core.cameraScale * Core.camera.zoom);
shader.setUniformf("time", Timers.time());
}
}
}

View File

@ -23,7 +23,7 @@ public class Liquid {
heatCapacity = 0.2f;
}
},
lava = new Liquid("lava", Color.valueOf("ed5334")){
lava = new Liquid("lava", Color.valueOf("e37341")){
{
temperature = 0.7f;
viscosity = 0.8f;

View File

@ -49,6 +49,7 @@ public class Blocks{
solid = true;
liquidDrop = Liquid.lava;
liquid = true;
drawLayer = DrawLayer.lava;
}
@Override
@ -69,6 +70,7 @@ public class Blocks{
solid = true;
liquidDrop = Liquid.oil;
liquid = true;
drawLayer = DrawLayer.oil;
}
@Override