- Home /
Artifacts on applying bump map to sphere
I'm making a planet generator. This generator creates multiple textures, including 1 for the terrain and 1 for the bumpmap. These textures are then applied to an icosahedron. However when applying the bump map I get an artifact at the top of the sphere.
When only using the terrain texture I don't get this same artifact and so everything seems normal. I'm not sure what causes this only to happen when using a bump map.
To generate the bump map I use the following compute shader.
[numthreads( 8, 8, 1 )]
void ComputeNormal( uint3 id : SV_DispatchThreadID )
{
float3 pos = GetPosition( id.x, id.y );
float3 xLeftPos = GetPosition( id.x - 1, id.y );
float3 xRightPos = GetPosition( id.x + 1, id.y );
float3 yUpPos = GetPosition( id.x, id.y + 1 );
float3 yDownPos = GetPosition( id.x, id.y - 1 );
fnl_state noise_compute = fnlCreateState();
noise_compute.seed = _TerrainFrequency;
noise_compute.noise_type = FNL_NOISE_OPENSIMPLEX2;
noise_compute.fractal_type = FNL_FRACTAL_FBM;
noise_compute.frequency = _TerrainFrequency;
noise_compute.octaves = _TerrainOctaves;
noise_compute.gain = _TerrainPersistence;
noise_compute.lacunarity = _TerrainLacunarity;
float n = fnlGetNoise3D( noise_compute, pos.x, pos.y, pos.z );
float strength = n < 0.3f ? 0.1f : _NormalStrength;
float xLeft = fnlGetNoise3D( noise_compute, xLeftPos.x, xLeftPos.y, xLeftPos.z ) * strength;
float xRight = fnlGetNoise3D( noise_compute, xRightPos.x, xRightPos.y, xRightPos.z ) * strength;
float yUp = fnlGetNoise3D( noise_compute, yUpPos.x, yUpPos.y, yUpPos.z ) * strength;
float yDown = fnlGetNoise3D( noise_compute, yDownPos.x, yDownPos.y, yDownPos.z ) * strength;
float xDelta = ((xLeft - xRight) + 1) * 0.5f;
float yDelta = ((yUp - yDown) + 1) * 0.5f;
float4 col = float4(xDelta, yDelta, 1.0f, yDelta);
_Noise[indexFromCoord( id.x, id.y )] = col;
}
Which is called by the following method.
void CreateNormal() {
int kernel = PlanetCompute.FindKernel("ComputeNormal");
Color[] colors = ExecuteComputeShader(kernel);
Texture2D texture = new Texture2D(Width, Height, TextureFormat.ARGB32, true);
texture.SetPixels(colors);
texture.wrapMode = TextureWrapMode.Clamp;
texture.Apply();
Material.SetTexture("_BumpMap", texture);
}
The ExecuteComputeShader method simply sets some properties and dispatches the compute shader.
PlanetCompute.Dispatch(kernel, Width / m_ComputeNumThreads, Height / m_ComputeNumThreads, 1);
Your answer
Follow this Question
Related Questions
How to calculate the surface normal Vector3 between two Vector3's on a Sphere. 1 Answer
Shader: blending between normals not working 1 Answer
Displace and show normals in fragment shader 1 Answer
Shader for distorting a texture as if it were on a sphere 3 Answers
Normal from _CameraDepthNormals to screen space angle 1 Answer