Reflective planet water

This commit is contained in:
Anuken
2020-04-02 12:32:55 -04:00
parent 19239a6890
commit a26cd46a7e
7 changed files with 22 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ attribute vec4 a_color;
uniform mat4 u_proj; uniform mat4 u_proj;
uniform mat4 u_trans; uniform mat4 u_trans;
uniform vec3 u_lightdir; uniform vec3 u_lightdir;
//uniform vec3 u_camdir; uniform vec3 u_camdir;
uniform vec3 u_ambientColor; uniform vec3 u_ambientColor;
varying vec4 v_col; varying vec4 v_col;
@@ -14,7 +14,12 @@ const vec3 diffuse = vec3(0);
void main(){ void main(){
vec3 norc = u_ambientColor * (diffuse + vec3(clamp((dot(a_normal, u_lightdir) + 1.0) / 2.0, 0.0, 1.0))); vec3 norc = u_ambientColor * (diffuse + vec3(clamp((dot(a_normal, u_lightdir) + 1.0) / 2.0, 0.0, 1.0)));
float falloff = 4.0;
float shinelen = 0.2;
float shinedot = max((-dot(u_camdir, a_normal) - (1.0 - shinelen)) / shinelen, 0.0);
float shinyness = (1.0 - a_color.a) * pow(shinedot, falloff);
vec4 baseCol = vec4(a_color.rgb, 1.0);
v_col = a_color * vec4(norc, 1.0); v_col = lerp(baseCol * vec4(norc, 1.0), vec4(1.0), shinyness * norc.r);
gl_Position = u_proj * u_trans * a_position; gl_Position = u_proj * u_trans * a_position;
} }

View File

@@ -133,6 +133,7 @@ public class Blocks implements ContentList{
statusDuration = 120f; statusDuration = 120f;
drownTime = 140f; drownTime = 140f;
cacheLayer = CacheLayer.water; cacheLayer = CacheLayer.water;
albedo = 0.5f;
}}; }};
water = new Floor("water"){{ water = new Floor("water"){{
@@ -143,6 +144,7 @@ public class Blocks implements ContentList{
liquidDrop = Liquids.water; liquidDrop = Liquids.water;
isLiquid = true; isLiquid = true;
cacheLayer = CacheLayer.water; cacheLayer = CacheLayer.water;
albedo = 0.5f;
}}; }};
taintedWater = new Floor("tainted-water"){{ taintedWater = new Floor("tainted-water"){{
@@ -154,6 +156,7 @@ public class Blocks implements ContentList{
liquidDrop = Liquids.water; liquidDrop = Liquids.water;
isLiquid = true; isLiquid = true;
cacheLayer = CacheLayer.water; cacheLayer = CacheLayer.water;
albedo = 0.5f;
}}; }};
darksandTaintedWater = new Floor("darksand-tainted-water"){{ darksandTaintedWater = new Floor("darksand-tainted-water"){{
@@ -164,6 +167,7 @@ public class Blocks implements ContentList{
liquidDrop = Liquids.water; liquidDrop = Liquids.water;
isLiquid = true; isLiquid = true;
cacheLayer = CacheLayer.water; cacheLayer = CacheLayer.water;
albedo = 0.5f;
}}; }};
sandWater = new Floor("sand-water"){{ sandWater = new Floor("sand-water"){{
@@ -174,6 +178,7 @@ public class Blocks implements ContentList{
liquidDrop = Liquids.water; liquidDrop = Liquids.water;
isLiquid = true; isLiquid = true;
cacheLayer = CacheLayer.water; cacheLayer = CacheLayer.water;
albedo = 0.5f;
}}; }};
darksandWater = new Floor("darksand-water"){{ darksandWater = new Floor("darksand-water"){{
@@ -184,6 +189,7 @@ public class Blocks implements ContentList{
liquidDrop = Liquids.water; liquidDrop = Liquids.water;
isLiquid = true; isLiquid = true;
cacheLayer = CacheLayer.water; cacheLayer = CacheLayer.water;
albedo = 0.5f;
}}; }};
tar = new Floor("tar"){{ tar = new Floor("tar"){{

View File

@@ -80,6 +80,7 @@ public class Shaders{
public static class PlanetShader extends LoadShader{ public static class PlanetShader extends LoadShader{
public Vec3 lightDir = new Vec3(1, 1, 1).nor(); public Vec3 lightDir = new Vec3(1, 1, 1).nor();
public Color ambientColor = Color.white.cpy(); public Color ambientColor = Color.white.cpy();
public Vec3 camDir = new Vec3();
public PlanetShader(){ public PlanetShader(){
super("planet", "planet"); super("planet", "planet");
@@ -89,6 +90,7 @@ public class Shaders{
public void apply(){ public void apply(){
setUniformf("u_lightdir", lightDir); setUniformf("u_lightdir", lightDir);
setUniformf("u_ambientColor", ambientColor.r, ambientColor.g, ambientColor.b); setUniformf("u_ambientColor", ambientColor.r, ambientColor.g, ambientColor.b);
setUniformf("u_camdir", camDir);
} }
} }

View File

@@ -60,8 +60,7 @@ public class TODOPlanetGenerator extends PlanetGenerator{
Block block = getBlock(position); Block block = getBlock(position);
//replace salt with sand color //replace salt with sand color
if(block == Blocks.salt) return Blocks.sand.mapColor; if(block == Blocks.salt) return Blocks.sand.mapColor;
//return block.asFloor().isLiquid ? Tmp.c1.set(block.mapColor).a(0.5f) : block.mapColor; return Tmp.c1.set(block.mapColor).a(1f - block.albedo);
return block.mapColor;
} }
@Override @Override

View File

@@ -177,6 +177,9 @@ public class PlanetDialog extends FloatingDialog{
cam.lookAt(planet.position); cam.lookAt(planet.position);
cam.update(); cam.update();
//TODO hacky
Shaders.planet.camDir.set(cam.direction).rotate(Vec3.Y, planet.getRotation());
projector.proj(cam.combined()); projector.proj(cam.combined());
batch.proj(cam.combined()); batch.proj(cam.combined());

View File

@@ -129,6 +129,8 @@ public class Block extends UnlockableContent{
public boolean hasShadow = true; public boolean hasShadow = true;
/** Sounds made when this block breaks.*/ /** Sounds made when this block breaks.*/
public Sound breakSound = Sounds.boom; public Sound breakSound = Sounds.boom;
/** How reflective this block is. */
public float albedo = 0f;
/** The sound that this block makes while active. One sound loop. Do not overuse.*/ /** The sound that this block makes while active. One sound loop. Do not overuse.*/
public Sound activeSound = Sounds.none; public Sound activeSound = Sounds.none;

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=50df607c88d697dc42b29b56947cda318f90d71b archash=da2913187aa724da769c6a80bc709eebb5bc0888