                              const float3& Lpos, const float3& V,
                              const float3& Ka, const float3& Kd, const float3& Ks,
                              const float shininess,
+                             float3 const& volsize,
                              const float constAtt = 1.f, const float linearAtt = 0.f, const float quadAtt = 0.f,
                              const float3* normal = NULL)
 {
   // Normal transformed from texture to volume coordinates
-  float3 N = normalize(gradient<t_bpc>(texcoord));
+  float3 N = normalize(gradient<t_bpc>(texcoord, volsize));
   N = tex2vol(N);
 
   // Light direction

{
  return (x + (n - 1)) / n;
}

template<int t_bpc>
__device__ float volume(const float x, const float y, const float z);
template<>
__device__ float volume<1>(const float x, const float y, const float z)
{
  return tex3D(volTexture8, x, y, z);
}
template<>
__device__ float volume<2>(const float x, const float y, const float z)
{
  return tex3D(volTexture16, x, y, z);
}

template<int t_bpc>
__device__ float volume(const float3& pos);
template<>
__device__ float volume<1>(const float3& pos)
{
  return tex3D(volTexture8, pos.x, pos.y, pos.z);
}
template<>
__device__ float volume<2>(const float3& pos)
{
  return tex3D(volTexture16, pos.x, pos.y, pos.z);
}

}

template<int t_bpc>
__device__ float3 gradient(const float3& texcoord, float3 const& volsize)
{
  const float DELTA = 0.01f;

  float3 sample1;
  float3 sample2;

  sample1.x = volume<t_bpc>(texcoord - make_float3(DELTA, 0.0f, 0.0f), volsize);
  sample2.x = volume<t_bpc>(texcoord + make_float3(DELTA, 0.0f, 0.0f), volsize);
  sample1.y = volume<t_bpc>(texcoord - make_float3(0.0f, DELTA, 0.0f), volsize);
  sample2.y = volume<t_bpc>(texcoord + make_float3(0.0f, DELTA, 0.0f), volsize);
  sample1.z = volume<t_bpc>(texcoord - make_float3(0.0f, 0.0f, DELTA), volsize);
  sample2.z = volume<t_bpc>(texcoord + make_float3(0.0f, 0.0f, DELTA), volsize);

  return sample2 - sample1;
}
