9 #include "VoxelLayer.h"
11 #include "MaterialLibrary.h"
38 double noiseAmplitude,
44 double noiseLacunarity,
51 double getHeight(
double x,
double z,
double& noiseHeight,
double& tileHeight,
double& tileHeightMinFiltered,
double& tileHeightMaxFiltered);
59 double noiseAmplitude;
62 double noiseLacunarity;
146 InstanceRotation getRandomRotation(
int random);
183 void setMacroColor(
unsigned char* colors);
184 virtual void getColor(
double x,
double y,
double z,
unsigned char& r,
unsigned char& g,
unsigned char& b);
238 double tileHeightMin,
240 double tileHeightMax,
244 double caveBottomDisplacement,
262 double getValue(
double x,
double z);
266 double getValue(
double x,
double z,
CBiome* &biome,
double& noiseHeight,
double& tileHeight,
double& tileHeightMinFiltered,
double& tileHeightMaxFiltered);
268 unsigned int getValue(
int x,
int z);
274 TVector<CBiome*> biomes;
305 void* threadContext)
override;
321 void* threadContext);
330 void* threadContext);
342 MaterialId* materialLowRes;
346 const static int CornerMap[8][3];
347 const static int EdgeMap[12][2];
349 static inline double biLinearInterpolate(
double p[2][2],
double x,
double y);
350 static inline double getDisplacementMapValue(
unsigned char* displacementData,
int displacementDataSize,
double x,
double y);
351 static inline double getDisplacement(
unsigned char* displacementData,
int displacementDataSize,
double pos[3],
Algebra::Vector& normal,
double freq);
364 unsigned char* aMask,
367 unsigned char* aDisplacement,
368 int aDisplacementMapSize,
369 double aDisplacementFrequency,
370 int aDisplacementHeight,
371 int aDisplacementShift,
372 MaterialId aMaterial) :
374 maskCutMin(aMaskCutMin),
375 maskCutMax(aMaskCutMax),
376 displacement(aDisplacement),
377 displacementMapSize(aDisplacementMapSize),
378 displacementFrequency(aDisplacementFrequency),
379 displacementHeight(aDisplacementHeight),
380 displacementShift(aDisplacementShift),
381 material(aMaterial) {};
385 unsigned char* displacement;
386 int displacementMapSize;
387 double displacementFrequency;
388 int displacementHeight;
389 int displacementShift;
398 plantingRules.push_back(rule);
405 unsigned short* heightmap;
409 double heightmapFreq;
413 unsigned short* heightmap,
417 double heightmapFreq,
425 double getHeight(
double x,
double z,
CBiome* &topBiome, CBiome::CLayer* &topLayer);
426 void getHeightPage(
double xo,
double zo,
double pageLength,
int pageSize,
double* heights);
429 unsigned char* probabilityMap;
430 int probabilityMapSize;
432 double tileFrequency;
434 int biomeDistribution[256];
440 double tileFrequency,
442 unsigned char* probabilityMap,
443 int probabilityMapSize);
461 void* threadContext)
override;
478 static const int BUFFER_SIZE =
BLOCK_SIZE + 1;
479 float biomeStrength[BUFFER_SIZE][BUFFER_SIZE][4][4];
480 unsigned char biome[BUFFER_SIZE][BUFFER_SIZE][4][4];
481 unsigned char biomeProb[BUFFER_SIZE][BUFFER_SIZE];
482 double heights[BUFFER_SIZE][BUFFER_SIZE];
483 float mask[BUFFER_SIZE][BUFFER_SIZE];
484 float displacement[BUFFER_SIZE][BUFFER_SIZE];
485 float workBuffer[BUFFER_SIZE][BUFFER_SIZE];
486 double finalHeights[BUFFER_SIZE][BUFFER_SIZE];
487 MaterialId material[BUFFER_SIZE][BUFFER_SIZE];
488 MaterialId finalMaterial[BUFFER_SIZE][BUFFER_SIZE];
489 bool biomeInUse[256];
493 template <
typename T>
void expandInterpolationKernel(T* dest, T* source,
int size)
495 for (
int z = 0; z < size; z++)
497 for (
int x = 0; x < size; x++)
499 for (
int dz = 0; dz < 2; dz++)
501 for (
int dx = 0; dx < 2; dx++)
523 int idx0 = 4 * (z*size + x) + 2 * dz + dx;
524 int idx1 = nz*size + nx;
525 dest[idx0] = source[idx1];
526 dest[idx0] = source[idx1];
double maskShift
Adds a global shift to the mask.
virtual void getContourData(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext) override
Returns voxel data for the specified cell (IVoxelLayer)
double getValue(double x, double z)
Returns the height for the provided point in the XZ plane as a double precision. This method will per...
double minHeight
Minimum world height required for the scattering to happen.
int maskOctaves
Number of octaves in the mask signal.
TVector< CPlantingRule > plantingRules
List of instance planting rules for the biome.
virtual void disposeThreadContext(void *threadContext) override
Destroys the specified thread context.
double maskStep
Mask noise step (amplitude mutiplier on each octave)
void addBiome(CBiome *biome)
Adds a biome to the heightmap.
enum VoxelFarm::InstanceMirror_T InstanceMirror
Defines a rule for scattering instances.
virtual void * createThreadContext() override
The voxel layer can use this method to return a structure that will be unique for each calling thread...
double maskClampMin
Mask noise value clamp minimum.
Contains all classes and functions for the VoxelFarm engine.
double maskPhaseX
Mask noise phase along X axis.
CHeightLayer(ITileSet *tileSet, int tilePeriod, double tileAmplitude, int noiseType, double noiseAmplitude, double noiseFreq, double noiseStep, double noiseLacunarity, int noiseOctaves)
Constructs a HeightLayer object.
An interface for a 3D mask. A mask can be used to control the application of other features...
Contains all materials available in the system.
TVector< int * > materialMaps
List of material re-mappings.
const int BLOCK_SIZE
Actual number of voxels in one Cell Dim once the margin is considered.
double getHeight(double x, double z)
Returns the height for the provided point in the XZ plane as a double precision. This method will per...
double snowHeight
Height at which snow stats to appear for the biome.
int getStatsContourId() override
Returns the stats ID to be used for measuring performance of the getContourData() method...
double maskFreq
Mask noise frequency.
double maskScaleX
Mask noise scale along X axis.
void getContourDataRegular(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext)
Returns voxel data for the specified cell (IVoxelLayer)
int maskType
Type of mask. Only 0 (Perlin) is currently supported.
TVector< int > materials
List of terrain materials that appear in the biome.
int caveWallMaterial
Material that will be applied to cave walls.
Defines a type of biome. Several biomes can coexist in the same world. Each biome has a density mask ...
unsigned __int64 CellId
A 64bit integer that identifies a single world octree Cell.
A Voxel Layer object that outputs terrain voxels based on a heightmap.
double decimate
Additional probablity that an instance will not be placed.
double angleMin
Minimum slope required for the scattering to happen.
void addPlantingRule(CPlantingRule rule)
Adds a new PlantingRule object.
An interface for a voxel layer. By implementing this interface, very different modules can contribute...
TVector< String > classes
List of classes that will be scattered.
void addPlantingRule(CPlantingRule rule)
Adds a new PlantingRule object.
double maskScaleY
Mask noise scale along Y axis.
virtual void disposeThreadContext(void *threadContext) override
Destroys the specified thread context.
void addMaterial(CMaterialLibrary *materialLibrary, int id)
TVector< CPlantingRule > plantingRules
List of instance planting rules for the layer.
double maskPhaseY
Mask noise phase along Y axis.
int caveFloorMaterial
Material that will be applied to cave floors.
double maskFreq
Frequency of the mask signal.
const double CAVE_TOP_MIN_HEIGHT
Minimum depth of ground layer on top of a cave.
int maskType
Specified what type of mask noise should be used for scattering.
double maskClampMax
Maximum value for the mask. Values above this point will be considered one, and the remaining mask am...
A tileset with matching corners and two data channels.
double angleMax
Maximum slope required for the scattering to happen.
CHeightLayer * heightLayer
A HeightLayer object that specifies the height values for the biome.
Defines the world elevation at any XZ point. Contains a collection of biomes.
double maskClampMin
Minimum value for the mask. Values below this point will be considered zero, and the remaining mask a...
int getStatsContourId() override
Returns the stats ID to be used for measuring performance of the getContourData() method...
virtual void * createThreadContext() override
The voxel layer can use this method to return a structure that will be unique for each calling thread...
double maskLacunarity
Increment in frequency from one octave to the next for the mask signal.
double maskScaleZ
Mask noise scale along Z axis.
CBiome(CHeightLayer *heightLayer, CCornerTileSet *caveLayer, int maskType, double maskFreq, double maskStep, double maskLacunarity, int maskOctaves, double maskShift, double maskClampMin, double maskClampMax, double snowHeight, int caveFloorMaterial, int caveWallMaterial)
Constructs a biome object.
virtual void getContourData(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext) override
Returns voxel data for the specified cell (IVoxelLayer)
const double CAVE_MAX_HEIGHT
Maximum ceiling height for a cave.
CCornerTileSet * caveLayer
A tileset to be used for underground features like caves.
InstanceMirror_T
Defines a rule for scattering instances.
void getContourDataAdaptive(CellId cell, ContourVoxelData *data, bool &empty, void *threadContext)
Returns voxel data for the specified cell (IVoxelLayer)
One layer of an elevation map (heightmap). A VoxelFarm terrains starts with an elevation map...
double maskClampMax
Mask noise value clamp maximum.
double maxHeight
Maximum world height required for the scattering to happen.
unsigned char * macroColorMap
Contains the values read from the macro color map.
int maskOctaves
Mask noise number of octaves.
const double HEIGHT_INFINITE
Maximum possible height.
bool getCaveProfile(double x, double z, double noiseHeight, double tileHeight, double tileHeightMin, double tileHeightMax, double displacement, double caveBottomDisplacement, double &height, double &caveBottom, double &caveTop)
Retrieves cave profile for the biome. Returns true if the spot is exposed to open air...
CHeightmapTerrain(CMaterialLibrary *materialLibrary, CHeightmap *heightmap, IMask *instanceMask, IMask *waterMask, int downsampling)
double maskPhaseZ
Mask noise phase along Z axis.
double maskLacunarity
Mask noise lacunarity (frequency mutiplier on each octave)
double getMaskValue(double x, double z)
Retrieves the mask value for the specified point in the world map.
CBiome * getBiome(int x, int z)
Retruns the top biome for the specified point.
double maskStep
Increment in amplitude from one octave to the next for the mask signal.