Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

Marks on terrain

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 gnomgrol   Members   -  Reputation: 625


Posted 21 October 2012 - 10:54 AM

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.



#2 Anddos   Members   -  Reputation: 520


Posted 22 October 2012 - 08:24 AM

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..

#3 hupsilardee   Members   -  Reputation: 487


Posted 23 October 2012 - 01:53 AM

Keep your own copy of the heights array
float Heights[width*height]
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.

#4 BCullis   Crossbones+   -  Reputation: 1813


Posted 23 October 2012 - 10:57 AM

I'm assuming you're talking about drawing the pointer/editor itself 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.
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#5 Gavin Williams   Members   -  Reputation: 779


Posted 24 October 2012 - 04:34 AM

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 :

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);
  return float4(0,0,0,0);

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.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.