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 / "Brushing" the terrain?

Author
Message
Hayer
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 20th Jan 2008 10:21
Hi!
I have already read the
"Heightmap Terrain Brush + Conform/Mold Plain Object to Matrix Surface Help" thread, but didn't find much about UV-texturing.
So my problem atm is that I want to texture my terrain like a brush.
I select a texture, drag the mouse over the terrain, and "zimzalabim"
the vertices that I "touched" is now textured.

Any cidesnippets? Pointers? Tutorials?

Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 20th Jan 2008 10:47 Edited at: 20th Jan 2008 10:48
Well, I'm using this method:

I calculate the minimum and maximum position from my brush on both X and Z axis, and then I calculate which pixels it are.

eg. 128x128 texture, 500x500 size:
MinPixelX = 128 / 500 * minX
MinPixelY = 128 / 500 * minZ
MaxPixelX = 128 / 500 * maxX
MaxPixelY = 128 / 500 * maxZ

Then I loop:
for x = MinPixelX to MaxPixelX
for y = MinPixelY to MaxPixelY
...
next y
next x

and in the loops, I edited the memblock made from the texture image, brush image and world texture image. The new color is based on the old color, brush greyvalue and texture color.

red = WorldRed + ((TextureRed - WorldRed) / 255.0 * BrushRed * Hardness#)
where Hardness# is an extra factor to make it more transparent (0(completely invisible) <= Hardness# <= 1 (no transparency))

I don't have code snippets to actually paint on a 3D object, since those calculations would probably be alot harder...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Hayer
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 20th Jan 2008 14:28
so I need to loop all the vertices each time I press the "bursh-button"?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Jan 2008 17:57
I think Sven B means you to recalculate minX, etc, each time - so you only loop through the vertices that are likely to be affected.

Sven said:

Quote: "I calculate the minimum and maximum position from my brush on both X and Z axis, and then I calculate which pixels it are."
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 20th Jan 2008 19:09
Quote: "I think Sven B means you to recalculate minX, etc, each time - so you only loop through the vertices that are likely to be affected."


That's pretty much it, except for:
I think Sven B means you to recalculate minX, etc, each time - so you only loop through the pixels that are likely to be affected.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 20th Jan 2008 21:09 Edited at: 20th Jan 2008 21:12
Hayer! What's going on man

Here's a description of what I'll be doing, and I'm pretty sure Van B is doing the exact same thing.

Do you remember that 32x32 matrix, which in turn becomes a tile for a larger 10x10 matrix composed of those 32x32 matrices as each of it's tiles example (lol)?

Well, I'm not exactly there yet, so I might be off on a few things, but take this into heavy consideration.

When I started learning about texture brushing I too was under the impression I had to mess with the UV's a lot and paint each one individually. Forget about individual UV stuff and think larger. Think color mask shaders. For each one of those 32x32 tiles in that 10x10 matrix, a color mask shader will be there.

Whats a color mask shader you ask? Green Gandalf wrote a shader that takes an image, looks at it's rgb values and decides to place what texture where based on those rgb values and their positions. Now, right about now your thinking, well, that limits me to 3 textures. Right. But, Van B has modified that shader to be able to output 6 textures, which IS a good amount. But if your still not satisfied, think about how I have one shader running on each of my 32x32 tiles. Whats to say I can't use a certain combination of 6 textures on one tile, and a different combination of textures on the tile over? (Still thinking that last bit through)

However, if I have a 10x10 matrix, thats 100 shaders running, and that's a lot of requirements. But, that's where you need to get fancy with culling and other FPS requirements. Actually, right now, without culling, my 100 tiled matrix takes about 10 seconds to load, which isn't bad considering I haven't done much to optimize the code or start culling. In short, there is a lot that could be done to help this shader thing along.

A problem that I'm going to have to think about it order to get larger terrains per map is about the amount of limbs DBP likes... Right now, I've heard DBP only likes to work with 256 limbs at a time, it CAN do more, it just doesn't like it (stupid). So... if your already doing the math, that limits me to a 16x16(256) tiled matrix. I already know I can halfway combat this by simply increasing the stile size from 32x32 to like 128x128. But then the shaders take longer to load. When the time comes, I need to ask Van B what he does with his because he's doing the same thing with the color mask.

Want to see how sexy things can get with a color mask shader? This is a pic from Van B's editor.


"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Hayer
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 22nd Jan 2008 17:32
Hehe, been away for a while.. So i'll be readin trough my "very commented code"

and gettin' memblocks running..
i managed to use directX (c#) to make 4 welded vertices, but i dont know how i did it xD

Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Jan 2008 17:47
Sid, I've never seen this editor before. Where did you find it?

Your signature has been erased by a mod
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 17:49
Hayer, take a look at my little tutorial for memblocks found in this thread. I also posted LIT's welding code there too. Since you and djchaos are pretty much at the same level right now, I'd follow that thread pretty closely.

Both of you could learn a lot from that heightmap/terrain brush thread of mine too if you read through it and look at the snippets.

http://forum.thegamecreators.com/?m=forum_view&t=122177&b=1

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 22nd Jan 2008 17:58
You may want to look at these three terrain shaders I wrote: http://forum.thegamecreators.com/?m=forum_view&t=121575&b=1

Quote: "However, if I have a 10x10 matrix, thats 100 shaders running"


No it's only a single shader if you only apply one to the whole object, the same code gets run for every vertex/pixel anyway so it should run at a similar speed if you made a shader for every limb individually(though there would be little point).

Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Jan 2008 18:07
I believe he's talking about a 10x10 matrix of objects each one having 16x16 limbs. As he explained it's not feasible to get a single object with the level of polys he's talking about.
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 18:19 Edited at: 22nd Jan 2008 18:22
Quote: "I believe he's talking about a 10x10 matrix of objects each one having 16x16 limbs. As he explained it's not feasible to get a single object with the level of polys he's talking about."


No, I think you misunderstood my description lol. Have 100 objects and each having 16x16 limbs would be insane! Thats 25,600 limbs total! A little over the 256 limb limit that's been discovered.

Does anyone know if it's roughly 256 limbs total that DBP starts to have trouble with? Or 256 per object? Ian just gave me an idea...

Quote: "No it's only a single shader if you only apply one to the whole object, the same code gets run for every vertex/pixel anyway so it should run at a similar speed if you made a shader for every limb individually(though there would be little point)."


Thanks for pointing that out, I was under the impression it was otherwise. I'll have to go back in my code and just apply it to the object. Think there will be any gain in loading time?

Quote: "You may want to look at these three terrain shaders I wrote: http://forum.thegamecreators.com/?m=forum_view&t=121575&b=1"


I have, and they are very nice . I'm going to be modifing GG's shader or one of yours to do 6 texture blends instead of 3, like van b did. Good work on that example though, it's been helpful to a lot of people

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 22nd Jan 2008 18:24
Oh I see, so that's 25,600 limbs? That's crazy as DBP isn't exactly designed for high object/limb counts. You need to look into making some type of LOD system where the farther you are from any given terrain object the less limbs and verts/tris it uses, that would put far less strain on the frustum culler and draw speed.

Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 22nd Jan 2008 18:26
Quote: "No, I think you misunderstood my description lol. Have 100 objects and each having 16x16 limbs would be insane! Thats 25,600 limbs total! A little over the 256 limb limit that's been discovered."


Yeah; hence why I meant the objects would be separate, not linked together. My impression was certainly that DBP does not have any universal limbs limit. I've never run into that with using tens of thousands of objects with limbs.
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 18:30
Quote: "Oh I see, so that's 25,600 limbs? That's crazy as DBP isn't exactly designed for high object/limb counts. You need to look into making some type of LOD system where the farther you are from any given terrain object the less limbs and verts/tris it uses, that would put far less strain on the frustum culler and draw speed."


What? Go back and reread the messages, your misunderstanding. I'm not making that many limbs. I have 256 limbs, and thats are far as I'm going with the limb count. I plan on doing a culling system anyway... 25600 limbs... what do you take me for?

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 18:41
Holy crap, thanks for that shader tip DC, I just changed it and my editor loads about 10x faster, rofl. Loading the shader on the object and not every limb won't affect texturing painting at all will it? Thats kind of why I thought I had to do it on every tile (each tile is a 32x32 matrix as a limb.

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 22nd Jan 2008 19:30
Quote: "Loading the shader on the object and not every limb won't affect texturing painting at all will it?"


No you can just do it on the whole object, this also mean you should texture the object itself with each of the texture layers and not each individual limb(or at least that would be faster). Also remember that my shaders(the vertex and texture blend ones) aim to use maximum layers of textures so if you have any shader knowledge you can remove any unused layers for extra speed.

Also I'm not sure what method you're currently using but you should only need to load a single terrain(or generate one) and clone that 99 times and edit the heights of all the verts via the vertexdata commands, as that will likely be the fastest method to generate so any, plus you wouldn't have to texture each object again this way.

Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 19:57
Thanks, I'll look into it.

Quote: "Also I'm not sure what method you're currently using but you should only need to load a single terrain(or generate one) and clone that 99 times and edit the heights of all the verts via the vertexdata commands, as that will likely be the fastest method to generate so any, plus you wouldn't have to texture each object again this way."


-I make a very small triangle.
-I then make a 32x32 memblock matrix mesh, convert it an object, then make a mesh from the object (I hear this process does some stuff? Otherwise I would never convert it an object to begin with)
-I weld the verts
-Then I use that 32x32 matrix mesh as tiles for a 16x16 matrix (each 32x32 is one tile in the 16x16 matrix). Obviously those tiles are limbs.

Hope that clarifies

The reason I use the triangle is to fix a problem Jason P Sage and I came across with texturing. Limb zero acted weird with the welded vert version of the mesh... so we both made a triangle because limb 1 and up were fine. Problem solved. Plus I like being able to cull every limb and not worry about that one object inside of my grid.

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Jan 2008 20:51
I tried searching for VanB's editor but cant find it. Does anyone have a link?

Your signature has been erased by a mod
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 21:37
His editor isn't out yet. His plans are to release the full source before he modifies it for his game, but no telling when that will be.

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jan 2008 21:44
Arghhh, completely forgot about that. Will look into it.


less is more, but if less is more how you keeping score?
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 22nd Jan 2008 23:10
Good to hear

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 23rd Jan 2008 10:05
Got a lot of work done on it yesterday, so it should be uploaded tonight, just got to tidy up the code a bit and tart up the gui a little. Was missing a menu system and didn't want to leave it with my weird taste in hotkeys, but that's all sorted now.


less is more, but if less is more how you keeping score?
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 25th Jan 2008 06:49
So... how's it coming Hayer/Van B?



"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 25th Jan 2008 09:25
Soz about that, it's been a busy week but moreover, everytime I get stuck into it to wrap it up I end up adding stuff!. I'm happy with it though, so I just need to comment the code - not gonna promise it for tonight due to a certain son and World of Warcraft, but if not tonight it'll be tomorrow.


less is more, but if less is more how you keeping score?
Sid Sinister
19
Years of Service
User Offline
Joined: 10th Jul 2005
Location:
Posted: 27th Jan 2008 23:56
How's that commenting going?

"If I have seen a little further it is by standing on the shoulders of Giants" -Isaac Newton
-Computer Animation Programming Major @ Baker.edu-
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 29th Jan 2008 00:14
Commenting is done, well it's a bit ropey as usual but it's wrapped up:

http://forum.thegamecreators.com/?m=forum_view&t=122906&b=5&p=0


less is more, but if less is more how you keeping score?

Login to post a reply

Server time is: 2025-05-18 05:38:19
Your offset time is: 2025-05-18 05:38:19