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.
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?
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.
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