   Realtime Normal Map Generation
  Whilst working on my deferred renderer, I've noticed the quality of my normals is well.... terrible.The problem is most noticable where there is a sudden change of elevation in the terrain, which is pretty common considering I'm using noise to generate it.The bottom left section below shows what I mean:My normal map looks like this:My normal map is generated using the following HLSL:float topLeft = abs(tex2D (Elevation, uv + OneOverTextureSize * float2(-1.0f, -1.0f)).r);float left = abs(tex2D (Elevation, uv + OneOverTextureSize * float2(-1.0f,  0.0f)).r);float bottomLeft = abs(tex2D (Elevation, uv + OneOverTextureSize * float2(-1.0f,  1.0f)).r);float top = abs(tex2D (Elevation, uv + OneOverTextureSize * float2( 0.0f, -1.0f)).r);float bottom = abs(tex2D (Elevation, uv + OneOverTextureSize * float2( 0.0f,  1.0f)).r);float topRight = abs(tex2D (Elevation, uv + OneOverTextureSize * float2( 1.0f, -1.0f)).r);float right = abs(tex2D (Elevation, uv + OneOverTextureSize * float2( 1.0f,  0.0f)).r);float bottomRight = abs(tex2D (Elevation, uv + OneOverTextureSize * float2( 1.0f,  1.0f)).r);float dX = 3.0f * topLeft + 10.0f * left + 3.0f * bottomLeft - 3.0f * topRight - 10.0f * right - 3.0f * bottomRight;float dY = 3.0f * topLeft + 10.0f * top + 3.0f * topRight - 3.0f * bottomLeft - 10.0f * bottom - 3.0f * bottomRight;float3 normalf = normalize(float3(dX, dY, 1.0f));normalf.xy = normalf.xy * 0.5f + 0.5f;I'm using linear sampling to get the normals from the normal map and display them on the screen.How can I improve my normal map generation to make it look less pixelated and remove this problem? Is it even possible?[Edited by - adt7 on June 10, 2009 1:43:47 PM]
  I've managed to reduce the effect by reducing the strength of my normals, but the "criss-cross" effect is still there at sharp changes in height.   ;  I've doubled the resolution of my normal maps, and I've seen an improvement, but I'm still unconvinced by the normals at the height transitions.Can no one offer any insight?   ;float s1 = tex2D(Elevation, float2(p_uv.x - OneOverTextureSize, p_uv.y)).r;float s2 = tex2D(Elevation, float2(p_uv.x, p_uv.y - OneOverTextureSize)).r;float s3 = tex2D(Elevation, float2(p_uv.x + OneOverTextureSize, p_uv.y)).r;float s4 = tex2D(Elevation, float2(p_uv.x, p_uv.y + OneOverTextureSize)).r;  // change this value to soften / harden the normal mapfloat coeff = 2.0f;float3 normalf = float3( (s1 - s3), (s2 - s4), coeff );normalf = normalize( normalf );normalf.xy = normalf.xy * 0.5f + 0.5f;