# terrain blending

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

## Recommended Posts

hi, im trying to produce a blendmap for my terrain. ive worked out the angle of each point and can do something like:
grass = rock = 0.0

if angle > some_specified_angle:
rock = 1.0
else
grass = 1.0

blendmap.put_pixel(x, y, color = [grass, rock, 0.0])


but how do i make it do a more gradual blend between the rock and the grass texture? i guess i have to introduce some range factor for the blend but i cant think how to do it thanks dunk

##### Share on other sites
you could just transform the angle to get your blending factors -
if (angle > pies)     if (angle < end blending threshold)          rock = (angle - threshold) * blending factor

or something of that sort. You can probably fit it all in to a single equation, ie, rock = angle*PI/34.54+e^angle, or whatever.

##### Share on other sites
sorry i dont understand [disturbed]

could you be more specific on the maths?

thanks for quick reply tho :)

##### Share on other sites
Please excuse me for assuming lack of knowledge, but it's really simple. I'd suggest looking up interpolation. Or just general maths.

I even attempted to copy your style. Aren't I nice...
rock = (angle - min_rock_angle) / (max_rock_angle - min_rock_angle)if (rock < 0)   rock = 0else if rock > 1)   rock = 1

BUT, before you use that, I'll walk you through it.

angle - min_rock_angle -We want the rock to start when angle gets above min angle. So by subtracting min angle, we have > 0 where rock is, < 0 where it isn't.
/ (max_rock_angle - min_rock_angle) -Max angle - min angle will give you the range of angles where rock goes from nothing to full. So if we divide our angle (currently between 0 and ?) by it, we will get no rock - full rock from 0 to 1, like we want.
Then just make sure the rockness is in a reasonable range.

##### Share on other sites
Quote:
 Original post by RAZORUNREALPlease excuse me for assuming lack of knowledge, but it's really simple. I'd suggest looking up interpolation. Or just general maths.

thanks, sometimes i just get a block and cant see the wood for the trees.

i get it now and am successfully using it

##### Share on other sites
Kinda looks like an underwater scene, not knocking just commenting.

##### Share on other sites
the textures suck :|

##### Share on other sites
How do you calculate the "angle"? There appears to be something wrong because the middles of all the rocky regions contain grass.

I would do it like this:
    // Assuming Z is up, and N is the normal and it its length is 1    factor = N.x*N.x + N.y*N.y;    // Length (squared) of the projection of the normal on the XY plane                                   // Note: 1 is vertical terrain, 0 is horizontal terrain    lowThreshold  = 0.5f; // tweak this    highThreshold = 0.7f; // tweak this    rock = ( factor - lowThreshold ) / ( highThreshold - lowThreshold );        rock = min( max( 0.0f, rock), 1.0f );

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634076
• Total Posts
3015350
×