# Phong Plus NormalMapping in DX11

has anyone a nice shader for phongLighting+normalmapping

here is a very nice example…with source code and binary

with up to 5 point lights + directional light + and many surface material setting…i think it would be cool to have it in DX11

i tried it … but just had that binormal and tangent issue! if anyone is down - lets go!!!

mio

Here is a function you can use without binormals and tangents. Has some artifacting but at least you can use it with generative meshes.

``````//////////////////////////////////////////////////////////////
// poorly adapted from Chris­t­ian Schüler http://www.thetenthplanet.de
//////////////////////////////////////////////////////////////

float3 NormalMapper( float3 N, float3 V, float3 Nmap, float3 texcoord )
{
// assume N, the interpolated vertex normal and
// V, the view vector (vertex to eye)

Nmap = Nmap * 2 -1;
//Nmap.y = -Nmap.y;

//TBN///////////
// get edge vectors of the pixel triangle
float3 dp1 = ddx( -V );
float3 dp2 = ddy( -V );
float2 duv1 = ddx( texcoord );
float2 duv2 = ddy( texcoord );

// solve the linear system
float3 dp2perp = cross( dp2, N );
float3 dp1perp = cross( N, dp1 );
float3 T = dp2perp * duv1.x + dp1perp * duv2.x;
float3 B = dp2perp * duv1.y + dp1perp * duv2.y;

// construct a scale-invariant frame
float invmax = rsqrt( max( dot(T,T), dot(B,B) ) );
float3x3 TBN = float3x3( T * invmax, B * invmax, N );
//TBN///////////

float3 n = mul (Nmap,  TBN);

return normalize( n);

}
//////////////////////////////////////////////////////////////``````