Terrain Editor - Drawing a brush

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

Recommended Posts

Hi! I wonder what's the best solution to draw a brush on a Terrain for editing. ~Like this: I would draw a textured x*z grid slightly above the terrain which fetches the height values of it: Like putting a cloth on it. But I guess that's a bad solution, the brush texture will be blurry when some height values vary too much. Thanks.

Share on other sites
I would be interested in hearing some other suggestions for this also,

At the minute for my terrain editor I draw a textured grid like you said with a circle texture and alpha. It looks alright but like you say it becomes pixelated when height values are high, and becomes smaller and softer when you zoom out.

I think the best way would be to draw the circles out of lines because then you get a nice consistent line width regardless of your zoom level, but drawing a circle which deforms to the terrain, I'm stumped on that tried a few things myself and it didn't quiet work.

Share on other sites
You could draw the quad like you are already doing, but instead of using a texture use as function to define the color.

Compute the distance to the center of the quad and do:

return dist > r && dist < r*1.1 ? Yellow : Transparent;

For a terrain editor of my own I used a line strip for the circle, but the usual linestrip always has 1 pixel width, so the result wasn't very pleasant, because when you zoom in use lose focus of the thin line. However, I didn't cared, because it was just for my own use.
Of course you also could build a triangle strip that follows the circle.

Share on other sites
just an idea but could you use a pixelshader to draw the circle? Almost the same idea of a 2D metaball implementation?

if (minValue < lengthFromPixelToBrushTarget < maxValue)

Share on other sites
For my terrain editor (see here) I use lines.

Basically, I take the radius of the brush (you can adjust the radius to affect how much terrain is deformed in one go) and work out the number of vertices so that the length of each edge is approximately 1.0 (i.e. the spacing of the terrain vertices). Then I simply sample the height of the terrain at each vertex and offset it vertically by a little bit more.

When I first wrote it, I was worried that you might get a situation where the line would go "through" the terrain, but if you keep the length of each line segment smaller than one unit, there shouldn't be a problem.

Share on other sites
Can't you just make a circle in a texture, and when you draw the terrain, use a second map channel mapped to the circle texture?

Use the center point of the brush, and it's radius to calculate the texture coordinates based on the x,y of the pixel being rendered, and clamp the texture coordinates.

I know it's an extra texture read but it avoids having to worry about detecting which of the underlying geometry falls into the brush region.

-S

Share on other sites
Quote:
 Original post by SphetCan't you just make a circle in a texture, and when you draw the terrain, use a second map channel mapped to the circle texture?I know it's an extra texture read but it avoids having to worry about detecting which of the underlying geometry falls into the brush region.
However, that still doesn't solve the OP's problem of texture stretching on slopes.

Share on other sites
Quote:
Original post by swiftcoder
Quote:
 Original post by SphetCan't you just make a circle in a texture, and when you draw the terrain, use a second map channel mapped to the circle texture?I know it's an extra texture read but it avoids having to worry about detecting which of the underlying geometry falls into the brush region.
However, that still doesn't solve the OP's problem of texture stretching on slopes.

Ahh, my apologies - I missed that part of the questions (duh).

However, the original image posted suffers from the texture stretching. If that kind of stretching is acceptable, a suitably high resolution brush image should work.

Regards,
S.

Share on other sites
I just display the ground cursor in the pixel shader, with something like the following :
if( cursorVisible ){	float distFromRing = distance( IN.uvCoords, cursorPosition );	if( distFromRing < cursorSize )	{		float strength = max( 0, lerp( -1.5, 0.5, distFromRing / cursorSize ) );		color += float4( (cursorColor * strength), 0 );	}}

In my app, I keep track of the ground cursor's position (in terrain-relative [0-1,0-1] texture coords), size, and color and just pass those as parameters to the HLSL. No cursor texture required.

It ends up looking like this:

As you can see, this method hugs the terrain quite nicely:

Share on other sites
I very much like that, pretty, and what i was trying to get at=]

Scott

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×