# Raising Terrain - Falloff

This topic is 2779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working in SlimDX, but this problem isn't really SlimDX related, so feel free to move the post if you there's a better place for it!

Anyway, I'm working on a 3D world editor in SlimDX and it's going pretty good. But I have a slight problem with the cursor falloff. Let me show you a picture of how I want my terrain to raise with 0% falloff and how I want it to raise with 100% falloff:

0% falloff:

100% falloff:

Now, I have some trouble getting this "exponential function" working. Currently I'm using this formula to get the FalloffFactor: 1 - distance * falloff, where distance is a floating value between 0.0 and 1.0 (1.0 is furthest away, 0.0 is cloest to the cursor position (middle)) and falloff is a floating value between 0.0 and 1.0, where 1.0 is 100% falloff and 0.0 is 0%! Simple! But this is obviously wrong, I get this linear looking hill:

I think you get the point by now So, does anyone know how to get this oval effect? Like an exponential function that returns a falloff factor value between 0.0 and 1.0? Thanks in advance!

// Ryxian

Edit:
Managed to get a perfect function at 100% falloff and 0% falloff: 1 - distance^2 / maxDistance^2 * falloff. distance is no longer between 0.0 and 1.0, but the actual distance. This gives a nice curve, but at falloffs like 50% it turns out something like this: (note that everything is drawn in paint, but I think you get the picture)

I would like something like this:

Basically, I still want the smooth edge, but I want it to be more steep at the edge, and more flat near the middle.

##### Share on other sites
height - distance^X * falloff * height

Height is the height at the center, falloff should be between 0 and 1. Try out different values for X, but somewhere between 5 and 10 should give pretty steep edges. Distance is expected to be between 0 and 1, so divide actual distance by range of your 'brush'.

##### Share on other sites
Cheers, worked like a charm! Used 3 as X btw. (: Also used 1 as your 'height', but meh.

private float CalculateFalloff(float falloff, float distance) { return 1.0F - MathHelper.Power(distance, 3F) * falloff; }

##### Share on other sites
Sorry for double-posting, but I figured I could post this in the same topic! Does anyone have a clue on how to do a Smooth-brush? Like the Startcraft II editor.

Thanks!

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013709
×