How do i need to modify the gradient vector in my fbm loop?
The Problem is that i can't get the Normals calculated right with this code... They are pointing just a bit off the right direction, this causes strange lighting.
Here the calculation of the Normal Vector:
float3 grad;
float noise = getNoiseValue(TriPos, grad);
float3 nTriPos = normalize(TriPos);
grad = grad / (noise);
float3 h = grad - dot(grad, nTriPos) * nTriPos;
float3 n = nTriPos - (h);
Edit: I changed the Normal calculation a tiny bit. And removed the frequency. And it looks ok now. Is there a way to insert the frequency?
float getNoiseValue(float3 TriPos, out float3 gradient)
{
float strength = 0.45f;
float octaves = 15;
float Persistence = 0.53333f;
float BaseRoughness = 0.71f;
float Roughness = 1.81f;
float MinNoiseValue = 1.4f;
float noiseValue = 0.f;
float frequency = BaseRoughness;
float amplitude = 1.f;
TriPos = TriPos / 40000.f;
for (int i = 0; i < octaves; i++)
{
float v = (sdnoise3(TriPos, gradient) + 1.f) * 0.5f;
gradient += gradient * amplitude;
noiseValue += v * amplitude;
frequency *= Roughness;
amplitude *= Persistence;
}
noiseValue = max(0.f, noiseValue - MinNoiseValue);
return noiseValue;
}
Update:
So everything works now as it should, BUT when i add the frequency to my loop i get strange lighting again...
for (int i = 0; i < octaves; i++)
{
float v = (sdnoise3(normalize(TriPos) * frequency, gradient) + 1.f) * 0.5f;
gradient = gradient + (gradient * amplitude * frequency);
noiseValue = noiseValue + (v * amplitude);
frequency *= Roughness;
amplitude *= Persistence;
}
Anybody can tell me what is wrong here?
I found the problem. Some logic error...
float3 grad;
for (int i = 0; i < octaves; i++)
{
float v = (sdnoise3(TriPos * frequency, gradient) + 1.f) * 0.5f;
grad += (gradient * amplitude);
noiseValue += (v * amplitude);
frequency = frequency * Roughness;
amplitude = amplitude * Persistence;
}
I used the gradient variable as out parameter of sdnoise3 function so it got overriden every iteration.