Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Smoothing Terrain... need help

Author
Message
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 10th Apr 2013 07:49 Edited at: 10th Apr 2013 08:22
I've developed a method of generating terrains which the user can edit in game. It works like so

The user chooses the base grid size - which equals the number of plane objects. The max size is 16x16 planes.

These planes are each 128.0 by 128.0 in size, and have 64x64 segments.

I store nine of them in an array, (3x3) the center of this 3x3 grid is the pick object. When I terraform (raise and lower) all nine objects enter the terraforming loop... that way seaming does not occur.

How do I use the nine objects to smooth the terrain and also level it? I know that the average would be adding all of the Y positions of each vertex together and dividing by the number of vertices would give me the average, but how do I smooth and level them (averaging is instantainious and is not like the leveling I mention... it's not asthetic.)

Tips, pointers, suggestions

EDIT for a more thourough analysis I've attached the project. You need Matix1 to run the project.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th Apr 2013 14:14
It's still easier with Blitzwerks terrain. lol

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 10th Apr 2013 14:54
I have tried to use it for the last figgin time - one of my plugins is conflicting with it everytime in every project IF I USE BLITZ - If you have anything helpful to add after knowing this information, please share - SMOTHING TERRAIN? Any ideas

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Apr 2013 21:16
sound like you need a 'falloff' range which incrementally offsets from the calculated average based on vertex distance from brush center. this way verts at the edge of the brush are moved only slightly towards average while verts closer in are affected more

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Apr 2013 23:24 Edited at: 10th Apr 2013 23:42
Wow the program looks really professional, should have been a WIP ages ago; unless you wanted to keep it secret...

After messing around with the program for 10 minutes I finally convinced myself to close it down and get on with my work.

Now I might not be on the same wavelength here when it comes to the leveling action you describe; but with terrain editors I've used, the level under the mouse cursor is simply used to override adjacent tiles. The height difference between each tile and the tile under the mouse is the distance; and the distance between the tile under the mouse and all tiles is the linear fall-off; and the linear fall-off is sometimes interpolated.

How this can be done in DBP is not something I've put my mind on; but before I put an idea accross, this reminds me of something that should have crossed my mind much earlier. Evolved, created a terrain editor (using BT Terrain or memblocks I think; I am sure one of his demos uses memblock terrains but when I talk like this I am usually wrong) which comes with his lighting kit; the source code is pretty extreme, but just letting you know it is there. It probably wouldn't fit in with your code if BT is incompatible with your plugin; might be worth letting the creator know about it.

If this is the first time hearing about Evolved, please browse his website and at least try out each and everything shader, tool and snippet he created, when you're done you will become a new man!!

Back to the leveling; If what I mentioned is what you want, then use the distances to apply movement to all of the adjacent tiles; multiplied by the fall-off which ranges from 1.0 * the difference to 0.0 * the difference between the height of the tile under the mouse compared with the tiles in fall-off range; fall-off is the distance between each tile and the tile under the mouse and is usually limited by a user control.

I always try to write down ideas and leave the idea on the side for a while until something better comes along; who knows something better might come along later.

I think a better way to treat the brush is to apply the principle of their never being just one instance of a given class; in this case the ObjectNum brush could actually be a series of object brushes; in turn each brush could have a bitmap which affects a multiplier of action across neighboring tiles.

A bitmap is much easier to manipulate than vertices, you could use a blurred brush to simulate smooth terraform, letting the colour values do the work. It only takes 4 seconds to create a smooth brush in a paint program.

Also, the Blur Bitmap command could be used to smooth the terrain; and shaders can be applied to the pixels using Image Kit. Also the actual fall-off could be variable, using pointers you could not only smooth the fall-off but randomize it to make crumple effects. You'd need to add each colour channel together to get more than 255 levels of detail.

It is faster to sample an Image Kit image pixel than it is to extract a vertex data position.

These commands come in handy with stuff like this: CurveValue, Wrap, WrapValue and the matrix1 curve commands EG: The [CURVE BEZIER Distance] and similar commands could control the fall-off.

One final note is that this could work 100 times faster if the terraform program was written in HLSL in a vertex shader. The advantage is you free up your CPU for more action; the down side is you cannot read the positions of the vertices (at least I'd assume) although what you would see is a terrain, the vertexdata would still be at position zero (I think...). Also, really old hardware might not support the vertex shader version that gives you enough array constants to play with, and obviously HLSL is more difficult to code and compile successfully.

If you happen to know HLSL, might be worth testing the speed difference between writing a vertex position via DBP vertexdata commands and writing a vertex array shader constant via Dark Shader commands.

Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 12th Apr 2013 15:18
Therein lie the issue (thank you for the detail!!!!!!!!!!!! That is setting me in one direction - and maybe the right one!)

I'm gonna bust out on the smoothing tid bit using the distance parameter to average the heights, Which will work perfectly in theory... but again it's theory

I do infact know quite a bit about shaders of HLSL and others and have writen some on more than one occasion. The trouble I was having with the one i was using was the heights of all the textures and - on top of that, with all those details, my shader ate a lot of power (aka frames per sec.) - So I gave that up and adopted the vertex coloring.

A side note - you can in a way, read the positions of vertices in an object, however to edit directly is something I've never done before.

The Brushes. Boy the brushes.
This has been the biggest puzzle of the thing. Mainly due to the fact of the seaming... which btw, I need to find out more indepth (that is I've asked but the answer was not comprehensible to me at the time) how to normalize the normals of the whole map and eliminate the 'nasty shadows'... I used the '3x3' grid to allocate the vertexdata in such a way that all 9 objects can be drawn at a time, and because of this, the frame rate SUCKS. If I increase the array housing the objects that will enter vertexdata (the brush if you will) so that a larger terrforming can take place, um... death.

I DO:
Have a wonderful idea but can't grasp how to do it yet... and that is:

1) Being that the planes are all flat at the start, do not sub-segment each plane, but rather tessalate (or form vertices in the mesh as it is edited.) But to do this, or, how is not apparent to me.

2) Water should FLOW. No, I wouldn't dare try to make a flowing liquid per say, but with a little thought I am sure I can ascertain how it can be done simply.

There is also the matter of time, a speed that can be adjusted by the user that WILL affect the terrain AKA, snow, water, drought and so forth will alter the shape and look of the terrain but not in such away that the user will have to continue to edit it (What is this "From Dust???" lol.

Memblocks have crossed my mind (is that a joke?) but until I see a variable change in speed, this method appears to be the fastest slow version

Leveling the terrain will also be a trick - not just smoothing... but one thing at a time.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 12th Apr 2013 18:05
Okay so here's a minute problem - I've been doing this



However this poses a problem, because if I click the top of a very steep hill, the hill does not shrink - infact, all smoothing seems to occur very MINIMALLY. The only thing that appears to occur is some very small changes to the surface.

So now I am thinking of a different form of smoothing, which may take some time to fathom (if I have misunderstood you however, then scratch that )

If you would like to see the updated code in detail then I will post - but I believe you will see that I am doing it correctly.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 12th Apr 2013 19:12 Edited at: 12th Apr 2013 19:15
Quote: "Leveling the terrain will also be a trick - not just smoothing..."


Smoothing generally recalculates the average as the brush is moved, keeping things gradually evening out.

Leveling grabs the average once at the start of the brush stroke and maintains this number until released, keeping things constantly moving towards a single level height.

Quote: "However this poses a problem, because if I click the top of a very steep hill, the hill does not shrink - infact, all smoothing seems to occur very MINIMALLY. The only thing that appears to occur is some very small changes to the surface.
"


are you checking the distance in 3 dimensions or just on the x/z plane? It sounds like the falloff is being applied vertically as well as horizontally, but should probably just be limited to the horizontal

Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 12th Apr 2013 19:18 Edited at: 12th Apr 2013 19:21
Actually I'm gathering the height of the terrain at the click location verses the vertex's y position within the alloted brush size - should I try three and see what happens or stick to just the height?

On leveling -

How then would I obtain a smoother edge, since that would give me a plauto looking thingy... not so asthetic... should I detect the distance from the edges downward to the surface below and normalize them or is there something more elaborate involved?

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 12th Apr 2013 19:25 Edited at: 12th Apr 2013 19:34
Quote: "Actually I'm gathering the height of the terrain at the click location verses the vertex's y position within the alloted brush size"


Right, but is the brush size spherical or circular when it comes to grabbing the distance of a vert from brush center? it should be circular, discounting height differences when calculating how much falloff should be applied.

falloff distance should be in terms of x/z positions only to get the falloff modifier then that gets applied to the y.

the reason why steep hills don't change much is that even though a vert may be 1 unit distance from the center in the x/z, it could be 20 units away in the y and if the falloff distance is being calculated with 3 dimensions it will think that the vert is very far from the brush, and while technically it is in actual space, for the purpose of the brush it shouldn't be.

On the leveling, you still apply falloff, but it will be a tighter range weighted towards the end. easiest way to desribe it is a picture i guess:



smoothing on left, leveling on right

Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 12th Apr 2013 19:29
AH! Okay let me try once more - and it's circular, distance outward from mouse (or proximity to mouse)

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 12th Apr 2013 19:36 Edited at: 12th Apr 2013 19:38
Double posting and appologies...

Okay so it looks like this:



My math must be wrong... silly vectors - trying to be 3d and sh*t.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 12th Apr 2013 22:41
I'd think that this:



should drop the Y parameters and calculate a distance in 2d terms

Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 12th Apr 2013 23:18 Edited at: 13th Apr 2013 09:12
That smooths yes, but If I make a solid single hill, and smooth the top, it should lower... instead it does nothing... I need to invert the scaling factor but dont know how.

actually I need to sin/cos the thing

EDIT

what I meant by that was to scale the fallof so that it is 0.5 at start, and 0.5 at end. I am not achieving the smoothing I am looking for - although this is VERY CLOSE... I need to tweak it a bit

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Daryn Alsup
18
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 13th Apr 2013 11:00
here's an updated project folder, run it (if you can) and see what you think

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!

Login to post a reply

Server time is: 2026-07-07 00:30:18
Your offset time is: 2026-07-07 00:30:18