Oh, and sorry for being such a subborn ass, the scaling coefficient did help when I finally set it to 0.02... Quite an extreme value, that the D3DX method seems to use by default, but hey, it works!
Here's the complete shader, should anyone need it:
[source lang-hlsl]float HeightMapSize; texture HeightMap;sampler HeightMapSampler = sampler_state{ Texture = <HeightMap>; MinFilter = Linear; MagFilter = Linear; AddressU = Clamp; AddressV = Clamp;};//application to vertex structurestruct a2v{ float4 position : POSITION0; float2 tex0 : TEXCOORD0;}; //vertex to pixel shader structurestruct v2p{ float4 position : POSITION0; float2 tex0 : TEXCOORD0;}; //pixel shader to screenstruct p2f{ float4 color : COLOR0;};float packNormal(float normal){ return (normal + 1) / 2;}void ps( in v2p IN, out p2f OUT){ float dU = 1 / HeightMapSize; float s0 = tex2D(HeightMapSampler, IN.tex0).r; float s1 = tex2D(HeightMapSampler, float2(IN.tex0.x - dU, IN.tex0.y)).r; float s2 = tex2D(HeightMapSampler, float2(IN.tex0.x, IN.tex0.y - dU)).r; float s3 = tex2D(HeightMapSampler, float2(IN.tex0.x + dU, IN.tex0.y)).r; float s4 = tex2D(HeightMapSampler, float2(IN.tex0.x, IN.tex0.y + dU)).r; /* // conventional way float3 v1 = normalize(float3( -dU, 0, s1 - s0)); float3 v2 = normalize(float3( 0, -dU, s2 - s0)); float3 v3 = normalize(float3( dU, 0, s3 - s0)); float3 v4 = normalize(float3( 0, dU, s4 - s0)); float3 n1 = normalize(cross( v1, v2 )); float3 n2 = normalize(cross( v2, v3 )); float3 n3 = normalize(cross( v3, v4 )); float3 n4 = normalize(cross( v4, v1 )); float3 n = normalize(n1 + n2 + n3) / 25;*/ float coef = 0.02; float2 n = normalize( float2( (s1 - s3), (s2 - s4))) * coef; OUT.color = float4( packNormal(n.x), packNormal(n.y), packNormal(1), 0); }; void vs( in a2v IN, out v2p OUT ){ OUT.position = IN.position; OUT.tex0 = IN.tex0; } //--------------------------------------------------------------------------------------// Techniques//--------------------------------------------------------------------------------------technique NormalMapComputation{ pass P0 { AlphaBlendEnable = false; SrcBlend = SRCALPHA; DestBlend = INVSRCALPHA; VertexShader = compile vs_1_1 vs(); PixelShader = compile ps_2_0 ps(); }}