Basic Terrain Generator

Everything related to 3D programming
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Basic Terrain Generator

Post by Samuel »

zxretrosoft wrote: Background + textures where I can have as well? That's what you're asking? It would be better, but we still try the easiest option.
Backgrounds like skyboxs and entities that are not using this shader can have textures like they normally do.

But entities that are using this shader can not have a texture on it.

So, for example let's say you want your terrain to have a dirt texture and then have the red and green gradient be layered on top of that dirt as slightly transparent. This way you can still see the dirt through the red and green.
In order to do this the shader needs to be set up to receive textures. Maybe you won't want this, but I am just letting you know it's possible to do it.

zxretrosoft wrote: The tops of red and green bottom. It will be difficult to change in the shader?
If you just want to swap the two colors then that will be easy to do.


Here's what I'll do for now. After I get done with work I'll post the shader as it currently is. Then you can experiment with it and see what you want different or added to it. After testing it if you feel the terrain needs lighting effects and/or textures I'll set the shader up to receive them.

applePi wrote: thats also what i want to ask, so we have the option to change the meanings of the colors
also we may be able to have a function like "Picture to terrain"
I'm not really sure what you mean by "Picture to terrain"?

Currently the shader goes off of preset color values and those values are limited to either pure red, green, or blue.

What would be nice to do is to use purebasic's EntityCustomParameter() to send what color value we want at the bottom and also what color we want at the top. Then you wouldn't need to open up the shader to change the color values.

In order for this to work the shader needs to be altered to accept any color value for top and bottom.

If you or zxretrosoft want this then I can attempt to set the shader up to support it.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Basic Terrain Generator

Post by applePi »

Samuel said:
the shader needs to be altered to accept any color value for top and bottom
at first i write this: (yes this is what i suggest, so we don't have a hard wired shader but flexible one.)) but later i saw a problem: what about the possible other colors between these top and bottom colors, it turns a difficult theoretical problem and an ambiguity of what we want. so my end suggestion is not determined yet, i need more ideas about the relations between colors and heights .

regarding the picture to terrain, i mean picture to 3D: it is may be related to the above discussions. i saw in MP3D an example picture to 3D, the program OpenFileRequester ask first "Please choose Gray scale Highmap", and we choose a colorful picture ,and the second OpenFileRequester ask: "Please choose Colormap" ,i choose the same picture , and it draws a 3d picture (terrain !!) from that picture. but it has sharp spikes. and i don't know how it consider the colors.
this is like this:
2d picture:
Image
resultant 3d picture
Image

rotated:
Image
User avatar
zxretrosoft
Enthusiast
Enthusiast
Posts: 171
Joined: Wed May 15, 2013 8:26 am
Location: Czech Republic, Prague
Contact:

Re: Basic Terrain Generator

Post by zxretrosoft »

applePi said:
what about the possible other colors between these top and bottom colors, it turns a difficult theoretical problem and an ambiguity of what we want. so my end suggestion is not determined yet, i need more ideas about the relations between colors and heights
Yet this is sufficient for me. I assume that this effect Samuel had somehow managed. This is an excellent beginning for further experiments.
http://s38.photobucket.com/user/Samuel2 ... c.png.html
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Basic Terrain Generator

Post by Samuel »

applePi wrote:it draws a 3d picture (terrain !!) from that picture. but it has sharp spikes. and i don't know how it consider the colors.
Image to mesh generators rely heavily on the image. The reason you're getting sharp spikes is because the image is jumping from a dark pixel to a light pixel very rapidly.

For example take a look at the image below. The left skull is using your unedited skull image and like your example it has many sharp spikes.
But the image on the right is nice and smooth. That's because I gave the image a slight blur to smooth out the pixels.

Image


Here's the blurred greyscale image I used. It's in greyscale because my generator doesn't support colored images.

Image


This same logic should apply to MPZ's example.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Basic Terrain Generator

Post by applePi »

thanks Samuel, you are right, i have tried the blurred image with mp3d and now it is much better smooth 3D.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Basic Terrain Generator

Post by Samuel »

I updated the download link in my original post. There's now a new example called Terrain Generator HLSL.

The material script has custom inputs built in. Which allows us to specify any color we want for the top and bottom of the terrain from within purebasic.
I give a little description on how this works within the example.

This shader doesn't allow lighting or textures on entities that are using this shader. If you decide you want those effects let me know and I'll set them up when I have some free time.

If you have any questions just ask and let me know if anything doesn't seem to look right.
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Basic Terrain Generator

Post by Mythros »

So wait.. a 2D image to a 3D model? This is BRILLIANT! =D (Even though I had that idea years ago)

Can you please add texturing so that it works without all the spikes using the shader?

Thank You so kindly! :)

Sincerely,

~Mythros
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Basic Terrain Generator

Post by Samuel »

Hello Mythros,
Mythros wrote:So wait.. a 2D image to a 3D model? This is BRILLIANT! =D (Even though I had that idea years ago)
It's actually a fairly simple process and image to mesh generators have been used in games since the early 90s.
So, there's plenty of info out there on how to build one.
Mythros wrote: Can you please add texturing so that it works without all the spikes using the shader?
I can add texture support within the shader, but you'll still have the gradient effect with it.

You could try my Terrain Generator.pb example it doesn't use the shader and just adds a simple grass texture to the terrain after it's built.
Maybe that's more towards what your looking for?

If it's not then I guess I'm not quite understanding what it is your after.
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Basic Terrain Generator

Post by Mythros »

@Samuel: What I'm looking for is simple. Creating half of an entire object (such as that human skull in this thread above, and giving it enough depth to ACTUALLY BE half of a human skull and not like a thing where it's a FLAT 3d model such as a 3d pir graph looking object hanging on the wall, so I can turn around, create a copy of the terrain, and flip it upside down on its X-Axis so it creates a whole skull. :)
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Basic Terrain Generator

Post by Samuel »

Now I think I understand what it is your after.

You could use this generator to calculate the 3D points, but I don't think the facing routine is good enough for what your after.
If you use my facing routine you'll most likely end up with jagged edges. As it's built for creating terrains or raised objects.

What you might want to look into is Delaunay triangulation.
This is a popular method for triangulating 2D and 3D objects.

All you would need to do collect all the 3D points from your images. Then send those points to a Delaunay triangulation procedure and voila you'd have a 3D mesh of your image.
User avatar
zxretrosoft
Enthusiast
Enthusiast
Posts: 171
Joined: Wed May 15, 2013 8:26 am
Location: Czech Republic, Prague
Contact:

Re: Basic Terrain Generator

Post by zxretrosoft »

Samuel, thanks!
Your upgrade (HLSL gradient) is exactly what I was looking for. Now I'm going to study a little bit, especially how to change the colors.
If you were to add the option to put forth the background (I think textures are not necessary), it would be perfect :wink:
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Basic Terrain Generator

Post by Mythros »

Is there an example you can show me that does this so I can mess about with the Delauney Triangulation function to see if I can maybe better it?

Thanks SO kindly, Samuel! :)

Sincerely,

~Mythros
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Basic Terrain Generator

Post by Samuel »

@Mythros

Comtois posted an example for 2D triangulation with some links.
http://www.purebasic.fr/english/viewtop ... 12&t=57820

Also here's a Youtube video on Delauney triangulation which might help you understand the process a little better.
http://www.youtube.com/watch?v=IqdSdbxrTsY
I'm sure there are other videos on the subject floating around as well. This is just the one that I watched.

Both Comtois example and the video only cover 2D triangulation, but once you learn the 2D the 3D version should be fairly easy to understand.
The main difference between the two is 2D uses circumcircles and 3D uses circumspheres.


@zxretrosoft
If your talking about skyboxes they should still work like they normally do.
Just add the location of the skybox images in a 3D archive and then you can create the skybox.

For example.

Code: Select all

Add3DArchive(#PB_Compiler_Home+"\Examples\3D\Data\Packs\skybox.zip", #PB_3DArchive_Zip)

...

SkyBox("stevecube.jpg")
User avatar
zxretrosoft
Enthusiast
Enthusiast
Posts: 171
Joined: Wed May 15, 2013 8:26 am
Location: Czech Republic, Prague
Contact:

Re: Basic Terrain Generator

Post by zxretrosoft »

Yes, it works normally. Thanks;-)
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Basic Terrain Generator

Post by Mythros »

I was never any good at 2D unfortunately... :/
Post Reply