Perlin noise - procedural shader

Dose the Cg noise() is a Pro only feature ??..

… since, I need something could generate the texture on the fly (with Unity indie), so that, I just made it by myself again :stuck_out_tongue:

http://mrl.nyu.edu/~perlin/noise/
(Original Paper)



source code and info of above test shader will be updated later…

Nice job.

Just a small heads up. The noise function is very rarely implemented by the gfx-cards manufacturers, it usually just returns 0. Therefore you often have to implement something like your implementation.

Understand !

… or maybe it is very heavy too. I found that, its need many arithmetic instructions to do the job :stuck_out_tongue:

However, the real time performance of the GPU port is very very good when compare with the javascript version that running on the CPU :slight_smile:

Have Fun !

(the small texture used as permutation table )

219309–7971–$perlin_2002_cg_v001_292.shader (4.35 KB)
219309–7972–$perlin_2002_110.js (2.96 KB)
219309--7973--$noise16x16_956.png

Nice work. You’re really tearing through this stuff!

Yeah ! After I tear the code apart :p, that give me more space to insert the second channel of perlin noise too :slight_smile:


(an animal skin look alike texture without using color map)


(is it good for making shirt too ??)

[ Sample Video ]

220114–7990–$perlin_2002_cg_v002_395.shader (3.91 KB)

awesome work!

and Im also curious to know, on how old of a GPU can a shader like this run? Can this run on like a geforce 3, or does it need like a geforce fx?

good question, but the answer in no. I think at least GeForce 6, since the perlin noise shader require to run on “Shader Model 3.0” mode.

press release on 2004…

well, already 5 years old - time to buy a new computer with a better graphic card :stuck_out_tongue:

PS.

Unity also provide some very useful statistics on their website on “shader models” too.
http://unity3d.com/webplayer/hwstats/pages/web-2009Q3-shader.html

I tried this in Unity 3.5.3 Indie. I had to make a few changes to match the 3.5 requirements. When I put the material on a large plane there were glitches in a grid pattern. I wonder whether the errors could be near integers, e.g. due to rounding errors with fmod, frac or lerp. If I replaced the noise function with a continuous function in (x, y) such as sin or cos the glitches went away. Any idea what it could be?

can someone please post an updated version for 3.5 ? :slight_smile:

Here you go.

It was a pretty easy fix-- just had to delete some of the comments from the original shader. Stuff like “/------------” at the end of a line seemed to confuse the new shader parser.

To get rid of the weird grid pattern, you need to make some changes to noise16x16_956.png’s import settings. Click the texture, switch Texture Type to Advanced, then uncheck Generate Mip Maps, and you should be good to go. :smile:

1150570–43737–$perlin_2002_cg_v001_292.shader (4.42 KB)

hey man! nice shader. I really like the leopard application

Oh right! it’s perlin in JS read from textcoord in CG… i thought it was native cg. nice though! native perlin would be good for seamless textures.

here are 2 different versions of GPU Perlin written in CG:

http://scrawkblog.com/2013/03/05/perlin-noise-pulgin-for-unity/comment-page-1/#comment-712
http://www.sci.utah.edu/~leenak/IndStudy_reportfall/Perlin%20Noise%20on%20GPU.html

Also this is 3d Perlin calculated on GPU entirely, for unity, it’s for DirectX 11, but that’s the mesh creation, perhaps the Perlin code part of the shader is okay on shader model 3: from the source code on this page
http://johannes.gotlen.se/blog/

Did you see this version? of perlin noise for GPU? it’s 3d and it is the fastest 3d noise code available apparently.

#ifndef __noise_hlsl_
#define __noise_hlsl_

// hash based 3d value noise
// function taken from [url]https://www.shadertoy.com/view/XslGRr[/url]
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// ported from GLSL to HLSL

float hash( float n )
{
    return frac(sin(n)*43758.5453);
}

float noise( float3 x )
{
    // The noise function returns a value in the range -1.0f -> 1.0f

    float3 p = floor(x);
    float3 f = frac(x);

    f       = f*f*(3.0-2.0*f);
    float n = p.x + p.y*57.0 + 113.0*p.z;

    return lerp(lerp(lerp( hash(n+0.0), hash(n+1.0),f.x),
                   lerp( hash(n+57.0), hash(n+58.0),f.x),f.y),
               lerp(lerp( hash(n+113.0), hash(n+114.0),f.x),
                   lerp( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
}

#endif
4 Likes