package d2isometricimg

import 

var rasterLightDirections = [3]Vec{rasterUnit(Vec{X: -1, Y: 1.8, Z: 1}), rasterUnit(Vec{X: 10, Y: 12, Z: -16}), rasterUnit(Vec{X: 12, Y: 5, Z: 12})}

// A broad key and restrained fill reveal the sidewalls without bleaching
// authored colors. Horizontal faces receive approximately unit illumination.
var rasterLightStrengths = [3]float64{.55, .16, .07}
var rasterLightColors = [3]Vec{{X: 1, Y: 1, Z: 1}, {X: .93, Y: .96, Z: 1}, {X: 1, Y: 1, Z: 1}}

// A silhouette normal is perpendicular to the camera. Mesh arithmetic can
// leave a residual of either sign there; do not let it flip the lit side.
func rasterLightingNormal(,  Vec) Vec {
	 = rasterUnit()
	if rasterDot(, ) < -1e-12 {
		return rasterMul(, -1)
	}
	return 
}

func ( *Raster) ( rasterPaint, ,  Vec) (float64, float64, float64) {
	if .unlit {
		return rasterSRGB(.base.X), rasterSRGB(.base.Y), rasterSRGB(.base.Z)
	}
	 = rasterLightingNormal(, .camera.direction)
	 := rasterClamp(.Y*.5 + .5)
	 := .32 + .12*
	 := Vec{X: , Y: , Z: }
	 := Vec{}
	 := .shadow.occlusion(, )
	for ,  := range rasterLightDirections {
		 := math.Max(0, rasterDot(, )) * rasterLightStrengths[]
		if  == 0 {
			 *= 1 - 
		}
		 = rasterAdd(, rasterMul(rasterLightColors[], ))
		 := rasterUnit(rasterAdd(, .camera.direction))
		 := math.Max(2, 2/(.roughness*.roughness)-2)
		 := math.Pow(math.Max(0, rasterDot(, )), ) *  * (.025 + .metalness*.10)
		 = rasterAdd(, rasterMul(rasterLightColors[], ))
	}
	 := 1 - .metalness*.08
	return rasterSRGB(.base.X*.X* + .X + .emission.X), rasterSRGB(.base.Y*.Y* + .Y + .emission.Y), rasterSRGB(.base.Z*.Z* + .Z + .emission.Z)
}