Skip to content

Commit

Permalink
Add Pbr shader biome (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps authored Dec 30, 2023
1 parent 77acf57 commit a932a17
Show file tree
Hide file tree
Showing 26 changed files with 461 additions and 254 deletions.
1 change: 1 addition & 0 deletions generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ shadowJar {
"Implementation-Version": generatorVersion,
"Impletementation-Title": "Neroxis Map Generator"
}
excludes += "**/source_images/*"
duplicatesStrategy = DuplicatesStrategy.WARN
}
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,12 @@ private void generate() {
map.setFilePrefix(mapName);

if (map.getTerrainShaderPath().equals(PBR_SHADER_NAME)) {
map.getBiome().terrainMaterials().getTexturePaths()[8] = Path.of("/maps", map.getFolderName(), "env",
"texture", "heightRoughness.dds")
map.getBiome().terrainMaterials().getNormalPaths()[8] = Path.of("/maps", map.getFolderName(), "env",
"layers", "heightRoughness.dds")
.toString()
.replace("\\", "/");
map.getBiome().terrainMaterials().getNormalPaths()[8] = map.getBiome()
.terrainMaterials()
.getCubeMaps()
.get(0)
.getPath();
map.getBiome().terrainMaterials().getTexturePaths()[9] = Path.of("/maps", map.getFolderName(), "env",
"texture", "mapwide.dds")
"layers", "mapwide.dds")
.toString()
.replace("\\", "/");
// This needs to be higher than the map size in ogrids to trigger all aspects of the terrain shader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ParameterConstraints getParameterConstraints() {
.plateauDensity(.5f, 1f)
.rampDensity(0f, .5f)
.reclaimDensity(.8f, 1f)
.biomes(DESERT, FRITHEN, LOKI, MOONLIGHT, WONDER)
.biomes(DESERT, FRITHEN, MOONLIGHT, SUNSET, WONDER)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ParameterConstraints getParameterConstraints() {
.plateauDensity(.5f, 1f)
.rampDensity(0f, .25f)
.reclaimDensity(.8f, 1f)
.biomes(DESERT, FRITHEN, LOKI, MOONLIGHT, WONDER)
.biomes(DESERT, FRITHEN, MOONLIGHT, SUNSET, WONDER)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.faforever.neroxis.generator.GeneratorParameters;
import com.faforever.neroxis.generator.Visibility;
import com.faforever.neroxis.generator.WeightedConstrainedOptions;
import com.faforever.neroxis.generator.WeightedOption;
import com.faforever.neroxis.generator.decal.BasicDecalGenerator;
import com.faforever.neroxis.generator.decal.DecalGenerator;
import com.faforever.neroxis.generator.prop.BasicPropGenerator;
Expand All @@ -12,6 +13,7 @@
import com.faforever.neroxis.generator.terrain.BasicTerrainGenerator;
import com.faforever.neroxis.generator.terrain.TerrainGenerator;
import com.faforever.neroxis.generator.texture.BasicTextureGenerator;
import com.faforever.neroxis.generator.texture.PbrTextureGenerator;
import com.faforever.neroxis.generator.texture.TextureGenerator;
import com.faforever.neroxis.generator.util.ConstrainedSelector;
import com.faforever.neroxis.generator.util.HasParameterConstraints;
Expand Down Expand Up @@ -47,7 +49,9 @@ protected WeightedConstrainedOptions<TerrainGenerator> getTerrainGeneratorOption
}

protected WeightedConstrainedOptions<TextureGenerator> getTextureGeneratorOptions() {
return WeightedConstrainedOptions.single(new BasicTextureGenerator());
return new WeightedConstrainedOptions<>(new BasicTextureGenerator(),
new WeightedOption<>(new BasicTextureGenerator(), 1f),
new WeightedOption<>(new PbrTextureGenerator(), 1f));
}

protected WeightedConstrainedOptions<ResourceGenerator> getResourceGeneratorOptions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.neroxis.generator.texture;

import com.faforever.neroxis.generator.GeneratorParameters;
import com.faforever.neroxis.generator.ParameterConstraints;
import com.faforever.neroxis.generator.terrain.TerrainGenerator;
import com.faforever.neroxis.map.SCMap;
import com.faforever.neroxis.map.SymmetrySettings;
Expand All @@ -11,6 +12,8 @@
import com.faforever.neroxis.util.ImageUtil;
import com.faforever.neroxis.util.Pipeline;

import static com.faforever.neroxis.biomes.BiomeName.*;

public class BasicTextureGenerator extends TextureGenerator {
protected BooleanMask realLand;
protected BooleanMask realPlateaus;
Expand All @@ -24,6 +27,14 @@ public class BasicTextureGenerator extends TextureGenerator {
protected FloatMask accentRockTexture;
protected IntegerMask terrainType;

@Override
public ParameterConstraints getParameterConstraints() {
return ParameterConstraints.builder()
.biomes(BRIMSTONE, DESERT, EARLYAUTUMN, FRITHEN, MARS,
MOONLIGHT, PRAYER, STONES, SYRTIS, WINDINGRIVER, WONDER)
.build();
}

@Override
protected void setupTexturePipeline() {
BooleanMask flat = slope.copyAsBooleanMask(.05f).invert();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package com.faforever.neroxis.generator.texture;

import com.faforever.neroxis.generator.GeneratorParameters;
import com.faforever.neroxis.generator.ParameterConstraints;
import com.faforever.neroxis.generator.terrain.TerrainGenerator;
import com.faforever.neroxis.map.SCMap;
import com.faforever.neroxis.map.SymmetrySettings;
import com.faforever.neroxis.mask.BooleanMask;
import com.faforever.neroxis.mask.FloatMask;
import com.faforever.neroxis.mask.IntegerMask;
import com.faforever.neroxis.util.DebugUtil;
import com.faforever.neroxis.util.ImageUtil;
import com.faforever.neroxis.util.Pipeline;

import static com.faforever.neroxis.biomes.BiomeName.SUNSET;

public class PbrTextureGenerator extends TextureGenerator {
protected BooleanMask realLand;
protected BooleanMask realPlateaus;
protected FloatMask groundTexture;
protected FloatMask groundAccentTexture;
protected FloatMask debrisTexture;
protected FloatMask plateauTexture;
protected FloatMask slopesTexture;
protected FloatMask underWaterTexture;
protected FloatMask waterBeachTexture;
protected FloatMask cliffAccentTexture;
protected FloatMask roughnessModifierTexture;
protected IntegerMask terrainType;
protected FloatMask waterSurfaceShadows;

@Override
public ParameterConstraints getParameterConstraints() {
return ParameterConstraints.builder()
.biomes(SUNSET)
.build();
}

@Override
protected void setupTexturePipeline() {
BooleanMask debris = slope.copyAsBooleanMask(.2f);
BooleanMask cliff = slope.copyAsBooleanMask(.75f);
BooleanMask extendedCliff = cliff.copy().inflate(2f);
BooleanMask realWater = realLand.copy().invert();
FloatMask waterBeach = realWater.copy().inflate(11)
.subtract(realPlateaus)
.subtract(slope.copyAsBooleanMask(.05f).invert())
.add(realWater)
.copyAsFloatMask(0, 1)
.blur(4);
FloatMask cliffMask = cliff.copyAsFloatMask(0, 1).blur(4).add(cliff, 1f).blur(2).add(cliff, 0.5f);

int textureSize = generatorParameters.mapSize() + 1;
int mapSize = generatorParameters.mapSize();

BooleanMask realWaterMapSized = realWater.copy().setSize(mapSize);
BooleanMask shadowsInWater = shadowsMask.copy().multiply(realWaterMapSized);
shadows.setToValue(shadowsInWater, 1f);
shadowsInWater.add(realLand.copy().setSize(mapSize), shadowsInWater.copy().inflate(6));
shadows.subtract(realWaterMapSized,
shadowsInWater.copyAsFloatMask(0, 1).blur(6))
.blur(1);
waterSurfaceShadows = heightmap.copy()
.clampMin(generatorParameters.biome().waterSettings().getElevation())
.copyAsShadowMask(generatorParameters.biome().lightingSettings().getSunDirection())
.inflate(0.5f)
.resample(map.getSize() / 2)
.copyAsFloatMask(1, 0)
.blur(1);


waterBeachTexture.setSize(textureSize)
.add(waterBeach)
.subtract(cliffMask);
cliffAccentTexture.setSize(textureSize)
.add(0.2f)
.addPerlinNoise(mapSize / 32, 0.6f)
.clampMax(1f)
.setToValue(extendedCliff.copy().invert(), 0f)
.blur(2)
.addGaussianNoise(.05f);
groundTexture.setSize(textureSize)
.add(1f)
.subtract(waterBeach)
.subtract(cliffMask)
.clampMin(0f);
groundAccentTexture.setSize(textureSize)
.add(0.1f)
.addPerlinNoise(mapSize / 16, 0.5f)
.addPerlinNoise(mapSize / 6, 0.2f)
.addGaussianNoise(.05f)
.clampMax(1f)
.multiply(groundTexture)
.clampMin(0f);
slopesTexture.init(slope)
.subtract(0.05f)
.multiply(4f)
.addPerlinNoise(mapSize / 40, .2f)
.addPerlinNoise(mapSize / 8, .1f)
.addGaussianNoise(.05f)
.subtract(0.2f)
.clampMax(1f)
.subtract(waterBeach)
.subtract(cliffMask.copy().subtract(0.2f).clampMin(0f));
debrisTexture.init(cliff.copy().inflate(8), 0f, 1f)
.subtract(0.25f)
.addPerlinNoise(mapSize / 8, .2f)
.addGaussianNoise(.05f)
.setToValue(debris.copy().invert(), 0f)
.setToValue(realPlateaus, 0f)
.subtract(realWater.copyAsFloatMask(0, 1).blur(4))
.subtract(cliff, 0.9f)
.clampMin(0f)
.multiply(0.7f)
.blur(1);
plateauTexture.setSize(textureSize)
.add(0.5f)
.addPerlinNoise(mapSize / 40, .4f)
.setToValue(realPlateaus.copy().invert(), 0f)
.multiply(slope.copyAsBooleanMask(0.01f).deflate(4), slope.copy().multiply(-8f).add(1f).clampMin(0f))
.clampMin(0f)
.blur(2)
.setToValue(cliff, 0f)
.blur(1)
.multiply(0.8f);
underWaterTexture.init(realWater.deflate(1), 0f, .7f)
.add(scaledWaterDepth.copy().multiply(.3f))
.clampMax(1f)
.blur(1);
roughnessModifierTexture.setSize(textureSize)
.add(0.5f)
.addPerlinNoise(mapSize / 70, .1f);

// due to the heightmapsplatting we effectively don't see a difference in very high or low values,
// so we compress the range a bit
slopesTexture.multiply(0.6f).add(slopesTexture.copyAsBooleanMask(0.01f), 0.3f);

texturesLowMask.setComponents(waterBeachTexture, cliffAccentTexture, groundTexture, groundAccentTexture);
texturesHighMask.setComponents(slopesTexture, debrisTexture, plateauTexture, roughnessModifierTexture);

setupTerrainType(mapSize);
}

protected void setupTerrainType(int mapSize) {
terrainType.setSize(mapSize);

Integer[] terrainTypes = map.getBiome().terrainMaterials().getTerrainTypes();
terrainType.add(terrainTypes[0])
.setToValue(waterBeachTexture.setSize(mapSize).copyAsBooleanMask(.55f), terrainTypes[1])
.setToValue(cliffAccentTexture.setSize(mapSize).copyAsBooleanMask(.35f), terrainTypes[2])
.setToValue(groundTexture.setSize(mapSize).copyAsBooleanMask(.5f), terrainTypes[3])
.setToValue(groundAccentTexture.setSize(mapSize).copyAsBooleanMask(.5f), terrainTypes[4])
.setToValue(slopesTexture.setSize(mapSize).copyAsBooleanMask(.3f), terrainTypes[5])
.setToValue(debrisTexture.setSize(mapSize).copyAsBooleanMask(.3f), terrainTypes[6])
.setToValue(plateauTexture.setSize(mapSize).copyAsBooleanMask(.5f), terrainTypes[7])
.setToValue(underWaterTexture.setSize(mapSize).copyAsBooleanMask(.7f), terrainTypes[8])
.setToValue(underWaterTexture.setSize(mapSize).copyAsBooleanMask(.8f), terrainTypes[9]);
}

@Override
public void initialize(SCMap map, long seed, GeneratorParameters generatorParameters,
SymmetrySettings symmetrySettings, TerrainGenerator terrainGenerator) {
super.initialize(map, seed, generatorParameters, symmetrySettings, terrainGenerator);
this.map.setTerrainShaderPath(SCMap.PBR_SHADER_NAME);

realLand = heightmap.copyAsBooleanMask(generatorParameters.biome().waterSettings().getElevation());
realPlateaus = heightmap.copyAsBooleanMask(
generatorParameters.biome().waterSettings().getElevation() + 5f);
waterBeachTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "waterBeachTexture", true);
cliffAccentTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "cliffAccentTexture", true);
groundTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "groundTexture", true);
groundAccentTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "groundAccentTexture", true);
slopesTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "slopesTexture", true);
debrisTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "debrisTexture", true);
plateauTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "plateauTexture", true);
underWaterTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "underWaterTexture", true);
roughnessModifierTexture = new FloatMask(1, random.nextLong(), symmetrySettings, "roughnessModifierTexture", true);
terrainType = new IntegerMask(1, random.nextLong(), symmetrySettings, "terrainType", true);
}

@Override
public void setTextures() {
Pipeline.await(texturesLowMask, texturesHighMask, terrainType,
normals, scaledWaterDepth, shadows, waterSurfaceShadows);
DebugUtil.timedRun("com.faforever.neroxis.map.generator", "generateTextures", () -> {
map.setTextureMasksScaled(map.getTextureMasksLow(), texturesLowMask.getFinalMask());
map.setTextureMasksScaled(map.getTextureMasksHigh(), texturesHighMask.getFinalMask());
map.setTerrainType(map.getTerrainType(), terrainType.getFinalMask());
map.setMapwideTexture(
ImageUtil.getMapwideTexture(normals.getFinalMask(), scaledWaterDepth.getFinalMask(),
shadows.getFinalMask()));
map.setWaterShadowMap(map.getWaterShadowMap(), waterSurfaceShadows.getFinalMask());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public void initialize(SCMap map, long seed, GeneratorParameters generatorParame
.subtract(generatorParameters.biome().waterSettings().getElevation())
.multiply(-1f)
.divide(abyssDepth)
.clampMin(0f)
.clampMax(1f);
.clampMin(0f);

texturesLowMask = new Vector4Mask(map.getSize() + 1, random.nextLong(), symmetrySettings, "texturesLow", true);
texturesHighMask = new Vector4Mask(map.getSize() + 1, random.nextLong(), symmetrySettings, "texturesHigh",
Expand Down
Loading

0 comments on commit a932a17

Please sign in to comment.