|
@@ -758,22 +758,8 @@ void ThermalErosionAction::process(Selection * sel, const Gui3DMouseEvent &, boo
|
|
|
if (!tblock)
|
|
|
return;
|
|
|
|
|
|
- Vector<F32> scratch = mNoiseData;
|
|
|
- if (type == Begin)
|
|
|
- {
|
|
|
- mNoise.setSeed(Sim::getCurrentTime());
|
|
|
- mNoise.fBm(&mNoiseData, mNoiseSize, 12, 1.0f, 5.0f);
|
|
|
- scratch = mNoiseData;
|
|
|
- mNoise.rigidMultiFractal(&mNoiseData, &scratch, mNoiseSize, 12, 1.0f, 5.0f);
|
|
|
- mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
|
|
- }
|
|
|
- scratch = mNoiseData;
|
|
|
- //erodeThermal(Vector<F32> *src, Vector<F32> *dst, F32 slope, F32 materialLoss, U32 iterations, U32 size, U32 squareSize, F32 maxHeight );
|
|
|
- mNoise.erodeThermal(&scratch, &mNoiseData, 30.0f, 5.0f, 5, mNoiseSize, 1, tblock->getObjBox().len_z());
|
|
|
- mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
|
|
- mScale = 1.5f / (mMinMaxNoise.x - mMinMaxNoise.y + 0.0001);
|
|
|
-
|
|
|
F32 selRange = sel->getMaxHeight()-sel->getMinHeight();
|
|
|
+ F32 avg = sel->getAvgHeight();
|
|
|
if (selChanged)
|
|
|
{
|
|
|
F32 heightDiff = 0;
|
|
@@ -785,23 +771,11 @@ void ThermalErosionAction::process(Selection * sel, const Gui3DMouseEvent &, boo
|
|
|
|
|
|
mTerrainEditor->getUndoSel()->add((*sel)[i]);
|
|
|
|
|
|
- const Point2I& gridPos = (*sel)[i].mGridPoint.gridPos;
|
|
|
-
|
|
|
- const F32 noiseVal = mNoiseData[(gridPos.x % mNoiseSize) +
|
|
|
- ((gridPos.y % mNoiseSize) * mNoiseSize)]/(mMinMaxNoise.y-mMinMaxNoise.x) * selRange + mMinMaxNoise.y;
|
|
|
-
|
|
|
- heightDiff = (noiseVal * mTerrainEditor->mNoiseFactor - (*sel)[i].mHeight) / tblock->getObjBox().len_z() * 2.0;
|
|
|
-
|
|
|
- const F32 squareSize = tblock->getSquareSize();
|
|
|
- Point2F p;
|
|
|
- Point3F norm;
|
|
|
-
|
|
|
- p.x = (*sel)[i].mGridPoint.gridPos.x * squareSize;
|
|
|
- p.y = (*sel)[i].mGridPoint.gridPos.y * squareSize;
|
|
|
- tblock->getNormal(p, &norm, true);
|
|
|
-
|
|
|
- F32 bias = 0.75f-norm.z;
|
|
|
- (*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight * bias;
|
|
|
+ F32 bias = ((*sel)[i].mHeight - avg) / selRange;
|
|
|
+ F32 nudge = mRandF(-mTerrainEditor->getBrushPressure(), mTerrainEditor->getBrushPressure());
|
|
|
+ F32 heightTarg = mRoundF((*sel)[i].mHeight - bias * nudge, mTerrainEditor->getBrushPressure() * 2.0f) ;
|
|
|
+ heightDiff = heightTarg - (*sel)[i].mHeight;
|
|
|
+ (*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight;
|
|
|
|
|
|
if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
|
|
|
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;
|
|
@@ -824,22 +798,13 @@ void HydraulicErosionAction::process(Selection* sel, const Gui3DMouseEvent&, boo
|
|
|
TerrainBlock* tblock = mTerrainEditor->getActiveTerrain();
|
|
|
if (!tblock)
|
|
|
return;
|
|
|
- Vector<F32> scratch = mNoiseData;
|
|
|
- if (type == Begin)
|
|
|
- {
|
|
|
- mNoise.setSeed(Sim::getCurrentTime());
|
|
|
- mNoise.fBm(&mNoiseData, mNoiseSize, 12, 1.0f, 5.0f);
|
|
|
- scratch = mNoiseData;
|
|
|
- }
|
|
|
- mNoise.erodeHydraulic(&scratch, &mNoiseData, 1, mNoiseSize);
|
|
|
- mNoise.getMinMax(&mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize);
|
|
|
- mScale = 1.5f / (mMinMaxNoise.x - mMinMaxNoise.y + 0.0001);
|
|
|
|
|
|
F32 selRange = sel->getMaxHeight() - sel->getMinHeight();
|
|
|
F32 avg = sel->getAvgHeight();
|
|
|
if (selChanged)
|
|
|
{
|
|
|
F32 heightDiff = 0;
|
|
|
+ const F32 squareSize = tblock->getSquareSize();
|
|
|
|
|
|
for (U32 i = 0; i < sel->size(); i++)
|
|
|
{
|
|
@@ -848,15 +813,19 @@ void HydraulicErosionAction::process(Selection* sel, const Gui3DMouseEvent&, boo
|
|
|
|
|
|
mTerrainEditor->getUndoSel()->add((*sel)[i]);
|
|
|
|
|
|
- const Point2I& gridPos = (*sel)[i].mGridPoint.gridPos;
|
|
|
+ Point2F p;
|
|
|
+ Point3F norm;
|
|
|
+
|
|
|
+ p.x = (*sel)[i].mGridPoint.gridPos.x * squareSize;
|
|
|
+ p.y = (*sel)[i].mGridPoint.gridPos.y * squareSize;
|
|
|
+ tblock->getNormal(p, &norm, true);
|
|
|
|
|
|
- const F32 noiseVal = mNoiseData[(gridPos.x % mNoiseSize) +
|
|
|
- ((gridPos.y % mNoiseSize) * mNoiseSize)] / (mMinMaxNoise.y - mMinMaxNoise.x) * selRange + mMinMaxNoise.y;
|
|
|
+ F32 bias = mPow(norm.z,3.0f) * ((*sel)[i].mHeight - avg) / selRange;
|
|
|
+ F32 nudge = mRandF(-mTerrainEditor->getBrushPressure(), mTerrainEditor->getBrushPressure());
|
|
|
|
|
|
- heightDiff = (noiseVal * mTerrainEditor->mNoiseFactor - (*sel)[i].mHeight) / tblock->getObjBox().len_z() * 2.0;
|
|
|
+ heightDiff = bias * (-(*sel)[i].mHeight + bias * nudge) / tblock->getObjBox().len_z() * 2.0;
|
|
|
|
|
|
- F32 bias = ((*sel)[i].mHeight - avg)/ selRange;
|
|
|
- (*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight * bias;
|
|
|
+ (*sel)[i].mHeight += heightDiff * (*sel)[i].mWeight;
|
|
|
|
|
|
if ((*sel)[i].mHeight > mTerrainEditor->mTileMaxHeight)
|
|
|
(*sel)[i].mHeight = mTerrainEditor->mTileMaxHeight;
|