From 6a992176763bf1164b9319206748a1e9e1a00f88 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 2 May 2020 13:00:51 -0500 Subject: [PATCH] Add support for grayscale lighting, parchment lighting --- .../src/main/java/org/dynmap/Color.java | 8 +++++++ .../java/org/dynmap/ConfigurationNode.java | 15 ++++++++++++- .../org/dynmap/hdmap/ShadowHDLighting.java | 18 ++++++++++++++++ .../java/org/dynmap/hdmap/TopoHDShader.java | 19 +++-------------- DynmapCore/src/main/resources/lightings.txt | 21 ++++++++++++++++++- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/Color.java b/DynmapCore/src/main/java/org/dynmap/Color.java index 1aba01e1..31e6da2f 100644 --- a/DynmapCore/src/main/java/org/dynmap/Color.java +++ b/DynmapCore/src/main/java/org/dynmap/Color.java @@ -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; } diff --git a/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java b/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java index 9a8b21cb..69135bfc 100644 --- a/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java +++ b/DynmapCore/src/main/java/org/dynmap/ConfigurationNode.java @@ -218,7 +218,20 @@ public class ConfigurationNode implements Map { 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 List getList(String path) { try { diff --git a/DynmapCore/src/main/java/org/dynmap/hdmap/ShadowHDLighting.java b/DynmapCore/src/main/java/org/dynmap/hdmap/ShadowHDLighting.java index 3fd1d748..7731c825 100644 --- a/DynmapCore/src/main/java/org/dynmap/hdmap/ShadowHDLighting.java +++ b/DynmapCore/src/main/java/org/dynmap/hdmap/ShadowHDLighting.java @@ -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) { diff --git a/DynmapCore/src/main/java/org/dynmap/hdmap/TopoHDShader.java b/DynmapCore/src/main/java/org/dynmap/hdmap/TopoHDShader.java index d91700ae..d0e38be7 100644 --- a/DynmapCore/src/main/java/org/dynmap/hdmap/TopoHDShader.java +++ b/DynmapCore/src/main/java/org/dynmap/hdmap/TopoHDShader.java @@ -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)); diff --git a/DynmapCore/src/main/resources/lightings.txt b/DynmapCore/src/main/resources/lightings.txt index ad65dc65..6ea92158 100644 --- a/DynmapCore/src/main/resources/lightings.txt +++ b/DynmapCore/src/main/resources/lightings.txt @@ -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 + \ No newline at end of file