 
   // Half way vector.
   const float3 H = normalize(L + V);
-  render<true, true><<<gridSize, blockSize>>>(d_output, width, height, 2.0f / (float)numSlices, volSize * 0.5f, L, H);
+
+  // Clip sphere.
+  const float3 center = make_float3(0.0f, 0.5f, 0.5f);
+  const float radius = 0.7f;
+
+  // Clip plane.
+
+  float* debug;
+  cudaMalloc((void**)&debug, sizeof(float3) * width * height);
+  const float3 pnormal = normalize(make_float3(0.0f, 0.71f, 0.63f));
+  const float pdist = 0.0f;
+  render<
+         true, // Front to back.
+         0, // Mip mode.
+         true, // Local illumination.
+         false, // Clip sphere.
+         true // Clip plane.
+        ><<<gridSize, blockSize>>>(d_output, width, height,
+                                                    2.0f / (float)numSlices,
+                                                    volSize * 0.5f,
+                                                    L, H,
+                                                    center, radius * radius,
+                                                    pnormal, pdist, debug);
   cudaGLUnmapBufferObject(pbo);
+
+  float* output = new float[width * height * 3];
+  cudaMemcpy(output, debug, sizeof(float3) * width * height, cudaMemcpyDeviceToHost);
+  for (int i=0; i<width*height; i+=3)
+  {
+    //std::cerr << output[i] << " " << output[i + 1] << " " << output[i + 2] << std::endl;
+  }
+  delete[] output;
 
   glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
   glBindTexture(GL_TEXTURE_2D, gltex);

  const float4 o = mul(c_invViewMatrix, make_float4(u, v, -1.0f, 1.0f));
  const float4 d = mul(c_invViewMatrix, make_float4(0.0f, 0.0f, 1.0f, 1.0f));

  Ray eyeRay;
  eyeRay.o = perspectiveDivide(o);
  eyeRay.d = perspectiveDivide(d);
  eyeRay.d = normalize(eyeRay.d);

  float tnear, tfar;
  int hit = intersectBox(eyeRay, boxMin, boxMax, &tnear, &tfar);
  if (!hit)
  {
    d_output[y * width + x] = 0;

  return make_float4(tmp.x, tmp.y, tmp.z, classification.w);
}

template<bool frontToBack, int mipMode, bool lighting, bool clipSphere, bool clipPlane>
__global__ void render(uint *d_output, const uint width, const uint height, const float dist,
                       const float3 volSizeHalf, const float3 L, const float3 H,
                       const float3 sphereCenter, const float sphereRadius,
                       const float3 planeNormal, const float planeDist,
                       float* debug)
{
  const int maxSteps = INT_MAX;
  const float tstep = dist;
