Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
FastNoise plugin - Page 2 — Gideros Forum

FastNoise plugin

2

Comments

  • rrraptorrrraptor Member
    edited December 2019
    Added tileable texture geneation :blush:
    I need to test it more, cuz it is a bit hardcoded.

    zz.png
    487 x 325 - 180K

    Likes: hgy29, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • So the left/right and top/bottom match up with each other?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Nice, also very useful. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • It might be good if you can pick a table of colours for it to use when generating the image.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited December 2019
  • rrraptorrrraptor Member
    edited December 2019


    I made lua version of colored texture generation.

    Example from image:
    -- genTex(width, height, filtering, options)
    -- options (table): texture parameters. Includes standart options like wrap, transparentColor etc.
    -- 	noise (table): noise parameters
    -- 		xoff (number): offset noise on x axis (optional)
    -- 		yoff (number): offset noise on y axis (optional)
    -- 		zoff (number): offset noise on z axis (optional)		
    -- 		min (number): noise minimum value (optional, default: -1)
    -- 		max (number): noise maximum value (optional, default: 1)
    -- 		colors (table): noise color map
    -- 			h (number): color height (from 0 to 1)
    -- 			color (table): color in r g b a format (by default - white color)
     
    local colors = {
    	{h = 0.3, color = {52,99,195,255}},
    	{h = 0.4, color = {54,102,198,255}},
    	{h = 0.45, color = {209,208,128,255}},
    	{h = 0.55, color = {88,151,24,255}},
    	{h = 0.6, color = {63,106,20,255}},
    	{h = 0.7, color = {92,68,61,255}},
    	{h = 0.9, color = {75,60,55,255}},
    	{h = 1, color = {255,255,255,255}},
    }
     
    n:setFrequency(0.03)
    n:setFractalOctaves(5)
    n:setFractalLacunarity(2.5)
    n:setInterp(Noise.HERMITE)
    n:setFractalGain(0.6)
    n:setNoiseType(Noise.SIMPLEX_FRACTAL)
     
    local tex = genTex(128, 128, false, {wrap=Texture.REPEAT, noise = {xoff = 0, yoff = 0, zoff = 0, min = -1, max = 1, colors = colors}})
    local btm = Bitmap.new(tex)
    btm:setPosition(10, 10)
    btm:setScale(4)
    stage:addChild(btm)
     
    n:setSeed(6546)
    n:setFrequency(0.02)
    n:setFractalOctaves(3)
     
    tex = genTex(128, 128, false, {wrap=Texture.REPEAT, noise = {xoff = 0, yoff = 0, zoff = 0, min = -1, max = 1, colors = colors}})
    btm = Bitmap.new()
    btm:setPosition(128*4 + 20, 10)
    btm:setScale(4)
    stage:addChild(btm)
    The question is: is this parameters mess is ok?)
    zx.png
    655 x 328 - 44K
    zx.png 44.1K
    +1 -1 (+3 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited December 2019
    imho it needs to mature. In my short experience using gideros I found that some classes I had written some weeks ago needed some slight adjustments to make it more flexible, like in your case, some functions parameters needed to be added/removed.
    So maybe use it for a couple more days (week) and see what you can mature.
    This was my 2 cents.
    Anyway your plugin looks AWESOME :) Can't wait to play with it.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • rrraptorrrraptor Member
    edited December 2019
    MoKaLux said:

    imho it needs to mature. In my short experience using gideros I found that some classes I had written some weeks ago needed some slight adjustments to make it more flexible, like in your case, some functions parameters needed to be added/removed.
    So maybe use it for a couple more days (week) and see what you can mature.
    This was my 2 cents.

    Any suggestions?)
    MoKaLux said:

    Anyway your plugin looks AWESOME :) Can't wait to play with it.

    Well, you already can :)
    I've attached plugin (works only on windows). Put into "Plugins" folder and you are ready to go)


    Usage:
    require "FastNoise"
    noise = Noise.new()
    print(noise:noise4D(1,2,3,4))
    No need to add plugin in project library window!



    Colored texture example:
    application:setBackgroundColor(0x323232)
     
    function byteColor(r,g,b,a)
    	r=r or 255
    	g=g or 255
    	b=b or 255
    	a=a or 255
    	return string.format("%s%s%s%s", string.char(r), string.char(g), string.char(b), string.char(a))
    end
     
    function map(v, minC, maxC, minD, maxD)
    	local newV = (v - minC) / (maxC - minC) * (maxD - minD) + minD
    	return newV 
    end
     
    require "FastNoise"
     
    local n = Noise.new()
     
    function gen(w, h, filtering, options)
    	local data = ""
    	local t = options.noise or {}
    	t.min = t.min or -1
    	t.max = t.max or 1
    	t.xoff = t.xoff or 0
    	t.zoff = t.zoff or 0
    	t.zoff = t.zoff or 0
     
    	local colors = t.colors or {}
    	for y = 1, h do 
    		for x = 1, w do 
    			local c = byteColor()
     
    			local v = n:noise(x + t.xoff, y + t.yoff, t.zoff)
    			local maped = map(v, t.min, t.max, 0, 1)
     
    			for _,tc in ipairs(colors) do 
    				if (maped <= tc.h) then 
    					c = byteColor(unpack(tc.color))
    					break
    				end
    			end
     
    			data = data .. c
    		end
    	end
    	return Texture.new(data,w,h,filtering,options)
    end
    local colors = {
    	{h = 0.3, color = {52,99,195,255}},
    	{h = 0.4, color = {54,102,198,255}},
    	{h = 0.45, color = {209,208,128,255}},
    	{h = 0.55, color = {88,151,24,255}},
    	{h = 0.6, color = {63,106,20,255}},
    	{h = 0.7, color = {92,68,61,255}},
    	{h = 0.9, color = {75,60,55,255}},
    	{h = 1, color = {255,255,255,255}},
    }
     
    n:setFrequency(0.03)
    n:setFractalOctaves(5)
    n:setFractalLacunarity(2.5)
    n:setInterp(Noise.HERMITE)
    n:setFractalType(Noise.FBM)
    n:setFractalGain(0.6)
    n:setNoiseType(Noise.SIMPLEX_FRACTAL)
     
    local btm = Bitmap.new(gen(128, 128, false, {wrap=Texture.REPEAT, noise = {xoff = 0, yoff = 0, zoff = 0, min = -1, max = 1, colors = colors}}))
    btm:setPosition(10, 10)
    btm:setScale(4)
    stage:addChild(btm)
     
    --n:setSeed(6546)
    n:setFrequency(0.02)
    n:setFractalOctaves(3)
     
    btm = Bitmap.new(gen(128, 128, false, {wrap=Texture.REPEAT, noise = {xoff = 0, yoff = 0, zoff = 0, min = -1, max = 1, colors = colors}}))
    btm:setPosition(128*4 + 20, 10)
    btm:setScale(4)
    stage:addChild(btm)

    zip
    zip
    binding.zip
    99K

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited December 2019
    rrraptor said:

    Any suggestions?)

    Sorry @rrraptor more experienced people may give you valuable suggestions. I need to use your plugin for quite a bit, then I could provide some feedback? Thank you for sharing <3 .
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • @rrraptor sorry to bother. I wanted to refer back to this thread for when I need to do the same (a gideros plugin) but now the first post with all your initial questions is gone and I won't know how to start. That's too bad :'(
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • @rrraptor very nice man! Pity 1d noise isn't working :(

    Just a question... if exporting directly to APK, will the right stuff be included?

    sorry, haven;t tested as I've just been finishing my API Reference reader.
  • rrraptorrrraptor Member
    edited December 2019
    antix said:

    @rrraptor very nice man! Pity 1d noise isn't working :(

    Well, you can use Noise:noise(x) or Noise:noise2D(x, 0), should work :)
    Better to use "noise2D(x, y)" because it uses actaul 2D functions, where "noise([x, y, z])" uses 3D functions but all parameters are optional and by default = 0.
    antix said:

    Just a question... if exporting directly to APK, will the right stuff be included?

    No, its not comiled for android. I'll try to compile someday ))) @hgy29 said, he will do it, so you just need to wait ;)
    antix said:

    sorry, haven;t tested as I've just been finishing my API Reference reader.

    Np, I did by myself.
    MoKaLux said:

    @rrraptor sorry to bother. I wanted to refer back to this thread for when I need to do the same (a gideros plugin) but now the first post with all your initial questions is gone and I won't know how to start. That's too bad :'(

    I'll try to write step by step guide.
    Actualy, there is one already: http://forum.giderosmobile.com/discussion/1025/step-by-step-how-to-write-a-c-plugin-and-deploy-it-to-the-desktop-windows-player
    This method still works (I mean VisualStudio), but its impossible to create a plugin that will have class defenition, becouse of that. All you need is QT. You can get it there -> https://wiki.giderosmobile.com/index.php/Compiling_Gideros_Source#1.1_Install_QT
    Thats it. Now go to "All pugins" and try to open QT project (*.pro files), and compile it (CTRL+B)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    @rraptor, is your plugin finished ? If so send me the sources and I’ll add it to gideros

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • rrraptorrrraptor Member
    edited December 2019
    hgy29 said:

    @rraptor, is your plugin finished ? If so send me the sources and I’ll add it to gideros

    No :disappointed:
    The texture generation should be improved (texture options parameters (wrap, transperentColor etc...) and coloring). I think it will take some time, but if you want to release new version, texture generation can be removed for now. Also, 1D noise should be removed.
    Sources are there -> https://github.com/MultiPain/Gideros_FastNoise_binding
  • Leave them in, just say it's in beta.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited December 2019
    @hgy29 can you help a bit?)

    I stacked with parsing lua table in C++ :D
    I want to have this format for colors:
    colors = {	
    	{h = 0.30, color = {52,99,194,255}},
    	{h = 0.40, color = {55,102,199,255}},
    	...
    }
    I have no problem of parsing "h" value, but have no idea how to parse "color" xDD
    // im parsing a table which contains another table, called "colors"
    lua_getfield(L, 6, "colors"); // stack: table, ...
    lua_pushnil(L); // stack: nil, table
    while (lua_next(L, -2)) // get key, value pair
    {
            lua_getfield(L, -1, "h"); // stack: key, value, table, ...
            double hh = luaL_checknumber(L, -1); // get height value
            lua_pop(L, 2); // stack: key, table, ... 
    }
    lua_pop(L, 1);
    I can change format to:
    {
    	{h = 0.30, r = 52, g = 99, b = 194, a = 255},
    	{h = 0.40, r = 55, g = 102, b = 199, a = 255},
    }
    But it is very long :)
  • hgy29hgy29 Maintainer
    use lua_rawgeti to fetch each color channel in your array in stead of going through lua_next
  • rrraptorrrraptor Member
    edited December 2019
    @hgy29 hmm, like that? :D
            lua_getfield(L, 6, "colors");
            for (int i = 0; i < 8; i++)
            {
                lua_rawgeti(L, -1, i+1);
                lua_getfield(L, -1, "h");
                double hh = luaL_checknumber(L, -1);
                lua_pop(L, 1);
     
                lua_getfield(L, -1, "color");
                for (int j = 0; j < 3; j++)
                {
                    lua_rawgeti(L, -1, j+1);
                    double colorValue = luaL_checknumber(L, -1);
                    lua_pop(L, 1);
                }
     
                lua_pop(L, 2);
            }
    Now I have hardcoded array length :D
    lua_objlen will help I guess...
  • hgy29hgy29 Maintainer
    yes, that should be fine.
    BTW I had to make some changes to your code to make it compile for all platforms: adding Math.h include at the top, checking if M_PI is defined, and changing some 'delete' into 'delete[]'
  • hgy29 said:

    yes, that should be fine.
    BTW I had to make some changes to your code to make it compile for all platforms: adding Math.h include at the top, checking if M_PI is defined, and changing some 'delete' into 'delete[]'

    Ok, I'll change my code then ;)
  • It would be good if any randomness could be optionally fixed - I mean so you could specify an optional seed. This would make it good for generating data based on a level number (so everyone sees the same data).

    Also, a z direction might be useful (with optional wrapping) so you can create animated data that loops. (by playing through each z frame of data).
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited December 2019
    @SinisterSoft it is already done ;) But the problem is that, we have to create new texture every time. We cant generate data and feed it to texture.
  • SinisterSoftSinisterSoft Maintainer
    edited December 2019
    Ahh, sorry I didn't see anything to set the seed here:
    -- genTex(width, height, filtering, options)
    -- options (table): texture parameters. Includes standart options like wrap, transparentColor etc.
    -- noise (table): noise parameters
    -- xoff (number): offset noise on x axis (optional)
    -- yoff (number): offset noise on y axis (optional)
    -- zoff (number): offset noise on z axis (optional)
    -- min (number): noise minimum value (optional, default: -1)
    -- max (number): noise maximum value (optional, default: 1)
    -- colors (table): noise color map
    -- h (number): color height (from 0 to 1)
    -- color (table): color in r g b a format (by default - white color)
    How do you set the seed? Also, don't forget the os random function work differently between each os. What are you using?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Yes, you would have to generate multiple textures.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • @SinisterSoft I didnot develop this library :)
    I took it and created a bridge between lua and c++
    To set seed from lua you simply do
    require "FastNoise"
    local n = Noise.new()
    n:setSeed(32231)
    n:noise(x,y,z)
    Set seed looks like this:
    void FastNoise::SetSeed(int seed)
    {
    	m_seed = seed;
     
    	std::mt19937_64 gen(seed);
     
    	for (int i = 0; i < 256; i++)
    		m_perm[i] = i;
     
    	for (int j = 0; j < 256; j++)
    	{
            int rng = (int)(gen() % (256 - j));
    		int k = rng + j;
    		int l = m_perm[j];
    		m_perm[j] = m_perm[j + 256] = m_perm[k];
    		m_perm[k] = l;
    		m_perm12[j] = m_perm12[j + 256] = m_perm[j] % 12;
    	}
    }
    My guess is that he shifts permutation table.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • rrraptorrrraptor Member
    edited December 2019
    Finaly, Its done.
    EDIT: actualy...I forgot to fix tileable texture generation xD
    EDIT2: probably fixed now

    Added texture options support to "generateTexture" and "generateTileableTexture"
    and color table support.


    @hgy29 I updated files ;)

    https://github.com/MultiPain/Gideros_FastNoise_binding/


    image.png
    566 x 450 - 48K
    +1 -1 (+2 / -0 )Share on Facebook
  • Top left: Simplex fractal
    Bottom left: perlin fractal
    Right: tileable texture

    noise2.gif
    540 x 470 - 2M
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.