Sign in to follow this  
Anand Baumunk

Marks on terrain

Recommended Posts

Anand Baumunk    699
Hello,
I'm currently working on my terraineditor.
At the moment I try to mark the part I edit with a circle. I tried to project it onto the scene with usual projected texturing, but that gave me some pretty wierd results. Now I want to ask if there is a better and more performat version to do this, or if what I did was going into the right direction.

Thanks

Share this post


Link to post
Share on other sites
Anddos    588
I dont know how todo what you do , but i was wondering how do you control the vertex buffer with mouse , like increasing the y vertices etc with left mouse button , i know you lock the vertex and index buffers but i dont know how you increment those locked vertices etc..

Share this post


Link to post
Share on other sites
hupsilardee    491
Keep your own copy of the heights array
[code]
float Heights[width*height]
[/code]
When the user clicks the mouse, loop through the region that is affected and increment as desired.
Then re-copy the array to the vertex buffer.

Is how I did it in a terrain editor I once made. It was highly performant even with a 1024x1024 terrain - the bottleneck was the rendering not the updating once the terrain reached that size. If you want to go much larger than 1024x1024 you could make a paging system.

Share this post


Link to post
Share on other sites
BCullis    1955
I'm assuming you're talking about drawing [i]the pointer/editor itself [/i]rather than modifying the terrain underneath the mouse. If that's not the case, disregard.

I use picking to translate mouse screen-position to the world position on the terrain that the mouse is hovering over, then render the circle that represents the "brush" originating at that world-space point, just like any other 3d object in the scene. I do that as the final part of my draw call so that it's always visible over the terrain.

Share this post


Link to post
Share on other sites
Gavin Williams    985
I pick the terrain point and basically render a light onto the terrain at that point. In the past I have just put that code in inside the terrain shader, but now I have it as a post process utilizing the position map in my gBuffer. The pixel shader is as follows :

[code]
float4 PShader(PSIN input) : SV_Target
{
float2 terrainPosition = gGBufferPositionUn.Sample(PointSampler, input.texcoord).rg;
if (distance(terrainPosition,gBrushPosition.xy)<gBrushRadius && distance(terrainPosition,gBrushPosition.xy)>gBrushRadius-0.1)
return float4(0.8,0,0,1);
else
return float4(0,0,0,0);
}
[/code]

I'd say that it's not very performant though, as it's fullscreen. For me right now, I'm still at 60fps so I haven't yet found the need to go over things for performance, but that is
certainly an easy way to do it if you are having problems.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this