Showcase
Showcase your work that you have created in the Skyline Game Engine.

Procedural Island

Procedural Island

Postby planetX » 21 Jan 2018, 12:07

Hi there,

I was messing a bit with procedural generation and finally could implement a Perlin Noise inside Skyline. :D

Code: Select all
-- ======================================================================
-- original code by Ken Perlin: http://mrl.nyu.edu/~perlin/noise/
-- ======================================================================
local function BitAND(a,b)--Bitwise and
    local p,c=1,0
    while a>0 and b>0 do
        local ra,rb=a%2,b%2
        if ra+rb>1 then c=c+p end
        a,b,p=(a-ra)/2,(b-rb)/2,p*2
    end
    return c
end

perlin = {}
perlin.p = {}
perlin.permutation = {}
perlin.size = 256
perlin.gx = {}
perlin.gy = {}
perlin.randMax = 256

-- Random Pattern
function randomSeed()
   local n = 256
   local t = {}
   for i = 1, n do
      t[i] = i
   end
   for i = 1, n do
      local j = math.random(i, n)
      t[i], t[j] = t[j], t[i]
      perlin.permutation[i] = t[i]
      --sky.lprint("permutation: "..t[i] )
   end
end

function perlin:load()
   -- Random Seed
   randomSeed()
    for i=1,self.size do
        self.p[i] = self.permutation[i]
        self.p[255+i] = self.p[i]
    end
end

function perlin:noise( x, y, z )
    local X = BitAND(math.floor(x), 255) + 1
    local Y = BitAND(math.floor(y), 255) + 1
    local Z = BitAND(math.floor(z), 255) + 1

    x = x - math.floor(x)
    y = y - math.floor(y)
    z = z - math.floor(z)
    local u = fade(x)
    local v = fade(y)
    local w = fade(z)
    local A  = self.p[X]+Y
    local AA = self.p[A]+Z
    local AB = self.p[A+1]+Z
    local B  = self.p[X+1]+Y
    local BA = self.p[B]+Z
    local BB = self.p[B+1]+Z

   return    lerp(w, lerp(v, lerp(u,    grad(self.p[AA  ], x  , y  , z  ),
                                          grad(self.p[BA  ], x-1, y  , z  )),
                     lerp(u,             grad(self.p[AB  ], x  , y-1, z  ),
                                          grad(self.p[BB  ], x-1, y-1, z  ))),
                     lerp(v, lerp(u,      grad(self.p[AA+1], x  , y  , z-1),
                                          grad(self.p[BA+1], x-1, y  , z-1)),
                     lerp(u,             grad(self.p[AB+1], x  , y-1, z-1),
                                          grad(self.p[BB+1], x-1, y-1, z-1))))
end


function fade( t )
    return t * t * t * (t * (t * 6 - 15) + 10)
end

function lerp( t, a, b )
    return a + t * (b - a)
end

function grad( hash, x, y, z )
    local h = BitAND(hash, 15)
    local u = h < 8 and x or y
    local v = h < 4 and y or ((h == 12 or h == 14) and x or z)
    return ((h and 1) == 0 and u or -u) + ((h and 2) == 0 and v or -v)
end

function Perlin_onInit()
   perlin:load()
   doPerlin()
end

function doPerlin()
    for i=1,200 do
        for j=1,200 do
         local x = i-1
         local z = j-1
         local y = perlin:noise(i/10, j/10, 0.3)
         if ( y > 0.05 ) then
            entity.spawn("node_cube",x,10,z,1,1,1)
         end
        end
    end
end


Since I'm unable to modify the vertices from a mesh, all I can get is a minecraft style terrain...

Image

Image


But there are some values I can use in my own functions, like the density of the noise...


Image


... and certain heights:


Image


That allowed me to populate an entire island with vegetation randomly, following some interesting patterns.

First I've created the palms, using a Perlin noise at a certain level, then I throw a ray down and spawn only those palms which are 2 meters over the sea level. That avoid the palms getting too close to the shore.


Image


Each palm will hold a cluster of grass meshes around, at a random distance.


Image


Then I spawn the bushes with the same Perlin noise but a lower level, to avoid colliding with the palms.


Image


Finally, the rocks don't have a perlin noise, just spawned around randomly, but they are clusters as well.


Image


This is one of the random levels. Every time I click play, these values change:

total_palm: 253
total_grass: 7590
total_bush: 8199
total_rock: 200

I even can make a dynamic map... Darker dots are the palms and the lighter ones are the bushes.


Image


There are still some work to do regarding to object placement in order to avoid overlapping, but already got a decent procedural environment. It's a pitty that I can not generate a terrain in the same way, with different biomes and much bigger. I only can use a custom terrain mesh, which is a huge limitation.

Anyway, here's a short video of a character walking around the island. Hope you like it! ;)





Cheers

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby lordalmighty1 » 21 Jan 2018, 12:52

nice vid and setup there m8 :).
just 1 thing i noticed the trees poppin in are not viewable from further out? seems rather close atm for them to player like.
have fun stay safe wot
rig NVidia i7 950 quad core @ 3.07 gtx1060 3gb gddr5, 12gb ram 1600mhz 120ssd 1tb hdd 1tb ex-hdd win10 pro 64bit
rig AMD A8 7650K Quad Core @ 4.0, gtx750ti boost 2.0 2gb gddr5, 16GB DDR3 1600MHz RAM 1tb hdd win10 pro 64bit
User avatar
lordalmighty1
Skyline Moderator
Skyline Moderator
 
Posts: 441
Joined: 02 Jan 2014, 12:13
Location: uk
Skill: Great creative
Skill: Level Designer

Re: Procedural Island

Postby SolarPortal » 21 Jan 2018, 14:04

wow, impressive! Procedural generation looks really good.. nice densities and clusters.. Nice work m8! :)

As for the vertice editing, its on the todo list so users can create custom meshes or at least modify terrain vertices..
But what you have done seems to be working really well... looking forward to seeing how this progresses
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Procedural Island

Postby StarFire » 21 Jan 2018, 15:04

Awesome! You rock! :shock: :shock: :D
I am blown away, this concept has a lot of mileage. As with your other project I am am excited to see this develop. :D :D

We did look at noise generation of vegetation and other procedural placement of in game content such as spawn points, health, survival items. But we are still a long way from playing with it. I never imagined that through Lua alone you could get great results and you beat us to it lol! Awesome, like I said, you Rock man!

I think vertex will have to be passed to Lua now :D

You could develop this into an editor side tool with its own skyline ui and sell it in the new store?

Again keep up the great work! :D :D
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1418
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Procedural Island

Postby planetX » 21 Jan 2018, 16:20

Thanks guys, glad you like it... all this came because I needed some sort of scenario to try this: :lol:


Image


StarFire wrote:I never imagined that through Lua alone you could get great results


Lua is cool but it's too slow for this purpose. Generation times are too long and it lags a lil bit. I feel like I'm pushing the limits with this little island. We would need something faster in order to create a vast open world. At least that's what I've read somewhere, I'm not really an expert in software engineering. :D

Anyway that was a lot of fun.

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby StarFire » 21 Jan 2018, 16:31

This is where c++ is faster, I think there could be a way of creating the noise or some sort of procedural function to run c++ side and only feed it some raw data from lua. This way the performance in generation would be fast but controlled from lua settings.

The run time lagging or popping could be smoothed out, thats if its due to the spawning of the items as the player moves?

BTW like the survival ui ;)
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1418
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Procedural Island

Postby planetX » 22 Jan 2018, 11:01

StarFire wrote:thats if its due to the spawning of the items as the player moves?


All the items are spawned at onInit(), then I show/hide them depending on the distance from the player.

Set all of them as static BTW.

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby planetX » 24 Jan 2018, 09:29

Hi,

I'm having problems to export this level as an exe. Tried to follow SolarPortal advice but getting errors and crashes when executing it. Actually I got the same problems no matters the project, is there any example level I can use to check if exporting is working? Because I could never export a game from Gen2...

lordalmighty1 wrote:nice vid and setup there m8 :).
just 1 thing i noticed the trees poppin in are not viewable from further out? seems rather close atm for them to player like.


Sorry m8, totally missed you... the camera settings are temporary, it will be much closer to the player so you wont see any tree popping in.

Cheers

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby planetX » 24 Jan 2018, 09:32

And have another question: is there any way to detect when the mouse is hovering an entity in the scene?

Thanks! :)

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby SolarPortal » 24 Jan 2018, 14:38

you could use a raycast, that when it hits the player is hovering and when not is not hovering.. the same ray could then be used to detect other hovering objects etc...

this is the way i would look into first.
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Procedural Island

Postby planetX » 24 Jan 2018, 16:19

Hi SP, thanks for reply. I have no idea where to start, so I'll make the question in a different way:

Imagine I have a cube in the scene, that when I click on it, it disappear. How do I code the mouse interaction part?

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby StarFire » 24 Jan 2018, 17:16

To tell the system to use the mouse ray for scene detection ie To click an object
use:
Code: Select all
game.enableMouseRay(1);


Best put this in the master control script , generally the scene script but it really doesn't matter as long as its called before you need to click on the object.

Next you would want a small script on the clickable object as this can now receive mouse click events due to enabling the mouse ray.

Code: Select all
obj = 0;
function onInit(objID)
   obj = objID;
end

function onClick( hitID  )
   entity.delete( obj );
end



hope this helps :)
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1418
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Procedural Island

Postby planetX » 24 Jan 2018, 17:28

It helps a lot, thanks... :D

So that's for clicking, but is there any way to get the object ID on mouse over?

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby StarFire » 24 Jan 2018, 19:07

yes sure, try this in an object script or scene script:

Code: Select all
function onUpdate(timeDelta)
   x,y,z = sky.raycastToCursor();
   hitID = entity.getLastHitEntityID();
   sprint("> "..hitID)
end


:D
Dream the Journey, Live the Experience!
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1418
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Procedural Island

Postby planetX » 24 Jan 2018, 21:02

Brilliant! :shock:

Thanks! :D

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby SpiderMack » 27 Jan 2018, 08:37

That's a good start :D

An important aspect is vegetation you create must be modifiable with terrain tools, otherwise you can't tweak manually to create unique places like any game has.

Some ideas you could expand it if textures selection was available for plugins :
- Use external tiling texture instead of noise option
- Add texture bitmap selection for masks (no spwaning in mask areas like lakes, rivers or city zone)
or allow spawning only some selected objects in some area masks.
- If you can modify terrain heights : texture heightmap stamps you move,zoom ,scale around terrain and stamp to create complex terrains in seconds

Expose tweak parameters (terrain height levels, ground texture color, noise type, noise parameters)
or add new ones like spacing parameters : for groups of trees , rocks or bushes, distance between each object (random between min max values)


If you need some ideas, you can read Horizon game presentation
https://www.guerrilla-games.com/read/gp ... -zero-dawn

And some video about their advanced painting tool


If vegetation gets back into Skyline engine, your tool could be a great addition.

(Why users showcase or projects are pinned in all threads as announcements ? it's a little weird as they are not engine features)
User avatar
SpiderMack
Skyline Expert
 
Posts: 437
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Procedural Island

Postby epsilonion » 01 Feb 2018, 12:34

Great that someone has picked up the procedural side of things, looking great mate..

I like the hair movement and cloth simulation in that video (above), can not wait till that's available in Skyline oh and destructible meshes and terrain deformation like driving over soft mud lol do I ask to much? lol great features to be added though..
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Procedural Island

Postby SpiderMack » 01 Feb 2018, 20:20

epsilonion wrote:Great that someone has picked up the procedural side of things, looking great mate..


Skyline devs should also pick up procedural.
For example Ghost Recon Wildlands world is all made by procedural tools : terrain, sculpting, roads, towns, houses ...
User avatar
SpiderMack
Skyline Expert
 
Posts: 437
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Procedural Island

Postby planetX » 02 Feb 2018, 11:15

epsilonion wrote:Great that someone has picked up the procedural side of things, looking great mate..


Thanks m8, glad you like it. :)

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby SpiderMack » 03 Feb 2018, 20:26

Are your trees and grass using LOD ? because we see lot of popup.

1 ) Can it handle a bitmap mask colors ? For example red color to mask where grass is allowed, green color for where trees are allowed and blue for where rocks are allowed ?

2) Using raycast does it avoid placing grass or trees on top of houses for example ?

Your plugin is great and could be integrated in Skyline as a base for procedural terrain generation why not.
User avatar
SpiderMack
Skyline Expert
 
Posts: 437
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Procedural Island

Postby epsilonion » 04 Feb 2018, 14:25

http://pcg.wikidot.com/ is a great source of procedural tutorials and examples.. :P
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Procedural Island

Postby planetX » 05 Feb 2018, 19:57

SpiderMack wrote:Are your trees and grass using LOD ? because we see lot of popup.

1 ) Can it handle a bitmap mask colors ? For example red color to mask where grass is allowed, green color for where trees are allowed and blue for where rocks are allowed ?

2) Using raycast does it avoid placing grass or trees on top of houses for example ?

Your plugin is great and could be integrated in Skyline as a base for procedural terrain generation why not.



I'm not using LODs atm but planning to do it. There are some functions to detect terrain textures, but they are still in development. You can define collision flags if necessary, but in a desert island there are no houses. ;) But yeah, if you want specific features, you have to code them. That's why scripts were invented.

This is not a plugin, it's just a small script I've used to generate random positions in a bit more realistic way. Far to be perfect, it's just an experiment. We all know the capabilities of AAA engines, but the point is doing something with the tools we have.

@epsilonion: I have been reading a bit about procedural content generation, including some of the links that you've posted above (thanks btw) and that's something that requires a lot of knowledge that I don't have atm. But I found some simple lua scripts to generate mazes and dungeons that maybe I could implement in Skyline. ;) I have some characters ready to be used, but feel lazy to model a level, maybe that helps. :lol:

My specs: Windows 10 - Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz - 16 Gb ram DDR4 - NVIDIA GeForce GTX 960M 4 Gb

planetX
Skyline Mage
 
Posts: 207
Joined: 28 Nov 2016, 18:27
Skill: 3D Modeller
Skill: Level Designer
Skill: Concept artist
Skill: Great creative
Skill: Programmer

Re: Procedural Island

Postby epsilonion » 05 Feb 2018, 22:10

The Santa running game (below) uses procedural tiling, Starfire can give you more of an incite in this as I have just browsed over procedural content.

https://www.forum.aurasoft-skyline.co.uk/viewtopic.php?f=53&t=1801&p=9964&hilit=santa#p9903

Maybe you could experiment with https://www.shadertoy.com/view/ltffzl and skyline..
then teach me... it blows my mind.. lol..

I would love to be able to create shaders to use in skyline but can not get my head around it atm, must be a age thing. lol
User avatar
epsilonion
Skyline Moderator
Skyline Moderator
 
Posts: 818
Joined: 26 Feb 2015, 11:51
Location: East Yorkshire, England
Skill: Business Manager
Skill: Great creative

Re: Procedural Island

Postby SpiderMack » 02 Mar 2018, 11:07

planetX wrote:
This is not a plugin, it's just a small script I've used to generate random positions in a bit more realistic way. Far to be perfect, it's just an experiment. We all know the capabilities of AAA engines, but the point is doing something with the tools we have.



Procedural is the way to go for games focused on big outdoors and exploration.
If we got access to terrain vertex position and be able to modify them with Lua, your script could also become a terrain generator.
Procedural is a huge time saver to quickly generate terrains before manually tweaking it.

About overlapping problem, this could be fixed using textures bitmaps or masks.
A high res textures only used when working with procedural that can be deleted once terrain is generated.
Each time you paint a palm, a rock or some grass, you paint on the bitmap mask at same position.
When the procedural generator tries to add a new object it will look up as texture mask to check if there is free space or if there is already something.

This could be extended with custom pre made masks that could be used when running procedural script, for example you have some island and you don't want palms or rocks on some places that would be villages, rivers, lakes or something else.

So you need Lua functions to create, read and modify a texture :lol:

I think Skyline team needs to allow terrain access from Lua, like painting textures, grass, vegetation and sculpting terrain.
If more users jump in making plugins this will be needed at some point otherwise no one will create terrain plugins.
User avatar
SpiderMack
Skyline Expert
 
Posts: 437
Joined: 02 Dec 2016, 09:15
Skill: Concept artist
Skill: 3D Modeller
Skill: Level Designer
Skill: Scripter

Re: Procedural Island

Postby SolarPortal » 02 Mar 2018, 15:27

Terrain vertex manipulation and creating / editing textures is already planned in for lua access.
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3100
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Next

Return to Showcase

Who is online

Users browsing this forum: No registered users and 1 guest