Rework cave shader - make default proportional for variable world height

This commit is contained in:
Michael Primm 2023-03-23 13:27:33 -05:00
parent 76649c6250
commit ab900740b7
7 changed files with 70 additions and 29 deletions

View File

@ -43,8 +43,8 @@ public class CaveHDShader implements HDShader {
public CaveHDShader(DynmapCore core, ConfigurationNode configuration) { public CaveHDShader(DynmapCore core, ConfigurationNode configuration) {
name = (String) configuration.get("name"); name = (String) configuration.get("name");
iflit = configuration.getBoolean("onlyiflit", false); iflit = configuration.getBoolean("onlyiflit", false);
startColor = configuration.getColor("startColor", "#0000FF"); startColor = configuration.getColor("startColor", null);
endColor = configuration.getColor("endColor", "#00FF00"); endColor = configuration.getColor("endColor", null);
for (int i = 0; i < DynmapBlockState.getGlobalIndexMax(); i++) { for (int i = 0; i < DynmapBlockState.getGlobalIndexMax(); i++) {
DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(i); DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(i);
if (bs.isAir() || bs.isWater()) { if (bs.isAir() || bs.isWater()) {
@ -118,19 +118,17 @@ public class CaveHDShader implements HDShader {
protected MapIterator mapiter; protected MapIterator mapiter;
protected HDMap map; protected HDMap map;
private boolean air; private boolean air;
private int yshift; private final int sealevel;
private final int ymax, ymin;
final int[] lightingTable; final int[] lightingTable;
private OurShaderState(MapIterator mapiter, HDMap map, MapChunkCache cache) { private OurShaderState(MapIterator mapiter, HDMap map, MapChunkCache cache) {
this.mapiter = mapiter; this.mapiter = mapiter;
this.map = map; this.map = map;
this.color = new Color(); this.color = new Color();
int wheight = mapiter.getWorldHeight(); this.ymax = mapiter.getWorldHeight() - 1;
yshift = 0; this.ymin = mapiter.getWorldYMin();
while(wheight > 128) { this.sealevel = mapiter.getWorldSeaLevel();
wheight >>= 1;
yshift++;
}
if (MapManager.mapman.useBrightnessTable()) { if (MapManager.mapman.useBrightnessTable()) {
lightingTable = cache.getWorld().getBrightnessTable(); lightingTable = cache.getWorld().getBrightnessTable();
} }
@ -192,30 +190,22 @@ public class CaveHDShader implements HDShader {
int cr, cg, cb; int cr, cg, cb;
int mult; int mult;
int ys = mapiter.getY() >> yshift; int y = mapiter.getY();
if(startColor.getARGB() != 0xFF0000FF && endColor.getARGB() != 0xFF00FF00) if((startColor != null) && (endColor != null))
{ {
if (startColor.getRed() + ys < 255) double interp = ((double)(y - this.ymin)) / (this.ymax - this.ymin);
cr = startColor.getRed() + ys * endColor.getRed(); cr = (int)(((1.0 - interp) * startColor.getRed()) + (interp * endColor.getRed()));
else cg = (int)(((1.0 - interp) * startColor.getGreen()) + (interp * endColor.getGreen()));
cr = startColor.getRed() - ys * endColor.getRed(); cb = (int)(((1.0 - interp) * startColor.getBlue()) + (interp * endColor.getBlue()));
if (startColor.getGreen() + ys < 255)
cg = startColor.getGreen() + ys * endColor.getGreen();
else
cg = startColor.getGreen() - ys * endColor.getGreen();
if (startColor.getBlue() + ys < 255)
cb = startColor.getBlue() + ys * endColor.getBlue();
else
cb = startColor.getBlue() - ys * endColor.getBlue();
} }
else else
{ {
if (ys < 64) { if (y < this.sealevel) {
cr = 0; cr = 0;
cg = 64 + ys * 3; cg = 64 + ((192 * (y - this.ymin)) / (this.sealevel - this.ymin));
cb = 255 - ys * 4; cb = 255 - (255 * (y - this.ymin)) / (this.sealevel - this.ymin);
} else { } else {
cr = (ys - 64) * 4; cr = (255 * (y - this.sealevel)) / (this.ymax - this.sealevel);
cg = 255; cg = 255;
cb = 0; cb = 0;
} }

View File

@ -18,7 +18,6 @@ import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.MapTile; import org.dynmap.MapTile;
import org.dynmap.MapType; import org.dynmap.MapType;
import org.dynmap.MapType.ImageFormat;
import org.dynmap.MapTypeState; import org.dynmap.MapTypeState;
import org.dynmap.markers.impl.MarkerAPIImpl; import org.dynmap.markers.impl.MarkerAPIImpl;
import org.dynmap.renderer.DynmapBlockState; import org.dynmap.renderer.DynmapBlockState;

View File

@ -106,10 +106,18 @@ public interface MapIterator extends MapDataContext {
*/ */
BlockStep getLastStep(); BlockStep getLastStep();
/** /**
* Get world height * Get world height (yMax+1)
* @return height * @return height
*/ */
int getWorldHeight(); int getWorldHeight();
/**
* Get world bottom (yMin)
*/
int getWorldYMin();
/**
* Get world sealevel
*/
int getWorldSeaLevel();
/** /**
* Get block key for current position (unique ID for block within cache being iterated) * Get block key for current position (unique ID for block within cache being iterated)
* @return block key * @return block key

View File

@ -97,6 +97,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
private DynmapBlockState type = null; private DynmapBlockState type = null;
private final int worldheight; private final int worldheight;
private final int ymin; private final int ymin;
private final int sealevel;
private final int x_base; private final int x_base;
private final int z_base; private final int z_base;
@ -108,6 +109,7 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
initialize(x0, y0, z0); initialize(x0, y0, z0);
worldheight = w.getMaxHeight(); worldheight = w.getMaxHeight();
ymin = dw.minY; ymin = dw.minY;
sealevel = dw.sealevel;
} }
@Override @Override
@ -587,6 +589,14 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
return worldheight; return worldheight;
} }
@Override @Override
public int getWorldYMin() {
return ymin;
}
@Override
public int getWorldSeaLevel() {
return sealevel;
}
@Override
public long getBlockKey() { public long getBlockKey() {
return (((chunkindex * (worldheight - ymin)) + (y - ymin)) << 8) | (bx << 4) | bz; return (((chunkindex * (worldheight - ymin)) + (y - ymin)) << 8) | (bx << 4) | bz;
} }

View File

@ -109,6 +109,7 @@ public class ForgeMapChunkCache extends MapChunkCache
private BlockStep laststep; private BlockStep laststep;
private DynmapBlockState blk; private DynmapBlockState blk;
private final int worldheight; private final int worldheight;
private final int ymin, sealevel;
private final int x_base; private final int x_base;
private final int z_base; private final int z_base;
@ -124,6 +125,8 @@ public class ForgeMapChunkCache extends MapChunkCache
initialize(x0, y0, z0); initialize(x0, y0, z0);
worldheight = w.getHeight(); worldheight = w.getHeight();
ymin = 0;
sealevel = w.getSeaLevel();
} }
@Override @Override
public final void initialize(int x0, int y0, int z0) public final void initialize(int x0, int y0, int z0)
@ -719,6 +722,14 @@ public class ForgeMapChunkCache extends MapChunkCache
return worldheight; return worldheight;
} }
@Override @Override
public int getWorldYMin() {
return ymin;
}
@Override
public int getWorldSeaLevel() {
return sealevel;
}
@Override
public long getBlockKey() public long getBlockKey()
{ {
return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz; return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz;

View File

@ -106,6 +106,8 @@ public class ForgeMapChunkCache extends MapChunkCache
private BlockStep laststep; private BlockStep laststep;
private DynmapBlockState blk; private DynmapBlockState blk;
private final int worldheight; private final int worldheight;
private final int ymin;
private final int sealevel;
private final int x_base; private final int x_base;
private final int z_base; private final int z_base;
@ -121,6 +123,8 @@ public class ForgeMapChunkCache extends MapChunkCache
initialize(x0, y0, z0); initialize(x0, y0, z0);
worldheight = w.getHeight(); worldheight = w.getHeight();
ymin = 0;
sealevel = w.getSeaLevel();
} }
@Override @Override
public final void initialize(int x0, int y0, int z0) public final void initialize(int x0, int y0, int z0)
@ -716,6 +720,14 @@ public class ForgeMapChunkCache extends MapChunkCache
return worldheight; return worldheight;
} }
@Override @Override
public int getWorldYMin() {
return ymin;
}
@Override
public int getWorldSeaLevel() {
return sealevel;
}
@Override
public long getBlockKey() public long getBlockKey()
{ {
return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz; return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz;

View File

@ -106,6 +106,7 @@ public class ForgeMapChunkCache extends MapChunkCache
private BlockStep laststep; private BlockStep laststep;
private DynmapBlockState blk; private DynmapBlockState blk;
private final int worldheight; private final int worldheight;
private final int ymin, sealevel;
private final int x_base; private final int x_base;
private final int z_base; private final int z_base;
@ -121,6 +122,8 @@ public class ForgeMapChunkCache extends MapChunkCache
initialize(x0, y0, z0); initialize(x0, y0, z0);
worldheight = w.getHeight(); worldheight = w.getHeight();
ymin = 0;
sealevel = w.getSeaLevel();
} }
@Override @Override
public final void initialize(int x0, int y0, int z0) public final void initialize(int x0, int y0, int z0)
@ -716,6 +719,14 @@ public class ForgeMapChunkCache extends MapChunkCache
return worldheight; return worldheight;
} }
@Override @Override
public int getWorldYMin() {
return ymin;
}
@Override
public int getWorldSeaLevel() {
return sealevel;
}
@Override
public long getBlockKey() public long getBlockKey()
{ {
return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz; return (((chunkindex * worldheight) + y) << 8) | (bx << 4) | bz;