normal maps and custom lighting models in Unity 3.0

Hi all,

I have written a custom lighting model that performs a lookup into an HDRI using the surface normal. It also computes standard spec, diffuse and fresnel lighting.

This all works fine … until … in the surface shader (the void surf(…) function) I read a normal map using the unpacknormal function. Once the custom lighting model is called the diffuse, specular and fresnel still work, but the HDRI lookup breaks. I find this really odd - for all that it does with the normals is read the normal from the SurfaceOutput structure and make a lookup based upon that, nothing is transformed in any way.

Anyone have any ideas?

many thanks - Gradus

New information about my problem …

so … since the HDRI lighting model is independent of light and view position it seemed silly to have it in the custom lighting model - so I moved it to the void surf(…) function - the surface shader. It didnt work there … so …

I decided to color the object to which the shader was applied with the normal - namely

// begin code

o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));

half3 col;
col[0]=(o.Normal[0]+1)/2;
col[1]=(o.Normal[1]+1)/2;
col[2]=(o.Normal[2]+1)/2;

o.Albedo=col;

// end code

the color is the same everywhere - so … why is this? shouldnt o.Normal applied as the albedo have a color that depends upon which way the surface is oriented in object space? - if I remove the line that applies the bump map - it works and the normal looks correct - ie it varies over the surface, if I keep that line in place the normal is uniform over the whole surface

again, many thanks - Gradus

problem solved - sorry - it was a trivial mistake - UnpackNormal() needs to have its result combined with o.Normal to make sense - sorry for bandwidth wasting

Gardus