Terrain Editor - Drawing a brush
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.
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.
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.
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.
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.
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)
if (minValue < lengthFromPixelToBrushTarget < maxValue)
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.
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.
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
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
Quote:Original post by SphetHowever, that still doesn't solve the OP's problem of texture stretching on slopes.
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?
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.
Quote:Original post by swiftcoderQuote:Original post by SphetHowever, that still doesn't solve the OP's problem of texture stretching on slopes.
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?
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.
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.
I just display the ground cursor in the pixel shader, with something like the following :
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:
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:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement