From 2ad72f0de92a081b374ae2cc39e4d30d362055db Mon Sep 17 00:00:00 2001 From: vinceh121 Date: Thu, 28 Dec 2023 04:15:13 +0100 Subject: [PATCH] feat: progress towards 1:1 sky properties --- android/assets/skies.json | 220 +++++++++++++++--- .../vinceh121/wanderer/glx/SkyProperties.java | 16 +- .../wanderer/glx/SkyboxRenderer.java | 20 +- .../wanderer/tools/WeatherCommand.java | 52 +++-- 4 files changed, 238 insertions(+), 70 deletions(-) diff --git a/android/assets/skies.json b/android/assets/skies.json index 83c4bba..65646e3 100644 --- a/android/assets/skies.json +++ b/android/assets/skies.json @@ -1,6 +1,54 @@ { "normal": { "sunColor": { + "0.75": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.875": { + "r": 0.439216, + "g": 0.090196, + "b": 0.0, + "a": 0.0 + }, + "0.0": { + "r": 1.0, + "g": 1.0, + "b": 0.109804, + "a": 0.0 + }, + "0.125": { + "r": 1.0, + "g": 1.0, + "b": 1.0, + "a": 0.0 + }, + "0.25": { + "r": 1.0, + "g": 1.0, + "b": 1.0, + "a": 0.0 + }, + "0.375": { + "r": 1.0, + "g": 1.0, + "b": 1.0, + "a": 0.0 + }, + "0.5": { + "r": 0.486275, + "g": 0.266667, + "b": 0.113725, + "a": 0.0 + }, + "0.625": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + } }, "sunLightColor": { "0": { @@ -41,35 +89,53 @@ } }, "ambLightColor": { - "0": { - "r": 0.4, - "g": 0.4, - "b": 0.4, - "a": 1.0 + "0.75": { + "r": 0.184314, + "g": 0.227451, + "b": 0.25098, + "a": 0.0 + }, + "0.875": { + "r": 0.3, + "g": 0.1, + "b": 0.0, + "a": 0.0 + }, + "0.0": { + "r": 0.3, + "g": 0.1, + "b": 0.0, + "a": 0.0 + }, + "0.125": { + "r": 0.054902, + "g": 0.137255, + "b": 0.152941, + "a": 0.0 }, "0.25": { - "r": 0.6, - "g": 0.6, - "b": 0.6, - "a": 1.0 + "r": 0.090196, + "g": 0.196078, + "b": 0.223529, + "a": 0.0 }, - "0.625": { - "r": 0.5, - "g": 0.5, - "b": 0.5, - "a": 1.0 + "0.375": { + "r": 0.07451, + "g": 0.101961, + "b": 0.101961, + "a": 0.0 }, - "0.75": { - "r": 0.3, - "g": 0.3, - "b": 0.3, - "a": 1.0 + "0.5": { + "r": 0.466667, + "g": 0.05098, + "b": 0.05098, + "a": 0.0 }, - "0.875": { - "r": 0.5, - "g": 0.5, - "b": 0.5, - "a": 1.0 + "0.625": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 } }, "skyTopColor": { @@ -158,15 +224,105 @@ "a": 0 } }, - "starsOpacity": { - "0.5": 0, - "0.75": 1, - "1": 0 + "starsColor": { + "0.75": { + "r": 1.0, + "g": 1.0, + "b": 1.0, + "a": 1.0 + }, + "0.875": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.0": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.125": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.25": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.375": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.5": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.0 + }, + "0.625": { + "r": 0.784314, + "g": 0.784314, + "b": 0.784314, + "a": 0.0 + } }, - "galaxyOpacity": { - "0.5": 0, - "0.75": 1, - "1": 0 + "galaxyColor": { + "0.75": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.2 + }, + "0.875": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.151 + }, + "0.0": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.192 + }, + "0.125": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.151 + }, + "0.2476852": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.11 + }, + "0.375": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.226 + }, + "0.5": { + "r": 0.5, + "g": 0.5, + "b": 0.5, + "a": 0.075 + }, + "0.625": { + "r": 0.0, + "g": 0.0, + "b": 0.0, + "a": 0.349 + } } } } diff --git a/core/src/me/vinceh121/wanderer/glx/SkyProperties.java b/core/src/me/vinceh121/wanderer/glx/SkyProperties.java index bd9a2a5..276f1fc 100644 --- a/core/src/me/vinceh121/wanderer/glx/SkyProperties.java +++ b/core/src/me/vinceh121/wanderer/glx/SkyProperties.java @@ -13,8 +13,8 @@ public class SkyProperties { private final NavigableMap skyMiddleColor = new TreeMap<>(); private final NavigableMap skyBottomColor = new TreeMap<>(); private final NavigableMap sunShineColor = new TreeMap<>(); - private final NavigableMap starsOpacity = new TreeMap<>(); - private final NavigableMap galaxyOpacity = new TreeMap<>(); + private final NavigableMap starsColor = new TreeMap<>(); + private final NavigableMap galaxyColor = new TreeMap<>(); public NavigableMap getSunColor() { return sunColor; @@ -44,19 +44,19 @@ public NavigableMap getSunShineColor() { return sunShineColor; } - public NavigableMap getStarsOpacity() { - return starsOpacity; + public NavigableMap getStarsColor() { + return starsColor; } - public NavigableMap getGalaxyOpacity() { - return galaxyOpacity; + public NavigableMap getGalaxyColor() { + return galaxyColor; } @Override public String toString() { return "SkyProperties [sunColor=" + sunColor + ", sunLightColor=" + sunLightColor + ", ambLightColor=" + ambLightColor + ", skyTopColor=" + skyTopColor + ", skyMiddleColor=" + skyMiddleColor - + ", skyBottomColor=" + skyBottomColor + ", sunShineColor=" + sunShineColor + ", starsOpacity=" - + starsOpacity + ", galaxyOpacity=" + galaxyOpacity + "]"; + + ", skyBottomColor=" + skyBottomColor + ", sunShineColor=" + sunShineColor + ", starsColor=" + + starsColor + ", galaxyColor=" + galaxyColor + "]"; } } diff --git a/core/src/me/vinceh121/wanderer/glx/SkyboxRenderer.java b/core/src/me/vinceh121/wanderer/glx/SkyboxRenderer.java index 634a5d5..8b2ae5d 100644 --- a/core/src/me/vinceh121/wanderer/glx/SkyboxRenderer.java +++ b/core/src/me/vinceh121/wanderer/glx/SkyboxRenderer.java @@ -91,10 +91,12 @@ public void update(final float time) { this.previous = time; this.stars.transform.rotateRad(Vector3.Y, 0.02f * delta / 0.016666668f); - ((BlendingAttribute) this.stars.materials.get(0).get(BlendingAttribute.Type)).opacity = - 1 - this.interpolatedFloat(time, this.skyProperties.getStarsOpacity()); + ((ColorAttribute) this.stars.materials.get(0).get(ColorAttribute.Diffuse)).color + .set(this.interpolatedColor(time, this.skyProperties.getStarsColor())); this.move(this.sun, MathUtils.PI * 0.65f, time * MathUtils.PI2, 0.6f, 0); + ((ColorAttribute) this.sun.materials.get(0).get(ColorAttribute.Diffuse)).color + .set(this.interpolatedColor(time, this.skyProperties.getSunColor())); MathUtilsW.preciseSetFromSpherical(this.sunDir, MathUtils.PI * 0.65f, time * MathUtils.PI2); if (this.shader != null) { @@ -111,8 +113,8 @@ public void update(final float time) { this.move(this.mars, MathUtils.PI2 * time, 0.12f * MathUtils.PI2, 1f, 0); this.move(this.galaxy, MathUtils.sin(time * MathUtils.PI2) / 5 + MathUtils.PI * 0.1f, MathUtils.HALF_PI, 1f, 0); - ((BlendingAttribute) this.galaxy.materials.get(0).get(BlendingAttribute.Type)).opacity = - 1 - this.interpolatedFloat(time, this.skyProperties.getGalaxyOpacity()); + ((ColorAttribute) this.galaxy.materials.get(0).get(ColorAttribute.Diffuse)).color + .set(this.interpolatedColor(time, this.skyProperties.getGalaxyColor())); // skycap rotates counter clock-wise this.skycap.transform.rotateRad(Vector3.Y, 0.2f * delta / 0.016666668f); @@ -336,9 +338,11 @@ private ModelInstance makeStars(final Texture tex) { final Model model = WandererConstants.ASSET_MANAGER.get("orig/lib/stars/stars.obj", Model.class); final ModelInstance ins = new ModelInstance(model); ins.materials.get(0) - .set(new DepthTestAttribute(false), IntAttribute.createCullFace(0), TextureAttribute.createDiffuse(tex) -// ,new NoLightningAttribute() - ); + .set(new DepthTestAttribute(false), + IntAttribute.createCullFace(0), + TextureAttribute.createDiffuse(tex), + new NoLightningAttribute(), + ColorAttribute.createDiffuse(Color.CLEAR)); return ins; } @@ -374,7 +378,7 @@ public static float toDayProgress(int hour, int minutes) { return toDayProgress(hour * 60 + minutes); } - public static float toDayProgress(int dayMinutes) { + public static float toDayProgress(float dayMinutes) { return (dayMinutes / 1440f - 0.25f + 1) % 1f; } } diff --git a/tools/src/me/vinceh121/wanderer/tools/WeatherCommand.java b/tools/src/me/vinceh121/wanderer/tools/WeatherCommand.java index aae16e6..64c0532 100644 --- a/tools/src/me/vinceh121/wanderer/tools/WeatherCommand.java +++ b/tools/src/me/vinceh121/wanderer/tools/WeatherCommand.java @@ -11,6 +11,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.FloatNode; import com.fasterxml.jackson.databind.node.ObjectNode; import me.vinceh121.n2ae.script.ClassCommandCall; @@ -18,12 +19,17 @@ import me.vinceh121.n2ae.script.NOBClazz; import me.vinceh121.n2ae.script.NewCommandCall; import me.vinceh121.n2ae.script.tcl.TCLParser; +import me.vinceh121.wanderer.glx.SkyboxRenderer; import picocli.CommandLine.Command; import picocli.CommandLine.Option; @Command(name = "weather", description = { "Converts a weather object to a sky configuration" }) public class WeatherCommand implements Callable { - private static final Map IPOL_NAMES = Map.ofEntries(entry("amb_color", "ambLightColor")); + private static final Map IPOL_NAMES = Map.ofEntries(entry("amb_color", "ambLightColor"), + entry("sun1_em", "sunColor"), + entry("fog_color", "fogColor"), + entry("stars_em", "starsColor"), + entry("galaxy_diff", "galaxyColor")); private static final float DAY_LENGTH = 86400f; @Option(names = { "-i", "--input" }) @@ -53,7 +59,13 @@ public Integer call() throws Exception { ICommandCall call = parser.getCalls().get(i); if (call instanceof NewCommandCall && ((NewCommandCall) call).getClazz().getName().equals("nipol")) { - final String ipolName = getIpolName(((NewCommandCall) call).getVarName()); + final String pnIpolName = ((NewCommandCall) call).getVarName(); + final String ipolName = IPOL_NAMES.get(pnIpolName); + + if (ipolName == null) { + System.err.println("Unknown ipol " + pnIpolName); + continue; + } final ObjectNode ipol = mapper.createObjectNode(); doc.set(ipolName, ipol); @@ -73,20 +85,27 @@ public Integer call() throws Exception { final String cmd = ((ClassCommandCall) call).getPrototype().getName(); final Object[] arguments = ((ClassCommandCall) call).getArguments(); - final float time = ((float) arguments[1]) / DAY_LENGTH; + final float time = SkyboxRenderer.toDayProgress(((float) arguments[1]) / 60f); JsonNode keyFrame; if (cmd.equals("setkey4f")) { - ObjectNode keyFrameObj = mapper.createObjectNode(); - keyFrame = keyFrameObj; - - keyFrameObj.put("r", (float) arguments[2]); - keyFrameObj.put("g", (float) arguments[3]); - keyFrameObj.put("b", (float) arguments[4]); - keyFrameObj.put("a", (float) arguments[5]); + keyFrame = mapper.createObjectNode() + .put("r", (float) arguments[2]) + .put("g", (float) arguments[3]) + .put("b", (float) arguments[4]) + .put("a", (float) arguments[5]); + } else if (cmd.equals("setkey1f")) { + keyFrame = new FloatNode((float) arguments[2]); + } else if (cmd.equals("setkey2f")) { + keyFrame = mapper.createArrayNode().add((float) arguments[2]).add((float) arguments[3]); + } else if (cmd.equals("setkey3f")) { + keyFrame = mapper.createArrayNode() + .add((float) arguments[2]) + .add((float) arguments[3]) + .add((float) arguments[4]); } else { - continue; + throw new UnsupportedOperationException(cmd); } ipol.set(Float.toString(time), keyFrame); @@ -100,15 +119,4 @@ public Integer call() throws Exception { return 0; } - - private static String getIpolName(String pnName) { - String wName = IPOL_NAMES.get(pnName); - - if (wName == null) { - System.err.println("Unknown ipol " + pnName); - return pnName; - } else { - return wName; - } - } }