• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1montify  Members

Posted 20 December 2012 - 02:23 PM

Hello

I use Libnoise.XNA for creating the height of my Terrain.

I have implemented a Quadtree with LOD.

So with Libnoise i Choose the right Position of the Heightmap with:

  float[] v = new float[Planet.size * Planet.size];
for (int z = 0; z < Planet.size; z++)
for (int x = 0; x < Planet.size; x++)
{
test = new Vector3(MathHelper.Lerp(-1, 1, (float)x / (Planet.size - 1)), 0, MathHelper.Lerp(-1, 1, (float)z / (Planet.size - 1)));
test = Vector3.Transform(test, world);
test = Vector3.Normalize(test);
v[x + z * Planet.size] = (float)perlin.GetValue(test.X, 0, test.Z); ;


perlin.GetValue.

So i Implemented the GPU Perlin

float4x4 World;
float3 coord;
{
float4 Position : POSITION0;
float2 texCoord : TEXCOORD0;
};
{
float4 Position : POSITION0;
float2 texCoord : TEXCOORD0;
float4 wPosition: TEXCOORD1;
};
{
output.Position = input.Position;
output.wPosition = input.Position;
output.texCoord = input.texCoord;
return output;
}
texture permTexture2d;
sampler permSampler2d = sampler_state
{
texture = <permTexture2d>;
MAGFILTER = POINT;
MINFILTER = POINT;
MIPFILTER = NONE;
};
{
MAGFILTER = POINT;
MINFILTER = POINT;
MIPFILTER = NONE;
};
{
return t * t * t * (t * (t * 6 - 15) + 10); // new curve
}
float4 perm2d(float2 p)
{
return tex2D(permSampler2d, p);
}
{
return dot(sample, p);
}
{
}
float inoise(float3 p)
{
//new Vector3(MathHelper.Lerp(-1, 1, (float)x / (Planet.size - 1)), 0, MathHelper.Lerp(-1, 1, (float)z / (Planet.size - 1)));
float3 xx;
xx.x = lerp( -1 ,1, coord.x);
xx.y = 0;
xx.z =lerp( -1 ,1, coord.z);

xx = normalize(xx);
float3 P = fmod(floor(p), 256);
p -= floor(p);
P = P /256;
const float one = -11.0 /256;
float4 AA = perm2d(P.xy) + P.z;
return lerp(lerp( lerp( gradPerm(AA.x, p ),
gradPerm(AA.z, p + float3(-1, 0, 0) ), f.x),
lerp( gradPerm(AA.y, p + float3(0, -1, 0) ),
gradPerm(AA.w, p + float3(-1, -1, 0) ), f.x), f.y),

lerp( lerp( gradPerm(AA.x+one, p + float3(0, 0, -1) ),
gradPerm(AA.z+one, p + float3(-1, 0, -1) ), f.x),
lerp( gradPerm(AA.y+one, p + float3(0, -1, -1) ),
gradPerm(AA.w+one, p + float3(-1, -1, -1) ), f.x), f.y), f.z);
}
float turbulence(float3 p, int octaves, float lacunarity = 2.0, float gain = 0.5)
{
float sum = 0;
float freq = 1.0, amp = 1.0;
for(int i=0; i < octaves; i++) {
sum += abs(inoise(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float ridge(float h, float offset)
{
h = abs(h);
h = offset - h;
h = h * h;
return h;
}
float ridgedmf(float3 p, int octaves, float lacunarity, float gain, float offset = 1.0)
{
float sum = 0;
float freq = 1.3f;
float amp = 0.5;
float prev = 1.0;
for(int i=0; i < octaves; i++)
{
float n = ridge(inoise(p*freq), offset);
sum += n*amp*prev;
prev = n;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float fBm(float3 p, int octaves, float lacunarity, float gain = 0.7)
{
float freq = 1.3f,
amp  = 0.5f;
float sum  = 0.6f;
for(int i=0; i < octaves; i++) {
sum += inoise(p*freq)*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float Interpolate(float x, float y, float a)
{
float val = (1 - cos(a * 3.1415926535f)) * .5;
return  x * (1 - val) + y * val;
}
{
float3 p = input.wPosition;
float inz = inoise(p)*0.7+0.7;

inz += ridgedmf(p,8,2.0,0.5);
inz *= turbulence(p,8,2.0,0.5);
inz *= fBm(p,8,2.0,0.8);
inz *= Interpolate(0.7,0.7,0.5);

return float4(inz,inz,inz,1);
}
technique PerlinNoise
{
pass Pass1
{
}
}


But how can i get the Coords similar like perlin.GetValue?

Anyone can help me? :/

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.