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

View File

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

View File

@ -106,10 +106,18 @@ public interface MapIterator extends MapDataContext {
*/
BlockStep getLastStep();
/**
* Get world height
* Get world height (yMax+1)
* @return height
*/
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)
* @return block key

View File

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

View File

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

View File

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