Search Unity

Libnoise-like shader?

Discussion in 'Shaders' started by Kald, May 22, 2013.

  1. Kald

    Kald

    Joined:
    Apr 20, 2013
    Posts:
    16
    Hi there. I'm quite new to coding shaders, as I didn't really need it up until now... I have used libnoise before to generate textures on fly in my C# script - but the problem is, it is not efficient enough (as generating and swapping textures in real-time is quite cpu consuming). I was wondering if there is any way I could do it on GPU?
    What I need, in short, is a way to render random height-map-like (looking like a terrain, but not modifing mesh) texture on sphere. Much like in my demo - www.chainreaction.p.ht/spacepirates/spacepirates2.html
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,879
    in nvidia shader library, you can find cool and fast noise functions.

    EDIT: obviously its not as sophisticated as libnoise but still good enough for simple noise operations.
     
  3. Kald

    Kald

    Joined:
    Apr 20, 2013
    Posts:
    16
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,879
    Well, i wont do that as this is not suitable for 4 year olds and it would take alot of my time.
    But here is a easier to understand and easier to convert source code for clouds rendering. What matters is, the base noise functions.
    http://www.sci.utah.edu/~leenak/IndStudy_reportfall/CloudsCode.txt

    EDIT: One hint, the main code section is the part where you generate a permutation texture, and a gradient texture.
     
    Last edited: May 22, 2013
  5. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hi Kald. I have a working Unity project of the GPU gems improved perlin noise. Computes 2D, 3D, or 4D perlin noise all on the GPU.

    Improved perlin noise.
     
  6. Kald

    Kald

    Joined:
    Apr 20, 2013
    Posts:
    16
    I've seen that, and that's pretty impressive work - especially that you are sharing this with public for free! Sadly, when it comes to shaders I'm as dumb as a mule, and even though I've managed to get it working and used it on three different meshes, with Random.Range on frequency/lacunarity/gain, they've all looked exactly the same. I was wondering if it's possible to make every mesh using same material to look different (generate new noise)? But, once again, since I know nothing about shaders, I've put that aside for the moment and tried to rewrite SetPixels/Apply method to pure GL... With as little results as with shaders ;)
     
  7. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Yes you can make each mesh unique

    Its not the frequency, lacunarity or gain that should be a random value. Its the the seed value that needs to be changed for a different noise.

    In my script you create a perlin noise object like this.

    Code (csharp):
    1. ImprovedPerlinNoise perlin = new ImrovedPerlinNoisse(0);
    Its the number passed to the constructor thats the seed value ( the 0).

    I will update the project to make that a bit easier. I should have put the seed value as a public value you can change in the editor. Over looked that.
     
  8. Kald

    Kald

    Joined:
    Apr 20, 2013
    Posts:
    16
    Yeah, that worked great, thanks ;) I've also reworked loadpermtable and loadgradient functions to use SetPixels instead SetPixel (as I've heard it's a bit faster). One thing I can't work out, though, is how to make coloured noise, much like terrain gradient in libnoise.
     
  9. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,879
    cpu or gpu noise, they both still have an impact on the frame rate. Have you considered generating your textures before or while loading your scenes?
    My libnoise port has a visual front end as well as full libnoise port with tutorials as well. you might consider checking it out.