Misc fog improvements

This commit is contained in:
Anuken
2022-03-01 10:24:20 -05:00
parent 8b51ba17ec
commit 97cbc3d345
23 changed files with 214 additions and 45 deletions

View File

@@ -412,7 +412,10 @@ public class BlockRenderer{
if(build != null){
if(visible){
if(!build.wasVisible) updateShadow(build);
if(!build.wasVisible){
updateShadow(build);
renderer.minimap.update(tile);
}
build.wasVisible = true;
}

View File

@@ -51,7 +51,7 @@ public final class FogRenderer{
dynamicFog.resize(world.width(), world.height());
if(player.team() != lastTeam){
if(state.rules.staticFog && player.team() != lastTeam){
copyFromCpu();
lastTeam = player.team();
clearStatic = false;
@@ -59,8 +59,6 @@ public final class FogRenderer{
//draw dynamic fog every frame
{
Core.camera.bounds(Tmp.r1);
Draw.proj(0, 0, staticFog.getWidth() * tilesize, staticFog.getHeight() * tilesize);
dynamicFog.begin(Color.black);
ScissorStack.push(rect.set(1, 1, staticFog.getWidth() - 2, staticFog.getHeight() - 2));
@@ -68,11 +66,11 @@ public final class FogRenderer{
Team team = player.team();
for(var build : indexer.getFlagged(team, BlockFlag.hasFogRadius)){
poly(Tmp.r1, build.x, build.y, build.block.fogRadius * tilesize);
poly(build.x, build.y, build.fogRadius() * tilesize);
}
for(var unit : team.data().units){
poly(Tmp.r1, unit.x, unit.y, unit.type.fogRadius * tilesize);
poly(unit.x, unit.y, unit.type.fogRadius * tilesize);
}
dynamicFog.end();
@@ -81,7 +79,7 @@ public final class FogRenderer{
}
//grab static events
if(clearStatic || events.size > 0){
if(state.rules.staticFog && (clearStatic || events.size > 0)){
//set projection to whole map
Draw.proj(0, 0, staticFog.getWidth(), staticFog.getHeight());
@@ -107,22 +105,23 @@ public final class FogRenderer{
Draw.proj(Core.camera);
}
staticFog.getTexture().setFilter(TextureFilter.linear);
if(state.rules.staticFog){
staticFog.getTexture().setFilter(TextureFilter.linear);
}
dynamicFog.getTexture().setFilter(TextureFilter.linear);
Draw.shader(Shaders.fog);
Draw.color(state.rules.dynamicColor);
Draw.fbo(dynamicFog.getTexture(), world.width(), world.height(), tilesize);
Draw.color(state.rules.staticColor);
Draw.fbo(staticFog.getTexture(), world.width(), world.height(), tilesize);
if(state.rules.staticFog){
Draw.color(state.rules.staticColor);
Draw.fbo(staticFog.getTexture(), world.width(), world.height(), tilesize);
}
Draw.shader();
}
void poly(Rect check, float x, float y, float rad){
//todo clipping messes up the minimap
//if(check.overlaps(x - rad, y - rad, rad * 2f, rad * 2f)){
void poly(float x, float y, float rad){
Fill.poly(x, y, 20, rad);
//}
}
void renderEvent(long e){

View File

@@ -150,7 +150,6 @@ public class MinimapRenderer{
Texture staticTex = renderer.fog.getStaticTexture(), dynamicTex = renderer.fog.getDynamicTexture();
//crisp pixels
staticTex.setFilter(TextureFilter.nearest);
dynamicTex.setFilter(TextureFilter.nearest);
Tmp.tr1.set(dynamicTex);
@@ -159,10 +158,14 @@ public class MinimapRenderer{
Draw.color(state.rules.dynamicColor);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Tmp.tr1.texture = staticTex;
//must be black to fit with borders
Draw.color(0f, 0f, 0f, state.rules.staticColor.a);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
if(state.rules.staticFog){
staticTex.setFilter(TextureFilter.nearest);
Tmp.tr1.texture = staticTex;
//must be black to fit with borders
Draw.color(0f, 0f, 0f, state.rules.staticColor.a);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
}
Draw.color();
Draw.shader();
@@ -252,13 +255,20 @@ public class MinimapRenderer{
Units.nearby((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize, units::add);
}
private Block realBlock(Tile tile){
//TODO dynamically update on visibility change; right now it's just entirely hidden
return tile.build == null ? tile.block() : state.rules.fog && tile.build.team != player.team() ? Blocks.air : tile.block();
}
private int colorFor(Tile tile){
if(tile == null) return 0;
int bc = tile.block().minimapColor(tile);
Color color = Tmp.c1.set(bc == 0 ? MapIO.colorFor(tile.block(), tile.floor(), tile.overlay(), tile.team()) : bc);
Block real = realBlock(tile);
int bc = real.minimapColor(tile);
Color color = Tmp.c1.set(bc == 0 ? MapIO.colorFor(real, tile.floor(), tile.overlay(), tile.team()) : bc);
color.mul(1f - Mathf.clamp(world.getDarkness(tile.x, tile.y) / 4f));
if(tile.block() == Blocks.air && tile.y < world.height() - 1 && world.tile(tile.x, tile.y + 1).block().solid){
if(real == Blocks.air && tile.y < world.height() - 1 && realBlock(world.tile(tile.x, tile.y + 1)).solid){
color.mul(0.7f);
}else if(tile.floor().isLiquid && (tile.y >= world.height() - 1 || !world.tile(tile.x, tile.y + 1).floor().isLiquid)){
color.mul(0.84f, 0.84f, 0.9f, 1f);