mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 17:56:03 +00:00
Re-add old image sampler to config-noise-function w/ deprecation notice
This commit is contained in:
@@ -18,6 +18,7 @@ import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.BinaryArithmeticTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.DomainWarpTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.ImageSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.KernelTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.LinearHeightmapSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.CellularNoiseTemplate;
|
||||
@@ -91,7 +92,9 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register(addon.key("PROBABILITY"), ProbabilityNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("SCALE"), ScaleNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("POSTERIZATION"), PosterizationNormalizerTemplate::new);
|
||||
|
||||
|
||||
noiseRegistry.register(addon.key("IMAGE"), ImageSamplerTemplate::new);
|
||||
|
||||
noiseRegistry.register(addon.key("DOMAIN_WARP"), DomainWarpTemplate::new);
|
||||
|
||||
noiseRegistry.register(addon.key("FBM"), BrownianMotionTemplate::new);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.noise.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.ImageSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImageSamplerTemplate.class);
|
||||
|
||||
private static boolean used = false;
|
||||
|
||||
@Value("image")
|
||||
private @Meta BufferedImage image;
|
||||
|
||||
@Value("frequency")
|
||||
private @Meta double frequency;
|
||||
|
||||
@Value("channel")
|
||||
private ImageSampler.@Meta Channel channel;
|
||||
|
||||
@Override
|
||||
public NoiseSampler get() {
|
||||
if(!used) {
|
||||
logger.warn("The IMAGE NoiseSampler implemented by the config-noise-function addon is deprecated. " +
|
||||
"It is recommended to use the IMAGE NoiseSampler implemented by the config-noise-image " +
|
||||
"addon instead.");
|
||||
used = true;
|
||||
}
|
||||
return new ImageSampler(image, channel, frequency);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public class ImageSampler implements NoiseSampler {
|
||||
private final BufferedImage image;
|
||||
private final Channel channel;
|
||||
|
||||
private final double frequency;
|
||||
|
||||
public ImageSampler(BufferedImage image, Channel channel, double frequency) {
|
||||
this.image = image;
|
||||
this.channel = channel;
|
||||
this.frequency = frequency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return ((channel.getChannel(image.getRGB(FastMath.floorMod(FastMath.floorToInt(x * frequency), image.getWidth()),
|
||||
FastMath.floorMod(FastMath.floorToInt(y * frequency), image.getHeight()))) / 255D) - 0.5) *
|
||||
2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y, double z) {
|
||||
return noise(seed, x, y);
|
||||
}
|
||||
|
||||
public enum Channel {
|
||||
RED {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (mashed >> 16) & 0xff;
|
||||
}
|
||||
},
|
||||
GREEN {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (mashed >> 8) & 0xff;
|
||||
}
|
||||
},
|
||||
BLUE {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return mashed & 0xff;
|
||||
}
|
||||
},
|
||||
GRAYSCALE {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (RED.getChannel(mashed) + GREEN.getChannel(mashed) + BLUE.getChannel(mashed)) / 3;
|
||||
}
|
||||
},
|
||||
ALPHA {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (mashed >> 24) & 0xff;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int getChannel(int mashed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user