per pixel bumpmapping / phong illumination

Hi all,

I’ve been trying to implement a bumpmap shader with phong lighting, it’s running quite well, considering… but the light seems to “go through” walls. If anyone can help? The shader uses a light input, a view input and a gloss input (respectively: mspos_light, mspos_view, k_gloss).

Shader code is below.

//Cg profile arbvp1 arbfp1

void vshader(   float4 vtx_position : POSITION,
                float3 vtx_normal : NORMAL,
                float3 vtx_tangent0,
                float3 vtx_binormal0,
                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,
                uniform float4x4 mat_modelproj)
l_position = mul(mat_modelproj, vtx_position);

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

void fshader(   float4 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,
                float3 l_normal,
                float4 l_pointpos,
                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 lightVector = normalize((float3)mspos_light - (float3)l_pointpos);
float3 viewVector = normalize((float3)mspos_view - (float3)l_pointpos);
float3 halfAngle = normalize(lightVector + viewVector);
l_brite = pow(dot((float3)normalMap, halfAngle), k_gloss.x)+0.3;

o_color=l_brite * tex * attenuate;



Glancing at your code very quickly, you seem to have stuff right. As for going through walls… thats what normal computer graphics lights do. There is no occulsion going on. That would require shadows.

Well, I figured it out… I needed to convert the camera and the light to tangent space and use egg2x -> x2egg -tbnall to precompute tangents and binormals. After that I normalize the view and the light vector in the pixel shader and that way it turns out way shiny.