Skip to content

Commit

Permalink
feat: sun shine alpha from PN scale
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceh121 committed Jan 14, 2024
1 parent 8f0e0c7 commit 33b999b
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 10 deletions.
100 changes: 100 additions & 0 deletions android/assets/story/singleplayer/chapter00/part01/skyIntro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
exports.skyIntro = {
"sunShineColor": {
"0.75": {
"r": 0.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
},
"0.875": {
"r": 0.101961,
"g": 0.0,
"b": 0.0,
"a": 0.0
},
"0.0": {
"r": 0.113725,
"g": 0.113725,
"b": 0.113725,
"a": 0.023999989
},
"0.125": {
"r": 0.160784,
"g": 0.160784,
"b": 0.2,
"a": 0.0
},
"0.25": {
"r": 0.247059,
"g": 0.247059,
"b": 0.247059,
"a": 0.0
},
"0.375": {
"r": 0.180392,
"g": 0.180392,
"b": 0.188235,
"a": 0.13200003
},
"0.5": {
"r": 0.290196,
"g": 0.070588,
"b": 0.0,
"a": 0.0
},
"0.625": {
"r": 0.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
}
},
"sunLightColor": {
"0.75": {
"r": 0.156863,
Expand Down Expand Up @@ -49,6 +99,56 @@ exports.skyIntro = {
"a": 0.0
}
},
"moonLightColor": {
"0.75": {
"r": 0.556863,
"g": 0.717647,
"b": 0.835294,
"a": 0.0
},
"0.875": {
"r": 0.184314,
"g": 0.223529,
"b": 0.25098,
"a": 0.0
},
"0.0": {
"r": 0.721569,
"g": 0.466667,
"b": 0.278431,
"a": 0.0
},
"0.125": {
"r": 0.082353,
"g": 0.266667,
"b": 0.301961,
"a": 0.0
},
"0.25": {
"r": 0.070588,
"g": 0.129412,
"b": 0.145098,
"a": 0.0
},
"0.375": {
"r": 0.180392,
"g": 0.211765,
"b": 0.207843,
"a": 0.0
},
"0.5": {
"r": 0.756863,
"g": 0.380392,
"b": 0.0,
"a": 0.0
},
"0.625": {
"r": 0.447059,
"g": 0.588235,
"b": 0.729412,
"a": 0.0
}
},
"ambLightColor": {
"0.75": {
"r": 0.184314,
Expand Down
5 changes: 5 additions & 0 deletions core/src/me/vinceh121/wanderer/glx/SkyProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class SkyProperties {
private final NavigableMap<Float, Color> sunColor = new TreeMap<>();
private final NavigableMap<Float, Color> sunLightColor = new TreeMap<>();
private final NavigableMap<Float, Color> moonLightColor = new TreeMap<>();
private final NavigableMap<Float, Color> ambLightColor = new TreeMap<>();
private final NavigableMap<Float, Color> skyTopColor = new TreeMap<>();
private final NavigableMap<Float, Color> skyMiddleColor = new TreeMap<>();
Expand All @@ -24,6 +25,10 @@ public NavigableMap<Float, Color> getSunLightColor() {
return sunLightColor;
}

public NavigableMap<Float, Color> getMoonLightColor() {
return moonLightColor;
}

public NavigableMap<Float, Color> getAmbLightColor() {
return ambLightColor;
}
Expand Down
5 changes: 4 additions & 1 deletion core/src/me/vinceh121/wanderer/glx/SkyboxRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public void update(final float time) {
this.shader.setSkyTop(this.interpolatedColor(time, this.skyProperties.getSkyTopColor()));
this.shader.setSkyMiddle(this.interpolatedColor(time, this.skyProperties.getSkyMiddleColor()));
this.shader.setSkyBottom(this.interpolatedColor(time, this.skyProperties.getSkyBottomColor()));
this.shader.setSunShine(this.interpolatedColor(time, this.skyProperties.getSunShineColor()));

// FIXME missing proper alpha
final Color sunShine = this.interpolatedColor(time, this.skyProperties.getSunShineColor());
this.shader.setSunShine(sunShine);
}

this.sunDir.scl(-1);
Expand Down
108 changes: 99 additions & 9 deletions tools/src/me/vinceh121/wanderer/tools/WeatherCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.DoubleSummaryStatistics;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.Callable;

import org.apache.commons.collections4.ListValuedMap;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -44,13 +48,15 @@
@Command(name = "weather", description = { "Converts a weather object to a sky configuration" })
public class WeatherCommand implements Callable<Integer> {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final Map<String, String> IPOL_NAMES = Map.ofEntries(entry("amb_color", "ambLightColor"),
entry("sun1_em", "sunColor"),
entry("fog_color", "fogColor"),
entry("stars_em", "starsColor"),
entry("galaxy_diff", "galaxyColor"),
entry("licht1_color", "sunLightColor"),
entry("licht2_color", "moonLightColor"));
private static final Map<String, ConversionEntry> IPOL_NAMES =
Map.ofEntries(entry("amb_color", new ConversionEntry("ambLightColor")),
entry("sun1_em", new ConversionEntry("sunColor")),
entry("fog_color", new ConversionEntry("fogColor")),
entry("stars_em", new ConversionEntry("starsColor")),
entry("galaxy_diff", new ConversionEntry("galaxyColor")),
entry("licht1_color", new ConversionEntry("sunLightColor")),
entry("licht2_color", new ConversionEntry("moonLightColor")),
entry("sun3_em", new ConversionEntry("sunShineColor").setAlphaFromScale("sun3_s")));

@Spec
private CommandSpec spec;
Expand Down Expand Up @@ -119,13 +125,15 @@ private ObjectNode buildSkyProp(File input, Map<String, NOBClazz> model) throws

if (call instanceof NewCommandCall && ((NewCommandCall) call).getClazz().getName().equals("nipol")) {
final String pnIpolName = ((NewCommandCall) call).getVarName();
final String ipolName = IPOL_NAMES.get(pnIpolName);
final ConversionEntry entry = IPOL_NAMES.get(pnIpolName);

if (ipolName == null) {
if (entry == null) {
System.err.println("Unknown ipol " + pnIpolName);
continue;
}

final String ipolName = entry.getName();

final ObjectNode ipol = MAPPER.createObjectNode();
doc.set(ipolName, ipol);

Expand Down Expand Up @@ -154,6 +162,11 @@ private ObjectNode buildSkyProp(File input, Map<String, NOBClazz> model) throws
.put("g", (float) arguments[3])
.put("b", (float) arguments[4])
.put("a", (float) arguments[5]);

if (entry.getAlphaFromScale() != null) {
((ObjectNode) keyFrame).put("a",
this.getAlphaForScale(parser.getCalls(), entry.getAlphaFromScale(), time));
}
} else if (cmd.equals("setkey1f")) {
keyFrame = new FloatNode((float) arguments[2]);
} else if (cmd.equals("setkey2f")) {
Expand Down Expand Up @@ -216,6 +229,56 @@ private ObjectNode buildSkyProp(File input, Map<String, NOBClazz> model) throws
return doc;
}

private Float getAlphaForScale(LinkedList<ICommandCall> calls, String scaleIpolName, float time) {
for (int i = 0; i < calls.size(); i++) {
ICommandCall call = calls.get(i);

if (call instanceof NewCommandCall && ((NewCommandCall) call).getClazz().getName().equals("nipol")
&& ((NewCommandCall) call).getVarName().equals(scaleIpolName)) {

call = calls.get(i++);

while (!(call instanceof ClassCommandCall)
|| !((ClassCommandCall) call).getPrototype().getName().equals("beginkeys")) {
call = calls.get(i++);
}

List<ICommandCall> sizeCalls = new Vector<>();
ICommandCall exactTimeCall = null;

int keys = (int) ((ClassCommandCall) call).getArguments()[0];

for (int j = 0; j < keys; j++) {
call = calls.get(i + j);

sizeCalls.add(call);

if (SkyboxRenderer
.toDayProgress(((Float) ((ClassCommandCall) call).getArguments()[1]) / 60f) == time) {
exactTimeCall = call;
}
}

if (exactTimeCall == null) {
return null;
}

DoubleSummaryStatistics stats = sizeCalls.stream()
.map(c -> (ClassCommandCall) c)
.mapToDouble(c -> (Float) c.getArguments()[2])
.summaryStatistics();

return MathUtils.map((float) stats.getMin(),
(float) stats.getMax(),
0,
1,
(Float) ((ClassCommandCall) exactTimeCall).getArguments()[2]);
}
}

return null;
}

private SkyPoint recognizeColors(List<Vertex> vertices) {
ListValuedMap<Float, Color> grouped = new ArrayListValuedHashMap<>();

Expand Down Expand Up @@ -275,6 +338,33 @@ public static Color average(Collection<Color> colors) {
return new Color(r, g, b, a);
}

private static class ConversionEntry {
private final String name;
private String alphaFromScale;

public ConversionEntry(String name) {
this.name = name;
}

public String getName() {
return name;
}

public String getAlphaFromScale() {
return alphaFromScale;
}

public ConversionEntry setAlphaFromScale(String alphaFromScale) {
this.alphaFromScale = alphaFromScale;
return this;
}

@Override
public String toString() {
return this.getName();
}
}

private static class SkyPoint {
private final Color top = new Color(), middle = new Color(), bottom = new Color();

Expand Down

0 comments on commit 33b999b

Please sign in to comment.