proper normal mapping

Here’s a snippet for anyone who likes to have per pixel bumpmapping implemented into panda. It reacts (kind of) lifelike to viewposition and lightposition. Try it. Feedback is always appreciated

//Cg profile arbvp1 arbfp1

void vshader(   float4 vtx_position : POSITION,
                 float3 vtx_normal : NORMAL,
                 float3 vtx_binormal0    :    BINORMAL,
                 float3 vtx_tangent0     :   TANGENT,
                 float4 vtx_color : COLOR,
                 float3 vtx_texcoord0 : TEXCOORD0,
                 out float4 l_position : POSITION,
                 out float4 l_brite : TEXCOORD1,
                 out float3 l_texcoord0,
                 out float4 l_color : COLOR,
                 out float4 l_pointpos,
                 out float3 l_normal,
                 out float3 l_lightvec,
                 out float3 l_viewvec,
                 uniform float4x4 mat_modelproj,
                 uniform float4 mspos_light,
                 uniform float4 mspos_view)
l_position = mul(mat_modelproj, vtx_position);

float3 lightVector = ((float3)mspos_light - (float3)vtx_position);
l_lightvec.x = dot(vtx_tangent0, lightVector);
l_lightvec.y = -dot(vtx_binormal0, lightVector);
l_lightvec.z = dot(vtx_normal, lightVector);

float3 viewVector = ((float3)mspos_view - (float3)vtx_position);
l_viewvec.x = dot(vtx_tangent0, viewVector);
l_viewvec.y = -dot(vtx_binormal0, viewVector);
l_viewvec.z = dot(vtx_normal, viewVector);

l_texcoord0 = vtx_texcoord0;
l_color = vtx_color;
l_pointpos = vtx_position;

void fshader(   float l_brite : TEXCOORD1,
                 float4 l_color : COLOR,
                 uniform float4 mspos_light,
                 uniform float4 mspos_view,
                 uniform float4 k_gloss,
                 sampler2D tex_0,
                 sampler2D tex_0_n,
                 float2 l_texcoord0,
                 float4 l_pointpos,
                 float3 l_lightvec,
                 float3 l_viewvec,
                 out float4 o_color : COLOR)

float distance = length(mspos_light - l_pointpos) + length(mspos_view - l_pointpos);
float attenuate = saturate(30.0 / (15.0 + distance));

float4 normalMap = tex2D(tex_0_n, l_texcoord0) * 2.0 - float4(1.0, 
1.0, 1.0, 1.0);
float4 tex = tex2D(tex_0, l_texcoord0);

float3 halfAngle = normalize(normalize(l_lightvec) + normalize(l_viewvec) / 2.0);
l_brite = pow(dot((float3)normalMap, halfAngle), k_gloss.x);
float lightProd = saturate(dot(halfAngle, (float3)normalMap)+0.3);

o_color= (float4(0.2, 0.20, 0.20, 1.0) + l_brite) * lightProd * tex * attenuate;
o_color.a = tex.a;


SWEET, thank you! The normal map shader that comes with the demo, for some reason does not work on my computer, but when I used yours, and viola! I have a wonderfully normal mapped room! THANKS, I owe you big time, that was one of my biggest disappointments with panda, and you fixed it! :mrgreen: :mrgreen: :mrgreen:

hey rayman,

thanks for your reply! always good to hear someone appreciates an effort you make :slight_smile: I’m still looking for someone to give me hints on a multiple lightpass bumpmap shader, but i guess that’s something I have to find out for myself still.

anyways, good to hear your appreciate it and if you need any help please feel free to contact me.


You have to enable BBCode if you want

blocks to do anything.

Fixed it… - In case I made any errors, please lemme know…

Regards, Bigfoot29

Go to This guy is a freak, and he has a LOT of working awesome GL codes.

Ya, Humus is my hero!