Add vertical speed support to parallax layers
This commit is contained in:
parent
063317bca8
commit
991cf9df7e
@ -13,7 +13,7 @@ ParallaxLayer::ParallaxLayer() {
|
|||||||
timeOfDayCorrelation = "";
|
timeOfDayCorrelation = "";
|
||||||
zLevel = 0;
|
zLevel = 0;
|
||||||
verticalOrigin = 0;
|
verticalOrigin = 0;
|
||||||
speed = 0;
|
speed = { 0, 0 };
|
||||||
unlit = false;
|
unlit = false;
|
||||||
lightMapped = false;
|
lightMapped = false;
|
||||||
fadePercent = 0;
|
fadePercent = 0;
|
||||||
@ -32,7 +32,7 @@ ParallaxLayer::ParallaxLayer(Json const& store) : ParallaxLayer() {
|
|||||||
zLevel = store.getFloat("zLevel");
|
zLevel = store.getFloat("zLevel");
|
||||||
parallaxOffset = jsonToVec2F(store.get("parallaxOffset"));
|
parallaxOffset = jsonToVec2F(store.get("parallaxOffset"));
|
||||||
timeOfDayCorrelation = store.getString("timeOfDayCorrelation");
|
timeOfDayCorrelation = store.getString("timeOfDayCorrelation");
|
||||||
speed = store.getFloat("speed");
|
speed = { store.getFloat("speed"), store.getFloat("speedY", 0.0f) };
|
||||||
unlit = store.getBool("unlit");
|
unlit = store.getBool("unlit");
|
||||||
lightMapped = store.getBool("lightMapped");
|
lightMapped = store.getBool("lightMapped");
|
||||||
fadePercent = store.getFloat("fadePercent");
|
fadePercent = store.getFloat("fadePercent");
|
||||||
@ -50,7 +50,8 @@ Json ParallaxLayer::store() const {
|
|||||||
{"zLevel", zLevel},
|
{"zLevel", zLevel},
|
||||||
{"parallaxOffset", jsonFromVec2F(parallaxOffset)},
|
{"parallaxOffset", jsonFromVec2F(parallaxOffset)},
|
||||||
{"timeOfDayCorrelation", timeOfDayCorrelation},
|
{"timeOfDayCorrelation", timeOfDayCorrelation},
|
||||||
{"speed", speed},
|
{"speed", speed[0]},
|
||||||
|
{"speedY", speed[1]},
|
||||||
{"unlit", unlit},
|
{"unlit", unlit},
|
||||||
{"lightMapped", lightMapped},
|
{"lightMapped", lightMapped},
|
||||||
{"fadePercent", fadePercent}};
|
{"fadePercent", fadePercent}};
|
||||||
@ -227,12 +228,19 @@ void Parallax::buildLayer(Json const& layerSettings, String const& kind) {
|
|||||||
|
|
||||||
layer.verticalOrigin = m_verticalOrigin;
|
layer.verticalOrigin = m_verticalOrigin;
|
||||||
layer.zLevel = layer.parallaxValue.sum();
|
layer.zLevel = layer.parallaxValue.sum();
|
||||||
layer.parallaxOffset = {layerSettings.getArray("offset", {0, 0})[0].toFloat(),
|
auto offset = layerSettings.getArray("offset", { 0, 0 });
|
||||||
layerSettings.getArray("offset", {0, 0})[1].toFloat()}; // shift from bottom left to horizon level in the image
|
layer.parallaxOffset = { offset[0].toFloat(), offset[1].toFloat() }; // shift from bottom left to horizon level in the image
|
||||||
if (!layerSettings.getBool("noRandomOffset", false))
|
if (!layerSettings.getBool("noRandomOffset", false))
|
||||||
layer.parallaxOffset[0] += rnd.randInt(imgMetadata->imageSize(layer.textures[0])[0]);
|
layer.parallaxOffset[0] += rnd.randInt(imgMetadata->imageSize(layer.textures[0])[0]);
|
||||||
layer.timeOfDayCorrelation = layerSettings.getString("timeOfDayCorrelation", "");
|
layer.timeOfDayCorrelation = layerSettings.getString("timeOfDayCorrelation", "");
|
||||||
layer.speed = rnd.randf(layerSettings.getFloat("minSpeed", 0), layerSettings.getFloat("maxSpeed", 0));
|
auto minSpeed = layerSettings.get("minSpeed", 0.0f);
|
||||||
|
auto maxSpeed = layerSettings.get("maxSpeed", 0.0f);
|
||||||
|
if (!minSpeed.isType(Json::Type::Array))
|
||||||
|
minSpeed = JsonArray{ minSpeed, 0.0f };
|
||||||
|
if (!maxSpeed.isType(Json::Type::Array))
|
||||||
|
maxSpeed = JsonArray{ maxSpeed, 0.0f };
|
||||||
|
layer.speed = { rnd.randf(minSpeed.getFloat(0), maxSpeed.getFloat(0)),
|
||||||
|
rnd.randf(minSpeed.getFloat(1), maxSpeed.getFloat(1)) };
|
||||||
layer.unlit = layerSettings.getBool("unlit", false);
|
layer.unlit = layerSettings.getBool("unlit", false);
|
||||||
layer.lightMapped = layerSettings.getBool("lightMapped", false);
|
layer.lightMapped = layerSettings.getBool("lightMapped", false);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ struct ParallaxLayer {
|
|||||||
float zLevel;
|
float zLevel;
|
||||||
Vec2F parallaxOffset;
|
Vec2F parallaxOffset;
|
||||||
String timeOfDayCorrelation;
|
String timeOfDayCorrelation;
|
||||||
float speed;
|
Vec2F speed;
|
||||||
bool unlit;
|
bool unlit;
|
||||||
bool lightMapped;
|
bool lightMapped;
|
||||||
float fadePercent;
|
float fadePercent;
|
||||||
|
@ -256,10 +256,14 @@ void EnvironmentPainter::renderParallaxLayers(
|
|||||||
|
|
||||||
// texture offset in *screen pixel space*
|
// texture offset in *screen pixel space*
|
||||||
Vec2F parallaxOffset = layer.parallaxOffset * camera.pixelRatio();
|
Vec2F parallaxOffset = layer.parallaxOffset * camera.pixelRatio();
|
||||||
if (layer.speed != 0) {
|
if (layer.speed[0] != 0) {
|
||||||
double drift = fmod((double)layer.speed * (sky.epochTime / (double)sky.dayLength), (double)parallaxSize[0]);
|
double drift = fmod((double)layer.speed[0] * (sky.epochTime / (double)sky.dayLength), (double)parallaxSize[0]);
|
||||||
parallaxOffset[0] = fmod(parallaxOffset[0] + drift * camera.pixelRatio(), parallaxPixels[0]);
|
parallaxOffset[0] = fmod(parallaxOffset[0] + drift * camera.pixelRatio(), parallaxPixels[0]);
|
||||||
}
|
}
|
||||||
|
if (layer.speed[1] != 0) {
|
||||||
|
double drift = fmod((double)layer.speed[1] * (sky.epochTime / (double)sky.dayLength), (double)parallaxSize[1]);
|
||||||
|
parallaxOffset[1] = fmod(parallaxOffset[1] + drift * camera.pixelRatio(), parallaxPixels[1]);
|
||||||
|
}
|
||||||
|
|
||||||
// parallax camera world position in *parallax space*
|
// parallax camera world position in *parallax space*
|
||||||
Vec2F parallaxCameraCenter = parallaxWorldPosition - parallaxOrigin;
|
Vec2F parallaxCameraCenter = parallaxWorldPosition - parallaxOrigin;
|
||||||
|
Loading…
Reference in New Issue
Block a user