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 / Memblock Mesh as Terrain Matrix in Real Time

Author
Message
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 30th Aug 2010 04:02
Hey everyone,

I've spent the last several hours looking through various threads on here describing how to create and manipulate memblock matrices, and have a bit of a better understanding now, but I'm still confused on a few things and where to go with some things...

I'm wanting to implement a terrain editor into my current world editor. I've looked into Advanced Terrain, but it doesn't seem to be editable in real time, only using heightmaps and texture maps to load once. Same with BlitzTerrain. So it seems my best option is to use memblock matrices. However, this presents several problems as well:

I've done this before, but the way I did it didn't work out well. For one, in order to save the data for later editing, I had to save the height of every coordinate of the matrix, meaning if I only had a 100x100 matrix, I'd have to save and load 10,000 points.

Another problem I had was with texturing. The way I did it was made 2 memblock matrices stacked on each other, and changed the alpha of the one on top to "paint" that texture. Obviously this is impractical since it means that I'd have to double the number of polygons to have more than one texture.

So my questions/problems are:
-How can I save/load memblock matrix data efficiently?
-How can I have multiple textures that blend together well without having a separate memblock matrix for each texture?

Thanks.


Lost in Thought
22
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 30th Aug 2010 06:49 Edited at: 30th Aug 2010 06:51
Have a look at green gandalf's blended terrains thread he just posted a few days ago. Texture blending is the answer for the extra polys problem. http://forum.thegamecreators.com/?m=forum_view&t=174731&b=1

You are gonna have to save the points though ... how else are you gonna read them back in? It's not so hard to save though. Write memblock and read memblock?

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Aug 2010 07:14
BlitzTerrain is editable in realtime, check out the black hole demo.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 30th Aug 2010 07:21 Edited at: 30th Aug 2010 08:39
Thanks for the help! Yeah, I did see GG's texture blending, but that seems to be for premade Advanced Terrain, whereas I'm using real-time memblock mesh painting :/.

Hmm...I'll look into saving and reading memblocks. Saving the object itself isn't time-intensive, but I was writing each point as a string to a file, which is what took so long.

EDIT:
Quote: "BlitzTerrain is editable in realtime, check out the black hole demo."

Sorry, just saw your response, posted at the same time. Thanks, I'll look for it!


Lost in Thought
22
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 30th Aug 2010 08:57
He only used advanced terrain for a quick way to show it working. You can make his technique work with any object. Only for terrains it might be best to use the limb version of the new functionality? If I was going to do a terrain editor I'd try to use it though it's not the easiest. I think it would run the fastest. I have actually thought about adding this to my 3dw importer ... if I have time I will.

3dws uses 1 mesh per layer and paints the alpha values to the verts. And you only need to have double polys where the texturtes blend together so it's not so wastefull really. I do this in my 3dw importer.

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 30th Aug 2010 10:19
I suggest not bothering with memblock meshes too much. They don't support indices, and so you'll have around 3X as much vertices. Create a subdivided plain first, and apply the vertexdata commands on its vertices.

Cheers!
Sven B

Syncaidius
21
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 30th Aug 2010 14:36 Edited at: 30th Aug 2010 14:38
Theres also a MAKE OBJECT PLAIN Object number, Width, Depth, Columns, Rows command you can use in IanM's matrix1 plugin set that allows you to create a subdivided plain with X and Y amount of subdivisions.

Quoted from Matrix1 help file:
Quote: "Any plain created can only have up to 65536 vertices or the command will fail. The number of vertices is calculated as (Columns+1)*(Rows+1)."


So by that formula, I assume they are created with indices data included.

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 31st Aug 2010 01:04
Great, thanks for the help .

Well now I'm not sure whether to use BlitzTerrain (although it seems the commands for real-time manipulation are undocumented...), memblock matrices, or subdivided plains (which I have no experience with).


James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 31st Aug 2010 01:19
Have to say I played around with blitzT but as of yet is not the perfect solution - I have my own memblock terrain stuff which is nowhere near as good as blitzT but when push comes to shove, subdivided plains useing shared indexes makes a lot more sense when you consider how much of a part that shaders play in programs...
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 31st Aug 2010 05:10
I'd imagine that subdivided plains combined with the VertexData commands could make a pretty decent terrain .

I made a water function here:
http://forum.thegamecreators.com/?m=forum_view&t=174821&b=6

It wasn't difficult to do, and I believe that the verticies are organized by row/column. So adjusting the height and everything shouldn't be a problem.


Guns, cinematics, stealth, items and more!
Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 31st Aug 2010 05:27 Edited at: 31st Aug 2010 05:29
You just load an image into a memblock and then update the verts based on the data in the memblock. If you want to edit the vertices, you just edit the memblock instead. This is much easier method and your mesh can be highly optimized and any arbitrary shape.

I've attached a project that should give you everything you need, including seven sample "tablecloth" meshes to work with -- the "terrain_512_v7" is the one I like best, good framerate (~130fps on 5year old hardware), and no LOD "snapping." I don't have the actual "edit" functions in there, but all you'd have to do to add editing is to add a cursor and the memblock edits.

...and of course, you'll want check out TERSCULPT by VanB:

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

...which includes complete source code

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 31st Aug 2010 06:10 Edited at: 31st Aug 2010 06:15
Wow, thanks again for the excellent help . I'll play around with both options and see what I can come up with, thanks for the examples, those will definitely be useful .

If I were to use plains with vertices, what would be the best way to go about texture painting?


Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 31st Aug 2010 06:26 Edited at: 31st Aug 2010 06:40
For texture painting, you'd use another memblock - but this time the memblock data is used to modify the RGB values that are going into your image-blending shader. So, for example when you want to add more of terrain texture 1 to a spot, you would increase the R channel value. To decrease terrain texture 2, you would decrease the B channel value and so on.

So, if you look at gg's image blending mixer shader for terrains (which I was also using in my example), the image you'd be editing via a memblock is mask1.png for the first 3 textures and mask2.png for the second 3 textures.

Instead of updating the vertices of the mesh each update, you would instead be saving the mask file so that the shader can see the edits to the mask. This _sounds_ like it would be horribly slow, but really it's not at all -- I remember doing one for OMEN long ago, and it was able to do this at 60 fps for a 1024x1024 mask (on very old hardware at the time).

hehe that was a long time ago - I think I still have a video though

http://www.youtube.com/user/darrelcusey?feature=mhum#p/u/8/oc1MqAqBoto


But you could get more terrain textures into your blend shader by using fewer bits in your mask per terrain texture - you don't _really_ need all 8 bits of precision for a blending shader - you could probably get away with just using 4 bits per terrain texture, so 1 mask could get you as many as 8 different textures (with 2 masks, you could get 16 textures).

One thing you have to be careful of though is "overblending" -- this happens when your have multiple channels each contributing too much in one area. When this happens, the actual source terrain texture data combines to effectively just give you white - so you get this "white streak effect" that looks bad. To compensate, as you increase a given channel, you need to simultaneously decrease the contribution of all other channels in such a way that their combined contribution is equalized.

For example if you increase channel R by 10% and you have 5 other channels, each of the other 5 channels needs to be decreased by 2%.

Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 31st Aug 2010 16:12
I have a question though, how would you transfer the 3d coordinates where your brush is painting the texture into the correct position on the memblock image?

My computer surpasses all the technologies of the day. What computer do I have?

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 1st Sep 2010 00:43
Quote: "I have a question though, how would you transfer the 3d coordinates where your brush is painting the texture into the correct position on the memblock image?"

Yeah, I'm not really sure about that either, about to try and figure it out. If anyone has any tips, it'd be greatly appreciated .


Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 1st Sep 2010 01:36
for a weird rolling object like that, I'd say some collision plugin (the built in collision functions might work... I've never rly used them though)
I *think* you could use SC_raycast and sc_getfachit to look up the UV coordinates in the object's memblock mesh data, but I've never done it. That would allow you to paint stuff onto any object.

If you don't want to do that, you could use your collision function to find the point wherever you're clicking intersects with the terrain, discard the y value, and use the x/z values to draw a pixel in the right spot (Ex. If you're terrain went from 0,0 to 20,20, and your collision point was at 4,3, then the u/v coordinates would be 4/20,3/20)

Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Sep 2010 01:38 Edited at: 1st Sep 2010 01:42
I'd do it like this:

Image X = (3DXPos/TerrainWidth) * Image Width
Image Y = (3DZPos/TerrainLength) * Image Height

where 3DXPos and 3DZPos are your X/Z coordinates.

Then convert the image coordinates to memblock coordinates, which I can't remember how to do right now... Try a forum search?

EDIT:
A quick search turned this up:
http://forum.thegamecreators.com/?m=forum_view&t=166123&b=7

Or if you're lazy you could use this:
http://forum.thegamecreators.com/?m=forum_view&t=172059&b=6


Guns, cinematics, stealth, items and more!
Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 1st Sep 2010 05:01
Sixty Squares has it right, it's pretty much just this:

imageBytes=4
imageX = (terrainX/terrainWidth) * imageWidth
imageY = (terrainY/terrainWidth) * imageHeight
pixel = (imageY * memblock dword(mem, 0)) + imageX

...then to get the color
color = memblock dword(mem, 12 + (pixel * imageBytes))

...then to set the color
local mycolor as dword
mycolor=rgb(0,200,200)
write memblock dword mem, (12 + (pixel * imageBytes)), mycolor

...then to save the image so that the shader can pick up the change
local myimageID as integer
myimageID = 1
make image from memblock myimageID, mem
save image "mask1.png", myimageID

unfortunately, there's no way (at least none I know of) that will allow you to directly manipulate the images stored in the textures buffers on the GPU... now THAT would be amazing

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 1st Sep 2010 05:19
Great, that makes sense, I'll try it out .

Another problem I've run into (although I haven't actually tried to solve it yet, just thought about it) is determining the position on the matrix corresponding with where the mouse is for raising/lowering/editing the terrain. I'm looking into using pick screen, but I'm not sure that's the best method.


Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 1st Sep 2010 05:28
This should help -- it's pulled right from World of OMEN, so it won't work out-of-the-box (too many dependencies), but it should give you some ideas. This is the code that will move an object around a scene once an object has been selected:



Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 2nd Sep 2010 02:49
Awesome, that works great, got a simple raising/lowering terrain working now . Thanks again for the help.


Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 2nd Sep 2010 04:02
@Gil,

Sure anytime - I just hope to see more pirates in the future from ye

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 2nd Sep 2010 05:57
Quote: "Sure anytime - I just hope to see more pirates in the future from ye "

Haha, well that's what this is for, so hopefully .

Okay, I'm having some trouble with this terrain painting. I can't find any documentation on how to actually using GG's blended shader, so I'm looking at your code for the terrain test:


So what exactly does the shader do? Blend the texture's you give it? Do the first two textures have to be masks? And how do the masks work exactly? I see they seem to have RGB values that represent each texture?


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Sep 2010 13:04
Quote: "I can't find any documentation on how to actually using GG's blended shader, so I'm looking at your code for the terrain test"


Could you post or email me a simple complete demo including the shader and media (but no exe file) plus a description of what you're trying to do and I'll try to explain? I need the shader you're using because I have several blending shaders and I need to know which one.

I've just realised someone sent me an email some time ago with a similar query and I forgot to reply. Sorry about that (even if it wasn't you ).
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 2nd Sep 2010 19:40 Edited at: 2nd Sep 2010 19:40
Quote: "Could you post or email me a simple complete demo including the shader and media (but no exe file) plus a description of what you're trying to do and I'll try to explain? I need the shader you're using because I have several blending shaders and I need to know which one.
"

Great, thanks for the help . I've attached the current progress (I even cleaned and commented it for you ). Part of the problem is I don't know which shader to use, so I included 3 of them.

I'd like to be able to paint the terrain in real-time by clicking on it with an option of several textures (I'll probably just use the keys 1-[num of textures] to choose which one for now, but first I'd like to just get one working). So I'm just confused where to even start, really. Thanks for the help .


Math89
22
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 2nd Sep 2010 21:46
My advice for terrains is to use IanM's MatrixUtils dll for generating a grid of high-poly plains. This give you the advantage of indexed meshes (which can't be done with memblocks) and frustum culling (since your terrain is made of several objects). For the edition, you can then use vertexdata commands.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 2nd Sep 2010 21:47
Quote: "My advice for terrains is to use IanM's MatrixUtils dll for generating a grid of high-poly plains. This give you the advantage of indexed meshes (which can't be done with memblocks) and frustum culling (since your terrain is made of several objects). For the edition, you can then use vertexdata commands. "

Yup, that's what I ended up doing (for now at least, and it seems to work great) .


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Sep 2010 22:42 Edited at: 2nd Sep 2010 22:53
Quote: "I've attached the current progress (I even cleaned and commented it for you ). Part of the problem is I don't know which shader to use, so I included 3 of them.

I'd like to be able to paint the terrain in real-time by clicking on it with an option of several textures (I'll probably just use the keys 1-[num of textures] to choose which one for now, but first I'd like to just get one working). So I'm just confused where to even start, really."


I'll look at it after the weekend as I'll be away till then. It seems like you need two things:

1. a means of editing an image/bitmap according to which texture you want to use, e.g. paint it red if you want to use texture 1, or paint it medium yellow (i.e. half red, half green) if you want a mixture of textures 1 and 2, etc

2. a means of putting it all together to get the final terrain texture.

I guess you need the shader for point 2 but not for point 1.

Perhaps you could confirm that I've understood correctly? You might also need a means of blurring the joins between adjacent areas. When I get back on Monday I'll check the thread to see what has already been suggested.

Edit I agree with Math89's suggestion to use IanM's high poly plains for terrain. I use them as limbs as in Advanced Terrain for my own terrains except in simple demos where I use AT for convenience. Perhaps I shouldn't use limbs? I have yet to do a performance check of objects versus limbs. Math89, have you done the comparison?

Edit2 Gil, just a quick note to confirm that your demo works and is easy to follow. Nice. I'll see what I can do when I return.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 2nd Sep 2010 23:28 Edited at: 2nd Sep 2010 23:30
Alright thanks .

Quote: "Perhaps you could confirm that I've understood correctly? You might also need a means of blurring the joins between adjacent areas. When I get back on Monday I'll check the thread to see what has already been suggested."

Yup, sounds like you understand correctly.

Quote: "I agree with Math89's suggestion to use IanM's high poly plains for terrain. I use them as limbs as in Advanced Terrain for my own terrains except in simple demos where I use AT for convenience. Perhaps I shouldn't use limbs? I have yet to do a performance check of objects versus limbs. Math89, have you done the comparison?"

Yeah, that seems to be working well so far.

Quote: "
Gil, just a quick note to confirm that your demo works and is easy to follow. Nice. I'll see what I can do when I return. "

Great, thanks .

I'll give it a try this weekend, but not sure how far I'll get since I'm no sure how exactly to apply the shader. I understand the concept of using RGB to define which texture goes where, but not really sure how to "feed" that to the shader, or if I even need to.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Sep 2010 00:04
Quote: "I'll give it a try this weekend, but not sure how far I'll get since I'm no sure how exactly to apply the shader. I understand the concept of using RGB to define which texture goes where, but not really sure how to "feed" that to the shader, or if I even need to."


OK. If you can get the painting side sorted out I can show you how to get the shader to use the resulting image. Don't worry about painting the right colours as that can be fixed easily.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 3rd Sep 2010 07:18
Well that was easier than I expected, thanks to Sixty Squares and Omen . It doesn't blend the textures, but I can now paint pure red, pure green, or pure blue onto the surface. Hopefully this is close to what you meant Green Gandalf, I'll attach here.


Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 4th Sep 2010 04:12 Edited at: 4th Sep 2010 04:12
This is pretty simple implementation of painting (see attached project).

--> I had to remove the water plane because DBPro's built-in shaders seem to interfere with custom shaders.

--> I switched the mask textures to bitmaps because bitmaps never loss quality with distance from camera. If you use any image format other than bmp/tga for masks then you lose detail with distance (roads disappear and other oddities).

--> Added the textures and shader to the terrain object

--> You had the vertexdata lock/unlock being done every frame instead of just when changes were being done to the vertices. Fixed this.

--> Added "Erasers" for both mask 1 and mask 2 (they paint black to "erase" other channel data

--> Added an option to save or not save the changes done from painting.


I tried to make as few edits as possible and kept all the code in-line with what you were doing. Should all be pretty self-explanatory in the code.

Mugen Wizardry
User Banned
Posted: 4th Sep 2010 04:22
Use LandGenerator by Smaas. It is like the ULTIMATE terrain generator that I can find. It also comes with an example which is VERY easy to implement into your game. Do not forget to credit Smaas though. The Generator is in the WIP thread.

CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD! http://www.imageposeidon.com/
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 5th Sep 2010 08:18
Excellent, that's exactly what I was looking for, it seems the implementation of the shader is even simpler than I expected, thanks again for the help .

Quote: "I had to remove the water plane because DBPro's built-in shaders seem to interfere with custom shaders. "

I think the issue was actually that the image number for the water was 2, which was also the image number for one of the painted textures, seems to work fine now .

Quote: "Use LandGenerator by Smaas. It is like the ULTIMATE terrain generator that I can find. It also comes with an example which is VERY easy to implement into your game. Do not forget to credit Smaas though. The Generator is in the WIP thread. "

I have checked that out, and it's very impressive, but that's for creating prebuilt terrains which you can export to your game, I want real time editing of terrain within the world editor .


Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 6th Sep 2010 09:27
Alright, I've run into one problem...when I raise the terrain by a certain amount (which isn't too much), just try the one Omen attached and raise the terrain for about 2-3 seconds, it begins to turn black. I'm guessing this is part of the shader. Is there some way to turn it off or another version that doesn't do this?


Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Sep 2010 10:41
You may need to adjust the normals on the edited terrain?

My signature is NOT a moderator plaything! Stop changing it!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Sep 2010 14:26 Edited at: 6th Sep 2010 16:08
Quote: "just try the one Omen attached and raise the terrain for about 2-3 seconds, it begins to turn black"


I'll look into that. [Edit I don't see it getting black - just darker because of the assumed light direction hitting the terrain at an angle presumably. But not sure why that's happening yet.]

Quote: "You may need to adjust the normals on the edited terrain?"


I don't think so. [Edit You're probably right - I should have looked at the shader you were using first.] Anyway I'll have a look at Omen's code later today. It seems to have some minor bugs - things like memblock or array out of of bounds errors in some situations. I guess the checks when the "brush" gets near the terrain edges need to be tweaked (or added - I haven't checked yet).

Edit2 The darkening is not connected with the normals as far as I can tell - it's more likely because the shader assumes a positional light which is probably not what you want for terrains. With a positional light as you raise or lower the terrain you change the light's distance from the vertex so the light intensity will change. A directional light might be more appropriate - but then you would need normals. Let me know which you prefer and I'll see if there's an easy fix.

At the moment Omen's code doesn't seem to make it easy to apply all six textures - but it's an excellent start and he's shown how to apply the shader.

Once I understood the controls the code seems to work well except for one thing - the revised terrain isn't saved which is a shame because you get the updated mask image when you re-run the program. Perhaps you could load/save a dbo file each time so you get the latest version of the terrain when you re-start?

There were two things that I found awkward:

1. if I rotated the object the mouse clicks no longer lined up with the object
2. it was difficult to select specific vertices when I made a mistake (you'll be surprised how many times I forgot to hold down CTRL when trying to paint ).

One solution to both problems would be to use small marker objects for each vertex, small red spheres perhaps, and use pick object to decide which vertex had been selected. Then once you've selected a vertex change its colour to yellow perhaps so you can see what's happening. I've used that myself and it works well for this sort of thing and is independent of rotation.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 6th Sep 2010 19:34
Hey Green Gandalf,
Sorry, I should've said that I have fixed most of those problems while implementing them into the rest of my world editor . I added bounds checking for the memblocks, I fixed the problems that came with adding a texture from one mask to a texture of another, added a save function for both the terrain and terrain texture, you can't (and don't need to) rotate the object, but have a free moving camera, the controls are much easier (UI buttons instead of keys), I added a "flatten" and "level" command to set the height of vertices, and am in the process of adding a cursor. I would attach it for you to see, but now it's all integrated in the world editor and would take a while to pull it all out again unless you really need me to .

As for the shading, a directional light sounds like it should work, do I just need to add one and set the light?


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Sep 2010 13:55 Edited at: 7th Sep 2010 17:38
Thanks for the clarification. Sounds like you've got most things in place. Have you managed to integrate all six textures into your editor using the two mask images?

Quote: "As for the shading, a directional light sounds like it should work, do I just need to add one and set the light?"


You need two things: adjusted normals every time you modify the terrain heights, and some changes to the shader code. You'll also need some code in your dba file to set the light direction and colour. I'll see if I can illustrate what I mean using Omen's code. Probably later today.

Edit Here's a revised version of Omen's code. The changes are:

1. save edits set to 1 in the dba file
2. rewritten shader for directional light plus several changes to bring it into line with my present shader style
3. added set object normals to dba file (press returnkey for this)
4. changed the texture scaling so you could see the original textures more clearly.

Other than these it's essentially Omen's code.

The normals are recalculated in this line:



For some bizarre reason set object normals doesn't seem to take effect until the lock/unlock pair is executed - hence the inclusion of the empty pair. Looks like a bug to me but at last there seems to be a simple workaround.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 8th Sep 2010 02:11
Quote: "Thanks for the clarification. Sounds like you've got most things in place. Have you managed to integrate all six textures into your editor using the two mask images?"

Yup, they seem to be working great so far .

Great, your example with the new shader seems to work great. The only issue I have is that it seems to have darkened all of the textures(obviously they're dark when in shadows, but overall they are darker. Any idea why this could be?


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2010 02:30
Quote: "Any idea why this could be?"


Yes. I've changed the default light direction so it's at an angle to the ground instead of pointing straight down (makes it easier to see the effects of changing the normals). You can change that back and see if the original lighting has been restored. Rather than change the shader, the best way is to take control in DBPro itself by adding something like:



Make sure you do that after the shader has been loaded and also after the vector has been created.

Another reason is that I didn't try to adapt the lighting code of the version you were using - that lighting code isn't mine and had some odd features that I didn't bother to try to understand. One of them probably brightened the lighting. Actually I thought my shader was too bright - you get supersaturated colours at some light angles.

Another thing you can try is to change the levels of ambient light and the directional light colour - these are the vectors ambientColour and lightColour in the shader. Again the best way is to change those in DBPro as I mentioned above. The four components are red, green, blue and alpha respectively with 0 being no light and 1 being full light.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 8th Sep 2010 02:50 Edited at: 8th Sep 2010 05:46
Ah, got it . Is there some kind of reference to these internal variables (such as ambientColor, lightDirection, lightColor, etc.)?

EDIT: Also, new question: How would I go about painting one texture onto another a bit at a time (so it starts faded and the longer you hold it, the more it paints). I don't know how I'd get the current RGB values, and I assume I'd need them in order to change them by a small amount at a time. Then there's also the issue of dealing with textures from two different masks. So I'm basically confused on all aspects of it.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2010 14:53 Edited at: 8th Sep 2010 14:55
Quote: "Ah, got it"


Actually, what I said before was slightly misleading. While what I said was correct, I'd overlooked the fact that the original version you were using has the following line:



I'd forgotten it used the final factor 2 to brighten the final result. I suggest you just play with the values of lightColour and ambientColour till you get the result you want. Ideally the individual colour values of lightColour and ambientColour should add to 1 to avoid oversaturated colours (unless you want that effect of course or if you just want to brighten everything). For example you might have lightColour = {0.8, 0.8, 0.8, 1.0} and ambientColour = {0.2, 0.2, 0.2, 1.0}, i.e. the two red components add to 1 and so on (they didn't in my demo ). I suggested keeping them in the range 0 to 1 - but you can go outside that range if you want a special effect. The final colour rendered to the screen will have values in the range 0 to 1.

Quote: "Is there some kind of reference to these internal variables (such as ambientColor, lightDirection, lightColor, etc.)?"


They are variable names I decided to use - and I've used them in such a way that the four components in each of them are interpreted as {red, green, blue, alpha}. For terrains you would usually keep alpha at 1 and adjust the others. This arrangement makes it easy to align my colour vectors in calculations with the final colour output by the pixel shader (which is always in the RGBA order with components clamped to the range 0 to 1).

Quote: "Also, new question: How would I go about painting one texture onto another a bit at a time (so it starts faded and the longer you hold it, the more it paints). I don't know how I'd get the current RGB values, and I assume I'd need them in order to change them by a small amount at a time."


Good question. One way would be to use a "brush" that fades towards the edges - but that might be awkward to implement. Another way would be to use the blur bitmap command. This would have the effect of blurring the joins between two adjacent textures and might be all you need. However, in my experience that is slow and slightly unpredictable as it seems to shift the whole bitmap by a few pixels in some ill-defined way. If you use it sparingly, after doing lots of other changes for example, you might find it works. A tailor-made blur bitmap command would be faster - for example why bother blurring (i.e. averaging) pixels which are the same? (Of course, by the time you've programmed that you could have used the slow blur bitmap command thousands of times over. )

On balance I'd be tempted to go for a modified brush. For example, here's the painting bit of Omen's code:



That just uses a square "brush" which replaces the existing memblock colour value for a block of pixels with mycolor. You could use a blend of the existing colour and mycolor instead and adjust the blending by how far "i" and "j" are from 0. Actually, the more I think about it that's the way I would go.

I imagine you can get the current RGB values simply by using the read memblock dword command which corresponds to your write memblock dword command.

Quote: "Then there's also the issue of dealing with textures from two different masks."


Perhaps we can deal with that later.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 8th Sep 2010 20:19
Quote: "I'd forgotten it used the final factor 2 to brighten the final result."

Ah, makes sense, I'll play around with it .

As for texture painting...I started playing around with adding two colors together, but realized that by just getting the memblock value, I don't know how to extract the red, green, and blue values out of the dword returned, which would probably be important in deciding which values to change. So I guess my question for now is, how do you extract the RGB values out of a dword? Thanks again for the help .


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2010 21:42
Quote: "So I guess my question for now is, how do you extract the RGB values out of a dword?"


Just use the rgbr(), rgbg() and rgbb() commands. In this case the RGB components should be aligned in the same way.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Sep 2010 19:24
Here's a simple example of the modified paint brush that I had in mind a couple of posts back. It's not ideal but should give you something to start from.



You'll need to declare oldcolour as a global dword somewhere in your code.
Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 10th Sep 2010 03:04
Awesome . Thanks to your example, I got it working excellently in my world editor:


I owe you one for all the help and the awesome shader .


Omen
19
Years of Service
User Offline
Joined: 7th Nov 2006
Location: Maple Grove, MN US
Posted: 10th Sep 2010 04:49
Nicely done Gil

Gil Galvanti
21
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 10th Sep 2010 05:13 Edited at: 10th Sep 2010 05:13
Quote: "Nicely done Gil "

Thank you, many thanks to you as well, would've been very difficult without your code examples .


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 10th Sep 2010 11:57
Quote: "I owe you one for all the help and the awesome shader"


You're welcome - and it's great to see my suggestions being put to such good use.

Omen's clear painting code was an excellent place to start and I'll probably use something similar when I do something like this.

Login to post a reply

Server time is: 2026-07-22 12:41:40
Your offset time is: 2026-07-22 12:41:40