Add support for grayscale lighting, parchment lighting
This commit is contained in:
parent
9d7878c530
commit
6a99217676
5 changed files with 63 additions and 18 deletions
|
|
@ -37,6 +37,14 @@ public class Color {
|
|||
public final void setTransparent() {
|
||||
val = TRANSPARENT;
|
||||
}
|
||||
public final void setGrayscale() {
|
||||
int alpha = (val >> 24) & 0xFF;
|
||||
int red = (val >> 16) & 0xFF;
|
||||
int green = (val >> 8) & 0xFF;
|
||||
int blue = val & 0xFF;
|
||||
int gray = ((red * 76) + (green * 151) + (blue * 28)) / 255;
|
||||
setRGBA(gray, gray, gray, alpha);
|
||||
}
|
||||
public final void setColor(Color c) {
|
||||
val = c.val;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,7 +218,20 @@ public class ConfigurationNode implements Map<String, Object> {
|
|||
return null;
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
|
||||
public Color getColor(String path, String def) {
|
||||
String lclr = this.getString(path, def);
|
||||
if((lclr != null) && (lclr.startsWith("#"))) {
|
||||
try {
|
||||
int c = Integer.parseInt(lclr.substring(1), 16);
|
||||
return new Color((c>>16)&0xFF, (c>>8)&0xFF, c&0xFF);
|
||||
} catch (NumberFormatException nfx) {
|
||||
Log.severe("Invalid color value: " + lclr + " for '" + path + "'");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getList(String path) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.dynmap.Color;
|
|||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.DynmapWorld;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.MapManager;
|
||||
import org.dynmap.utils.LightLevels;
|
||||
import org.dynmap.utils.BlockStep;
|
||||
|
|
@ -14,6 +15,8 @@ public class ShadowHDLighting extends DefaultHDLighting {
|
|||
protected final int lightscale[]; /* scale skylight level (light = lightscale[skylight] */
|
||||
protected final boolean night_and_day; /* If true, render both day (prefix+'-day') and night (prefix) tiles */
|
||||
protected final boolean smooth;
|
||||
protected final boolean grayscale;
|
||||
protected final Color graytone;
|
||||
protected final boolean useWorldBrightnessTable;
|
||||
|
||||
public ShadowHDLighting(DynmapCore core, ConfigurationNode configuration) {
|
||||
|
|
@ -43,6 +46,8 @@ public class ShadowHDLighting extends DefaultHDLighting {
|
|||
lightscale[i] = i - (15-v);
|
||||
}
|
||||
smooth = configuration.getBoolean("smooth-lighting", MapManager.mapman.getSmoothLighting());
|
||||
grayscale = configuration.getBoolean("grayscale", false);
|
||||
graytone = configuration.getColor("graytone", null);
|
||||
}
|
||||
|
||||
private void applySmoothLighting(HDPerspectiveState ps, HDShaderState ss, Color incolor, Color[] outcolor, int[] shadowscale) {
|
||||
|
|
@ -215,6 +220,17 @@ public class ShadowHDLighting extends DefaultHDLighting {
|
|||
return lightlevel;
|
||||
}
|
||||
|
||||
private void checkGrayscale(Color[] outcolor) {
|
||||
if (grayscale) {
|
||||
outcolor[0].setGrayscale();
|
||||
if (graytone != null) outcolor[0].blendColor(graytone);
|
||||
if (outcolor.length > 1) {
|
||||
outcolor[1].setGrayscale();
|
||||
if (graytone != null) outcolor[1].blendColor(graytone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply lighting to given pixel colors (1 outcolor if normal, 2 if night/day) */
|
||||
public void applyLighting(HDPerspectiveState ps, HDShaderState ss, Color incolor, Color[] outcolor) {
|
||||
int[] shadowscale = null;
|
||||
|
|
@ -224,6 +240,7 @@ public class ShadowHDLighting extends DefaultHDLighting {
|
|||
shadowscale = defLightingTable;
|
||||
}
|
||||
applySmoothLighting(ps, ss, incolor, outcolor, shadowscale);
|
||||
checkGrayscale(outcolor);
|
||||
return;
|
||||
}
|
||||
LightLevels ll = null;
|
||||
|
|
@ -262,6 +279,7 @@ public class ShadowHDLighting extends DefaultHDLighting {
|
|||
}
|
||||
}
|
||||
}
|
||||
checkGrayscale(outcolor);
|
||||
}
|
||||
|
||||
private final void shadowColor(Color c, int lightlevel, int[] shadowscale) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import java.util.List;
|
|||
import org.dynmap.Color;
|
||||
import org.dynmap.ConfigurationNode;
|
||||
import org.dynmap.DynmapCore;
|
||||
import org.dynmap.Log;
|
||||
import org.dynmap.MapManager;
|
||||
import org.dynmap.common.DynmapCommandSender;
|
||||
import org.dynmap.exporter.OBJExport;
|
||||
|
|
@ -28,28 +27,16 @@ public class TopoHDShader implements HDShader {
|
|||
private BitSet hiddenids;
|
||||
private final int linespacing;
|
||||
|
||||
private Color readColor(String id, ConfigurationNode cfg) {
|
||||
String lclr = cfg.getString(id, null);
|
||||
if((lclr != null) && (lclr.startsWith("#"))) {
|
||||
try {
|
||||
int c = Integer.parseInt(lclr.substring(1), 16);
|
||||
return new Color((c>>16)&0xFF, (c>>8)&0xFF, c&0xFF);
|
||||
} catch (NumberFormatException nfx) {
|
||||
Log.severe("Invalid color value: " + lclr + " for '" + id + "'");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public TopoHDShader(DynmapCore core, ConfigurationNode configuration) {
|
||||
name = (String) configuration.get("name");
|
||||
|
||||
fillcolor = new Color[256]; /* Color by Y */
|
||||
/* Load defined colors from parameters */
|
||||
for(int i = 0; i < 256; i++) {
|
||||
fillcolor[i] = readColor("color" + i, configuration);
|
||||
fillcolor[i] = configuration.getColor("color" + i, null);
|
||||
}
|
||||
linecolor = readColor("linecolor", configuration);
|
||||
watercolor = readColor("watercolor", configuration);
|
||||
linecolor = configuration.getColor("linecolor", null);
|
||||
watercolor = configuration.getColor("watercolor", null);
|
||||
float wateralpha = configuration.getFloat("wateralpha", 1.0F);
|
||||
if (wateralpha < 1.0) {
|
||||
watercolor.setAlpha((int)(255 * wateralpha));
|
||||
|
|
|
|||
|
|
@ -80,5 +80,24 @@ lightings:
|
|||
shadowstrength: 0.5
|
||||
ambientlight: 4
|
||||
use-brightness-table: false
|
||||
|
||||
# Shadows enabled day mode - grayscale
|
||||
- class: org.dynmap.hdmap.ShadowHDLighting
|
||||
name: grayscale
|
||||
shadowstrength: 1.0
|
||||
grayscale: true
|
||||
smooth-lighting: true
|
||||
# Shadows enabled day mode - grayscale parchment
|
||||
- class: org.dynmap.hdmap.ShadowHDLighting
|
||||
name: parchment
|
||||
shadowstrength: 1.0
|
||||
grayscale: true
|
||||
graytone: '#ECE999'
|
||||
smooth-lighting: true
|
||||
# No shadows day mode - grayscale parchment
|
||||
- class: org.dynmap.hdmap.ShadowHDLighting
|
||||
name: parchment-noshadow
|
||||
grayscale: true
|
||||
graytone: '#ECE999'
|
||||
shadowstrength: 0.0
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue