 
               if ditherPercentage > 1 - (paletteColor?.dither or 0)
                 if Math.abs(pixel.x % 2) + Math.abs(pixel.y % 2) is 1
-                  @_destinationColor = secondBestColor
+                  destinationColor = secondBestColor
 
               ### Smooth shading routine
               #closest = THREE.Color.fromObject bestColor


class LOI.Assets.Engine.Sprite
  constructor: (@options) ->
    @palette = new ComputedField =>
      return unless spriteData = @options.spriteData()
      spriteData.customPalette or LOI.Assets.Palette.documents.findOne(spriteData.palette?._id)

    @ready = new ComputedField =>
      return unless spriteData = @options.spriteData()
      return unless spriteData.layers?.length and spriteData.bounds
      return unless @palette() or @options.visualizeNormals?()

      true

    # Create temporary objects and constants.
    @_normal = new THREE.Vector3
    @_backward = new THREE.Vector3 0, 0, 1
    @_destinationColor = new THREE.Color
    @_lightColor = new THREE.Color
    @_averageNormal = new THREE.Vector3


            else
              lightness = 0.5

            @_color.setHSL hue, saturation, lightness
            destinationColor = @_color

          else
            destinationColor = r: 0, g: 0, b: 0

        else if renderOptions.renderNormalData
          # Rendering of raw normal data for use in shaders.
          if pixel.normal
            destinationColor =
              r: pixel.normal.x * 0.5 + 0.5
              g: pixel.normal.y * 0.5 + 0.5
              b: pixel.normal.z * 0.5 + 0.5

            destinationColor.r = -pixel.normal.x * 0.5 + 0.5 if flippedHorizontal

          else
            destinationColor = r: 0, g: 0, b: 0

        else if renderOptions.renderPaletteData
          # Rendering of ramp + shade + dither data for use in shaders.
