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 / Terrain generation and texturing...

Author
Message
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 5th Sep 2011 22:24
I think I found the problem. Please check again and sorry.


Cheers

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 22:24 Edited at: 5th Sep 2011 22:29
@ WLGfx Yea this time I did a closer evaluation and I see where I went wrong myself. Man this is not easy.. But this is what I have so far as far as Data Types are concerned. Its a 1 to 1.



Now all you should have to do is set the Globals of all the parameters that are to KEEP the values the functions created. I'm still working on seeing what all they are.

@ chafari Hey bro, that worked this time. Good job.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 22:30


I did find xfrac and yfrac earlier had a capital X and Y in them but I've fixed them ones. And, guess what... Still no joy...

The only globals required for the entire algorithm are set up in the PN_init() function.

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 22:43 Edited at: 5th Sep 2011 22:50
I am curious.. Since your obviously not using a matrix, are you setting the heights in this function ? function create_terrain(noise)

Its the only place I can see how your doing it. I am not sure how "set vertexdata position" and "set indexdata" is accomplishing your heights yet since I have not learned enough about object manipulation yet. I can only guess your turning an object into a terrain.

EDIT : Here is something you might be interested in seeing...



I changed from this..

t = (n * (n * n * 15731 + 789221) + 1376312589) and 0x7fffffff

To this :

t = (n * (n * n * 15731 + 789221) + 1376312589) // and 0x7fffffff

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 22:48 Edited at: 5th Sep 2011 22:48
Yep, I create a noise map first as an image (which currently isn't working). And then from that I read the height values and manually create a single object. Instead of using terrain functions, I'm creating a proper DBP object which can then be scaled, fx'd, etc...

What I might do is to start converting the entire code over again. I'm determined... I don't like computers telling me it's broke...

@chafari - I got it working...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 5th Sep 2011 22:48
Quote: "@ chafari Hey bro, that worked this time. Good job."



I was worried that my programs will not work on all computers, but it was all my fault . Thanks for testing it


Cheers.

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 22:51 Edited at: 5th Sep 2011 22:52
@ WLGfx scroll up. Showing you my test picture in case you missed it.

Looks to me that line is messing up the math somehow.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 22:56
I don't get that result. Damn... Did you change the xfrac and yfrac so they're both lower case?

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 5th Sep 2011 22:56
@WLGfx

Ok thanks. Just one question WLGfx, will us be able to export to .x or Dbo with your code ?, and can you use an entire single texture?


Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 22:59
Yes, because it creates a standard dbo object it will save as a dbo file. If you're after a .x file then you'll have to "make mesh from object".

When it comes to the texturing, I'll be creating a layered texture based on vertex height. The texture will also be able to be saved.

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 23:03
I've changed this function and I'm getting something:



The image shows up as a plain grey image now...

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 23:16 Edited at: 5th Sep 2011 23:28
Quote: "I don't get that result. Damn... Did you change the xfrac and yfrac so they're both lower case?"


yes. I got that result before and after I fixed it.

Also, I was playing with your noise functions. I am printing the two different types of results in the code and its not randomly generating the noise function which is also why it comes out as a flat surface.

Meaning your on the right track with your function as I am. I too tracked the problem down to your noise function.



What I am getting at is I see those numbers EVERY TIME. It does not randomly generate.

Here is the code I have so far :



EDIT : I too was messing with this Noise function like that and it also came up grey. So we are definitely thinking the same thing. Its the Noise function. Also did you notice that when it was grey your terrain was higher then normal? Meaning everything seams to be working. But your Noise generator is not.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 23:27
Just tried that code to see what was different. I think that "wierd_num" I added might not be compiling correctly as a double float.

The line "noise = create_noise_map(64,100)" creates a 64x64 terrain map with a seed value of 100. If you change the 100 to another value then you should get any number of terrains.

What I might end up doing is creating a command line exe from the C++ source code to produce a random perlin noise map.

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 5th Sep 2011 23:28
@WLGfx

I tested your program, and really works...I use another heightmap and generate a dbo, and I like it Good job.

Cheers.

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 23:29 Edited at: 5th Sep 2011 23:32
That actually makes perfect sense. The code had been preset to a specific number and so was coming out flat.

@ chafari Hey bro, he is having issues with another code on this thread. That's what we been talking about the whole time. What you tested was an already pre-generated heightmap. He is trying to generate it. Which is what he and I have been talking about this whole thread. I think thats where your confusing which code we are talking about. I finally understand what he is doing. Now. ( Once I understood him that is.. lol )

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 23:42 Edited at: 5th Sep 2011 23:43
@chafari - hope that code helps you understand a little bit more about manually creating a dbo object...

@JackDawson - At least now I'm getting a grey image. I've tried googling to convert this number "0.931322574615478515625e-9". I'm going to have a quick final check over the code, then I'll make that command line exe.

Making the command line exe means I'll use the DBPro's "execute executable" command. That way the exe will create a map file which can then be read straight in and converted to the mesh object.

EDIT: lol @ understanding where I'm coming from with this...

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 23:46 Edited at: 5th Sep 2011 23:49
@ WLGfx I'm not so convinced that number is the problem just yet. Remember that number worked when I took out the bitwise "AND 0x7fffffff" out.

Also I forgot to fix this in your code. I compared and this was not written right. ( function PN_init )

This is how it was written :

PN_randomseed = _randomseed;

and in a 1 to 1 with C++ here is what it should be :

PN_randomseed = 2 + _randomseed * _randomseed;

Check your code.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 23:51 Edited at: 5th Sep 2011 23:56
PN_randomseed = 2.0 + _randomseed * _randomseed

Yep, got that in there. (Yours says PN_randomsee)

This is where I'm at and getting a grey image: (I've altered the amplitude but accounted for it in the formula for getting the height.)



Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 5th Sep 2011 23:54 Edited at: 5th Sep 2011 23:59
Where did you get these settings from ?

PN_init(0.5, 8.0, 3.9999, 6, seed)

I believe that 3.9999 is your height. So where is those to be randomly generated ?

You originally had it set to this when we started out testing your code. PN_init(0.5, 8, 0.9999, 6, seed)

See the issue ?

EDIT : Yea that number goes to your _amplitude which is your height from the looks of it.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 5th Sep 2011 23:59 Edited at: 6th Sep 2011 00:02
They're the settings I had in the C++ version which created the original image in the very first post. The 'seed' value can change and also a very slight variations to _persistance, _frequency and _octaves makes different types of maps.

Where I've got 3.9999, I altered:

h# = PN_getheight( sx#, sy# ) * 32.0 + 128.0

to account for the amplitude change...

EDIT: definitely getting frustrating this now. I'm sure there's some major MAFFAMATIK buffs out there that would be able to go, hey, that's what's wrong...

Not that lucky though... (I'm gonna try the command line exe)

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 00:02 Edited at: 6th Sep 2011 00:05
Then that means this function you have, should be rewritten so that its randomly changing that number to represent your height correct ?



Because your trying to create a map with only ONE set height. 3.9999

EDIT : I am not convinced this was a math error. More a "where to put this" error. What comes first, chicken or egg type of thing.

If I could see your whole C++ code that would be better. From what you pasted, I am only seeing part of it.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 00:12
PerlinNoise.h


PerlinNoise.cpp


terraingen.h


terraingen.cpp


The entire project as it stands is currently at 27 files of .h and .cpp 's and only compiles under Pure GDK. I can strip the PerlinNoise class and use that for creating the command line exe. Having to load and save data still won't take up that much time.

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 00:17


Oh and the above. Forgot to add the test function...

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 00:18
Ok, what i'm going to do is come back to this when I am not so tired. I'll take a break, give the wife a pickle tickle and then i'll come back and be fresh when I try to convert this.

Also, just in case you were not aware.. the F. example : 0.0f

it changes things depending on how its used. I see not all your floats or double floats have this.

0.0f forces the number to be treated as a single precision floating point number (float). Normally, you'd only use this for assigning to a float:

float xxx = 0.0f;

When you do:

double xxx = 0.0;

It uses the standard, which is equivalent to:

double xxx = 0.0l; // long double

It might be worth looking at.

http://msdn.microsoft.com/zh-tw/library/tfh6f0w2.aspx

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 00:20


It probably won't make that much sense but as you can see from all the includes the project is getting rather huge...

It's the prelude to a game...

Warning! May contain Nuts!
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 00:23
Yea, it looks pretty big. All I needed was what generates your terrain so its all good. I'll get back to you once I get cracking on this.

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 00:24 Edited at: 6th Sep 2011 17:37
Cheers man... I'll get the exe working then post something within the next hour or so when I have something working. TV is poop at the moment...

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 02:27
Almost working, at least this time it's producing an almost terrain like output.

DBPro project is attached...

Just a few more tweaks...

The code not included in the project which generates the perlin noise data file is this:


I'll polish it up so that it works properly and then I can get straight onto working how to do the textures...

Watch this space... (Although I am working on a game myself, I will be releasing a lot of the source along the way)

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Sep 2011 02:50
Quote: "@ chafari Hey bro, he is having issues with another code on this thread. That's what we been talking about the whole time"


I was so tired that I had a break. I was trying in my old desktop what was wrong with my code, that I lost the thread of the talk sorry . Now as you know, I found the problem


Quote: "@chafari - hope that code helps you understand a little bit more about manually creating a dbo object"


We learn every day a bit more from each others . Thanks again


Quote: "I'll take a break, give the wife a pickle tickle "


So did I .

Cheers.

I'm not a grumpy grandpa
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Sep 2011 04:23
Yes it works now. It was a very clean texture, no bad connections or anything.

JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 04:54 Edited at: 6th Sep 2011 05:01
@ chafari.. I hear you brother.. I hear ya... lol


@ WLGfx.. looking now into the code. . MAN there is a lot here. I cannot blame ya for getting lost. This is going to take some time.

EDIT : I just checked out your download. You did it !!! It works.. Now you have randomly generated terrain. How did you figure it out ? I see two data types have changed from float to integer. Good job. Glad you got it solved.



"Life is like a box of chocolates.. eat it before it melts."
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Sep 2011 12:35
You can use somthing like this script to generate your heightmap. You can make it as ramdom pressing spacekey and you could paint over it to adjusted as you need it.






Cheers.

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 6th Sep 2011 15:37
blur bitmap !!!! I have been looking for that command. Thank you chafari !!!!

"Life is like a box of chocolates.. eat it before it melts."
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 16:46 Edited at: 6th Sep 2011 18:55
Nice work chafari. For the DBP version I should've gone down that route to start with.

Attached is everything I'm working with in DBP at the moment. Including the C++ source code.

IT NOW WORKS!!! I got the C++ code to output as bytes in the end.

If anyone can fixed the random texture generator function. Everything it produces so far is in shades of red...

The DBP code:


The C++ function:


Screenshot will go here in a mo...





Any questions just ask...

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 18:56
DOWNLOAD in the above post fully working...

Now using some references I've found I'm going to be working on texturing the different heights of the terrain...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Sep 2011 22:30
Quote: "blur bitmap !!!! I have been looking for that command. Thank you chafari !!!!"

You are welcome!!.

Quote: "Nice work chafari. For the DBP version I should've gone down that route to start with"

Thanks for your comments.

Quote: "If anyone can fixed the random texture generator function"


So that's what you trying still to find out?

Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 23:21 Edited at: 6th Sep 2011 23:23
Quote: ""If anyone can fixed the random texture generator function""

I coloured the object right at the beginning red and forgot about it so no matter what texture I put on it, it would always be a shade of red.

Using the Set Blend Mapping On command I've managed to get this:


Which gives the effect, dark areas at the bottom and lighter areas at the top...

Unfortunately I can't get detail mapping as well as blend mapping...

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 6th Sep 2011 23:43
Quote: "Unfortunately I can't get detail mapping as well as blend mapping..."


You could try with a seamless detail texture .

Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Sep 2011 23:47 Edited at: 6th Sep 2011 23:51
What I've tried so far is:

1. texture the terrain (standard texture)
2. blend mapped texture
3. detail texture

Which ever order I put blend and detail, the previous one gets cancelled out.

I'm wondering if there's a way to get all three texture modes working...

EDIT: I've just had a thought, using the height map info I could generate the detail texture and use the heightmap to darken and lighten it. Hmmm... Will this work?

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Sep 2011 00:04
Quote: "I'm wondering if there's a way to get all three texture modes working"


We can blend 8 textures at a time

Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 7th Sep 2011 00:06
At this time I wish someone would explain how???

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Sep 2011 00:16 Edited at: 7th Sep 2011 00:23
It looks like I won't find the example I had somewhere lost in my laptop....I found it in TGC forum, someone must know about it

EDITED I have found the example. Sorry, but I don't know how did the example to put credits to him.

Download example


Cheers.

I'm not a grumpy grandpa
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 7th Sep 2011 01:13
To clear the red on the object.

TEXTURE OBJECT objid, 0

That should strip all color and texture from the object. It should appear grey or white depending on the intensity of your lighting.

The Set Blend Mapping On command is a strange beast. I've played around with it a lot and managed to get a few decent results, but a shader is much faster and easier to deal with. I haven't messed with detail maps much at all yet, so I'm not sure what to recommend there.

To apply a Normal map and a Texture to an object,

SET BLEND MAPPING ON objid, 0, imgNorm, 0, 24
SET BLEND MAPPING ON objid, 1, imgTex, 3, 7

The basic rule of thumb is, it matters in what order you layer things. You always want to put things that affect the look of the contour of the terrain before any coloring. So in this example we're applying the normal map to stage 0, then using Addative Blending to apply the texture coloring. If you were going to add a specular map, you would do this,

SET BLEND MAPPING ON objid, 1, imgSpec, 3, 26

and move your texture down to stage 2.

There are many other ways to use the command but I've not explored all of them. I switched to shaders before I pulled all of my hair out.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 7th Sep 2011 01:38 Edited at: 7th Sep 2011 01:39
Thanks for that chafari... That's helped a lot... Now I need to figure out how to implement it for the different texture stages. I'm getting a white model so far, but I'll figure it...

@KisTech - I've just refreshed the page and read that. Hopefully that information will solve the problem for me... Amazing!

Warning! May contain Nuts!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th Sep 2011 02:08 Edited at: 7th Sep 2011 02:09
Quote: "I'm getting a white model so far, but I'll figure it..."


It could be your graphic card

That is what I see in my PC.



Cheers.

I'm not a grumpy grandpa
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 7th Sep 2011 02:12
On the code you posted I see that too but on my first trials on my terrain object I end up getting white. Probably the blend modes. Part of my aim is if it works on this laptop then it will work on other dodgy old machines. So far 8 texture stages work.

My plan now is to do some low res textures for different heights, blend them, and hopefully get a detail map over them.

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 9th Sep 2011 00:54 Edited at: 9th Sep 2011 00:54
I've blended 4 random textures together based on the height map data.



The added function so far that did this:



TO DO:

1. Blend the textures into each other...
2. Speed the creation code up a hell of a lot...

Warning! May contain Nuts!
Mugen Wizardry
User Banned
Posted: 9th Sep 2011 01:04
could u teach us how to use set blend mapping on?

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Sep 2011 01:05
Is there a way to squash the vertical texture so that it doesn't stretch? That would be ace!

Mugen Wizardry
User Banned
Posted: 9th Sep 2011 01:10
yea, save a VERY small version of the texture.

Now can u please teach us how EXACTLY u blend mapped these?

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !

Login to post a reply

Server time is: 2026-07-10 17:53:47
Your offset time is: 2026-07-10 17:53:47