surface selection work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
8a9abcc8e4
commit
44c6a667e9
@ -1415,6 +1415,7 @@ Fix rock2 texture
|
|||||||
biome floor elements controlling noise generator's voxel selection
|
biome floor elements controlling noise generator's voxel selection
|
||||||
Plains (rock) biome
|
Plains (rock) biome
|
||||||
Lore message resend from client on failure
|
Lore message resend from client on failure
|
||||||
|
More surface selection work
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,8 @@ import electrosphere.server.terrain.generation.voxelphase.NoiseVoxelGen;
|
|||||||
import electrosphere.server.terrain.generation.voxelphase.VoxelGenerator;
|
import electrosphere.server.terrain.generation.voxelphase.VoxelGenerator;
|
||||||
import electrosphere.server.terrain.manager.ServerTerrainChunk;
|
import electrosphere.server.terrain.manager.ServerTerrainChunk;
|
||||||
import electrosphere.server.terrain.models.TerrainModel;
|
import electrosphere.server.terrain.models.TerrainModel;
|
||||||
|
import electrosphere.util.noise.OpenSimplex2S;
|
||||||
|
import io.github.studiorailgun.MathUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generator for testing terrain generation
|
* A generator for testing terrain generation
|
||||||
@ -143,6 +145,9 @@ public class TestGenerationChunkGenerator implements ChunkGenerator {
|
|||||||
BiomeData[][] surfaceBiomeMap = new BiomeData[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];
|
BiomeData[][] surfaceBiomeMap = new BiomeData[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];
|
||||||
this.populateElevation(heightfield,surfaceBiomeMap,worldX,worldZ,strideValue);
|
this.populateElevation(heightfield,surfaceBiomeMap,worldX,worldZ,strideValue);
|
||||||
|
|
||||||
|
//presolve surface selection noise
|
||||||
|
double[][] surfaceSelectionField = new double[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];
|
||||||
|
this.surfaceSelectionNoise(surfaceSelectionField,worldX,worldZ,strideValue,this.terrainModel.getSeed());
|
||||||
|
|
||||||
double[][] gradientField = new double[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];
|
double[][] gradientField = new double[ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE][ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE];
|
||||||
for(int x = 0; x < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; x++){
|
for(int x = 0; x < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; x++){
|
||||||
@ -182,6 +187,7 @@ public class TestGenerationChunkGenerator implements ChunkGenerator {
|
|||||||
double realZ = generationContext.getServerWorldData().convertVoxelToRealSpace(finalChunkZ,finalWorldZ);
|
double realZ = generationContext.getServerWorldData().convertVoxelToRealSpace(finalChunkZ,finalWorldZ);
|
||||||
double surfaceHeight = heightfield[x][z];
|
double surfaceHeight = heightfield[x][z];
|
||||||
double gradient = gradientField[x][z];
|
double gradient = gradientField[x][z];
|
||||||
|
double surfaceSelection = surfaceSelectionField[x][z];
|
||||||
BiomeData surfaceBiome = surfaceBiomeMap[x][z];
|
BiomeData surfaceBiome = surfaceBiomeMap[x][z];
|
||||||
BiomeSurfaceGenerationParams surfaceParams = surfaceBiome.getSurfaceGenerationParams();
|
BiomeSurfaceGenerationParams surfaceParams = surfaceBiome.getSurfaceGenerationParams();
|
||||||
|
|
||||||
@ -196,7 +202,7 @@ public class TestGenerationChunkGenerator implements ChunkGenerator {
|
|||||||
finalChunkX, finalChunkY, finalChunkZ,
|
finalChunkX, finalChunkY, finalChunkZ,
|
||||||
realX, realY, realZ,
|
realX, realY, realZ,
|
||||||
stride,
|
stride,
|
||||||
surfaceHeight, gradient,
|
surfaceHeight, gradient, surfaceSelection,
|
||||||
surfaceBiome, surfaceParams,
|
surfaceBiome, surfaceParams,
|
||||||
generationContext
|
generationContext
|
||||||
);
|
);
|
||||||
@ -284,6 +290,40 @@ public class TestGenerationChunkGenerator implements ChunkGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the surface selection noise field
|
||||||
|
* @param surfaceNoiseField The surface selection noise field
|
||||||
|
* @param worldX The world x position
|
||||||
|
* @param worldZ The world z position
|
||||||
|
* @param strideValue The stride value
|
||||||
|
*/
|
||||||
|
private void surfaceSelectionNoise(double[][] surfaceNoiseField, int worldX, int worldZ, int strideValue, long seed){
|
||||||
|
for(int x = 0; x < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; x++){
|
||||||
|
for(int z = 0; z < ServerTerrainChunk.CHUNK_DATA_GENERATOR_SIZE; z++){
|
||||||
|
int finalWorldX = worldX + ((x * strideValue) / ServerTerrainChunk.CHUNK_DIMENSION);
|
||||||
|
int finalWorldZ = worldZ + ((z * strideValue) / ServerTerrainChunk.CHUNK_DIMENSION);
|
||||||
|
int finalChunkX = (x * strideValue) % ServerTerrainChunk.CHUNK_DIMENSION;
|
||||||
|
int finalChunkZ = (z * strideValue) % ServerTerrainChunk.CHUNK_DIMENSION;
|
||||||
|
|
||||||
|
if(finalWorldX > this.serverWorldData.getWorldSizeDiscrete() || finalWorldZ > this.serverWorldData.getWorldSizeDiscrete()){
|
||||||
|
throw new Error("Invalid world dim! " + finalWorldX + " " + finalWorldZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
double realX = serverWorldData.convertVoxelToRealSpace(finalChunkX, finalWorldX);
|
||||||
|
double realZ = serverWorldData.convertVoxelToRealSpace(finalChunkZ, finalWorldZ);
|
||||||
|
|
||||||
|
double warpX = OpenSimplex2S.noise3_ImproveXY(seed, realX, realZ, 0);
|
||||||
|
double warpZ = OpenSimplex2S.noise3_ImproveXY(seed, realX, realZ, 1);
|
||||||
|
double valueRaw = OpenSimplex2S.noise2(seed, realX + warpX, realZ + warpZ);
|
||||||
|
double fixed = (MathUtils.clamp(valueRaw, -1, 1) + 1) / 2.0;
|
||||||
|
if(fixed < 0){
|
||||||
|
throw new Error("Failed to clamp value properly! " + valueRaw + " " + fixed);
|
||||||
|
}
|
||||||
|
surfaceNoiseField[x][z] = fixed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the elevation of a given position by sampling all four surrounding biome generators
|
* Gets the elevation of a given position by sampling all four surrounding biome generators
|
||||||
* @param finalWorldX The world x coordinate
|
* @param finalWorldX The world x coordinate
|
||||||
|
|||||||
@ -79,7 +79,7 @@ public class AnimeMountainsGen implements VoxelGenerator {
|
|||||||
int worldX, int worldY, int worldZ,
|
int worldX, int worldY, int worldZ,
|
||||||
int chunkX, int chunkY, int chunkZ,
|
int chunkX, int chunkY, int chunkZ,
|
||||||
double realX, double realY, double realZ,
|
double realX, double realY, double realZ,
|
||||||
int stride, double surfaceHeight, double surfaceGradient,
|
int stride, double surfaceHeight, double surfaceGradient, double surfaceSelectionNoise,
|
||||||
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
||||||
GenerationContext generationContext
|
GenerationContext generationContext
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public class HillsVoxelGen implements VoxelGenerator {
|
|||||||
int chunkX, int chunkY, int chunkZ,
|
int chunkX, int chunkY, int chunkZ,
|
||||||
double realX, double realY, double realZ,
|
double realX, double realY, double realZ,
|
||||||
int stride,
|
int stride,
|
||||||
double surfaceHeight, double surfaceGradient,
|
double surfaceHeight, double surfaceGradient, double surfaceSelectionNoise,
|
||||||
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
||||||
GenerationContext generationContext
|
GenerationContext generationContext
|
||||||
){
|
){
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public class MountainVoxelGen implements VoxelGenerator {
|
|||||||
int chunkX, int chunkY, int chunkZ,
|
int chunkX, int chunkY, int chunkZ,
|
||||||
double realX, double realY, double realZ,
|
double realX, double realY, double realZ,
|
||||||
int stride,
|
int stride,
|
||||||
double surfaceHeight, double surfaceGradient,
|
double surfaceHeight, double surfaceGradient, double surfaceSelectionNoise,
|
||||||
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
||||||
GenerationContext generationContext
|
GenerationContext generationContext
|
||||||
){
|
){
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class NoiseVoxelGen implements VoxelGenerator {
|
|||||||
int worldX, int worldY, int worldZ,
|
int worldX, int worldY, int worldZ,
|
||||||
int chunkX, int chunkY, int chunkZ,
|
int chunkX, int chunkY, int chunkZ,
|
||||||
double realX, double realY, double realZ,
|
double realX, double realY, double realZ,
|
||||||
int stride, double surfaceHeight, double surfaceGradient,
|
int stride, double surfaceHeight, double surfaceGradient, double surfaceSelectionNoise,
|
||||||
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceParams,
|
||||||
GenerationContext generationContext
|
GenerationContext generationContext
|
||||||
) {
|
) {
|
||||||
@ -94,13 +94,13 @@ public class NoiseVoxelGen implements VoxelGenerator {
|
|||||||
voxel.weight = -1.0f;
|
voxel.weight = -1.0f;
|
||||||
voxel.type = 0;
|
voxel.type = 0;
|
||||||
} else if(heightDiff < -strideMultiplier){
|
} else if(heightDiff < -strideMultiplier){
|
||||||
BiomeFloorElement floorEl = surfaceParams.getFloorVariant((float)surfaceGradient);
|
BiomeFloorElement floorEl = surfaceParams.getFloorVariant((float)surfaceSelectionNoise);
|
||||||
//generate full-size surface-type voxel
|
//generate full-size surface-type voxel
|
||||||
double finalHeight = sample;
|
double finalHeight = sample;
|
||||||
voxel.weight = (float)finalHeight;
|
voxel.weight = (float)finalHeight;
|
||||||
voxel.type = floorEl.getVoxelId();
|
voxel.type = floorEl.getVoxelId();
|
||||||
} else {
|
} else {
|
||||||
BiomeFloorElement floorEl = surfaceParams.getFloorVariant((float)surfaceGradient);
|
BiomeFloorElement floorEl = surfaceParams.getFloorVariant((float)surfaceSelectionNoise);
|
||||||
//surface
|
//surface
|
||||||
double surfacePercent = -heightDiff / strideMultiplier;
|
double surfacePercent = -heightDiff / strideMultiplier;
|
||||||
if(surfacePercent > 1.0 || surfacePercent < 0){
|
if(surfacePercent > 1.0 || surfacePercent < 0){
|
||||||
|
|||||||
@ -37,6 +37,7 @@ public interface VoxelGenerator {
|
|||||||
* @param stride The stride of the data
|
* @param stride The stride of the data
|
||||||
* @param surfaceHeight The height of the surface at x,z
|
* @param surfaceHeight The height of the surface at x,z
|
||||||
* @param surfaceGradient The rate of change in the surface at this point
|
* @param surfaceGradient The rate of change in the surface at this point
|
||||||
|
* @param surfaceSelectionNoise The noise value to select surface variants
|
||||||
* @param surfaceBiome The surface biome of the chunk
|
* @param surfaceBiome The surface biome of the chunk
|
||||||
* @param surfaceGenPArams Extra parameters for generating surface voxel values
|
* @param surfaceGenPArams Extra parameters for generating surface voxel values
|
||||||
* @param generationContext The generation context
|
* @param generationContext The generation context
|
||||||
@ -47,7 +48,7 @@ public interface VoxelGenerator {
|
|||||||
int chunkX, int chunkY, int chunkZ,
|
int chunkX, int chunkY, int chunkZ,
|
||||||
double realX, double realY, double realZ,
|
double realX, double realY, double realZ,
|
||||||
int stride,
|
int stride,
|
||||||
double surfaceHeight, double surfaceGradient,
|
double surfaceHeight, double surfaceGradient, double surfaceSelectionNoise,
|
||||||
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceGenParams,
|
BiomeData surfaceBiome, BiomeSurfaceGenerationParams surfaceGenParams,
|
||||||
GenerationContext generationContext
|
GenerationContext generationContext
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user