// add the editable flex controllers
flexcontroller eyelid right_lid_raiser left_lid_raiser 
flexcontroller eyelid right_lid_tightener left_lid_tightener
flexcontroller eyelid right_lid_droop left_lid_droop
flexcontroller eyelid right_lid_closer left_lid_closer
flexcontroller eyelid half_closed
flexcontroller eyelid blink
flexcontroller brow right_inner_raiser left_inner_raiser
flexcontroller brow right_outer_raiser left_outer_raiser 
flexcontroller brow right_lowerer left_lowerer
flexcontroller nose right_cheek_raiser left_cheek_raiser
flexcontroller nose wrinkler dilator
flexcontroller mouth right_upper_raiser left_upper_raiser 
flexcontroller mouth right_corner_puller left_corner_puller
flexcontroller mouth right_corner_depressor left_corner_depressor
flexcontroller mouth chin_raiser
flexcontroller phoneme right_part left_part 
flexcontroller phoneme right_puckerer left_puckerer 
flexcontroller phoneme right_funneler left_funneler 
flexcontroller phoneme right_stretcher left_stretcher
flexcontroller phoneme bite presser tightener jaw_clencher jaw_drop
flexcontroller phoneme right_mouth_drop left_mouth_drop

flexcontroller mouth smile

//flexcontroller mouth right_sneer left_sneer
//flexcontroller mouth wide_open
//flexcontroller eyelid half_closed
flexcontroller mouth lower_lip

// eyelids tend toward 0 as center of vision
// FIXME: add a control to set how close to the COV the lids should match (blink == 0, normal == 1)
%upper_right_raiser = right_lid_raiser * (1 - right_lid_droop * 0.8) * (1 - right_lid_closer) * (1 - blink)
%upper_right_neutral = (1 - right_lid_droop * 0.8) * (1 - right_lid_raiser) * (1 - right_lid_closer) * (1 - blink)
%upper_right_lowerer = right_lid_closer + blink * (1 - right_lid_closer)
%upper_left_raiser = left_lid_raiser * (1 - left_lid_droop * 0.8) * (1 - left_lid_closer) * (1 - blink)
%upper_left_neutral = (1 - left_lid_droop * 0.8) * (1 - left_lid_raiser) * (1 - left_lid_closer) * (1 - blink)
%upper_left_lowerer = left_lid_closer + blink * (1 - left_lid_closer)

%lower_right_raiser = right_lid_closer + blink * 0.5 * (1 - right_lid_closer)
%lower_right_neutral = (1 - right_lid_closer) * (1 - 0.5 * blink) * (1 - right_lid_tightener * 0.5) * (1 - right_cheek_raiser * 0.25)
%lower_right_lowerer = 0
%lower_left_raiser = left_lid_closer  + blink * 0.5 * (1 - left_lid_closer)
%lower_left_neutral = (1 - left_lid_closer) * (1 - 0.5 * blink) * (1 - left_lid_tightener * 0.5) * (1 - left_cheek_raiser * 0.25)
%lower_left_lowerer = 0

%AU1R = right_inner_raiser * (1 - right_outer_raiser) * (1 - right_lowerer)
%AU1L = left_inner_raiser * (1 - left_outer_raiser) * (1 - left_lowerer)
%AU2R = right_outer_raiser * (1 - right_inner_raiser) * (1 - right_lowerer)
%AU2L = left_outer_raiser * (1 - left_inner_raiser) * (1 - left_lowerer)
%AU1AU2R = right_inner_raiser * right_outer_raiser * (1 - right_lowerer)
%AU1AU2L = left_inner_raiser * left_outer_raiser * (1 - left_lowerer)
%AU4R = right_lowerer
%AU4L = left_lowerer

%AU6R = right_cheek_raiser
%AU6L = left_cheek_raiser
%AU9R = wrinkler
%AU9L = wrinkler
%AU38 = dilator

localvar right_open left_open
localvar right_lip_suppressor left_lip_suppressor

%right_open = smile + right_part * (1 - smile) + right_puckerer + right_funneler + right_upper_raiser * 0.5 + lower_lip * 0.5
%left_open = smile + left_part * (1 - smile) + left_puckerer + left_funneler + left_upper_raiser * 0.5 + lower_lip * 0.5
%right_lip_suppressor = (1 / %right_open) * (1 - presser) * (1 - bite)
%left_lip_suppressor = (1 / %left_open) * (1 - presser) * (1 - bite)

%AU10R = right_upper_raiser * (right_upper_raiser * 0.5 * %right_lip_suppressor)
%AU10L = left_upper_raiser * (left_upper_raiser * 0.5 * %left_lip_suppressor)
%AU25R = right_part * (right_part * %right_lip_suppressor) * (1 - smile)
%AU25L = left_part * (left_part * %left_lip_suppressor) * (1 - smile)
%AU12AU25 = smile * (smile * 0.5 * (%right_lip_suppressor + %left_lip_suppressor))
%AU18R = right_puckerer * (right_puckerer * %right_lip_suppressor)
%AU18L = left_puckerer * (left_puckerer * %left_lip_suppressor)
%AU22R = right_funneler * (right_funneler * %right_lip_suppressor)
%AU22L = left_funneler * (left_funneler * %left_lip_suppressor)

%AU17R = chin_raiser * (1 - jaw_drop * 0.5) * (1 - bite) * (1 - 0.6 * (%AU25R + %AU18R + %AU22R)) * (1 - smile)
%AU17L = chin_raiser * (1 - jaw_drop * 0.5) * (1 - bite) * (1 - 0.6 * (%AU25L + %AU18L + %AU22L)) * (1 - smile)

localvar right_depressor_suppressor left_depressor_suppressor

%right_depressor_suppressor = (1 / (%AU18R * 0.8 + %AU22R * 0.8 + %AU17R + bite + right_corner_puller + right_stretcher + right_corner_depressor)) * (1 - jaw_drop * 0.5)  * (1 - smile * 0.5)
%left_depressor_suppressor = (1 / (%AU18L * 0.8 + %AU22L * 0.8 + %AU17L + bite + left_corner_puller + left_stretcher + left_corner_depressor)) * (1 - jaw_drop * 0.5) * (1 - smile * 0.5)

%AU15R = right_corner_depressor * (right_corner_depressor * %right_depressor_suppressor)
%AU15L = left_corner_depressor * (left_corner_depressor * %left_depressor_suppressor)

localvar right_corner_suppressor left_corner_suppressor

%right_corner_suppressor = (1 / (%AU18R * 0.8 + %AU22R * 0.8 + %AU17R + bite + right_corner_puller + right_stretcher + right_corner_depressor)) * (1 - jaw_drop * 0.5)  * (1 - smile)
%left_corner_suppressor = (1 / (%AU18L * 0.8 + %AU22L * 0.8 + %AU17L + bite + left_corner_puller + left_stretcher + left_corner_depressor)) * (1 - jaw_drop * 0.5) * (1 - smile)

%AU12R = right_corner_puller * (right_corner_puller * %right_corner_suppressor)
%AU12L = left_corner_puller * (left_corner_puller * %left_corner_suppressor)
%AU20R = right_stretcher * (right_stretcher * %right_corner_suppressor)
%AU20L = left_stretcher * (left_stretcher * %left_corner_suppressor)


%AU32 = bite
%AU24 = presser + (1 - presser) * tightener
%AU31 = jaw_clencher * (jaw_clencher / (jaw_clencher + jaw_drop))

localvar right_drop_suppressor left_drop_suppressor
localvar right_drop left_drop

%right_drop_suppressor = (1 / (0.5 * %right_open + right_mouth_drop)) * (1 - presser) * (1 - bite)
%left_drop_suppressor = (1 / (0.5 * %left_open + left_mouth_drop )) * (1 - presser) * (1 - bite)

%right_drop = right_mouth_drop * (right_mouth_drop * %right_drop_suppressor)
%left_drop = left_mouth_drop * (left_mouth_drop * %left_drop_suppressor)

%AU26R = jaw_drop * (1 - %right_drop ) * (jaw_drop / (jaw_clencher + jaw_drop))
%AU26L = jaw_drop * (1 - %left_drop ) * (jaw_drop / (jaw_clencher + jaw_drop))
%AU27R = jaw_drop * %right_drop * (jaw_drop / (jaw_clencher + jaw_drop))
%AU27L = jaw_drop * %left_drop * (jaw_drop / (jaw_clencher + jaw_drop))

//add to mouth if reverted: + %AU10SR * 0.35 + %AU10SL * 0.35
//%AU10SR = right_sneer
//%AU10SL = left_sneer

//%AU27ZR = wide_open
//%AU27ZL = wide_open

//%AU42 = half_closed

%AU16 = lower_lip * (lower_lip * 0.25 * (%right_lip_suppressor + %left_lip_suppressor)) * (1 - 0.5 * (%AU27R + %AU27L))


// set the mouth shader illumination to roughly how far the mouth is open
%mouth = %AU27R * 0.5 + %AU27L * 0.5 + %AU22R * 0.35 + %AU22L * 0.35 + %AU18R * 0.25 + %AU18L * 0.25 + %AU25R * 0.35 + %AU25L * 0.35 + %AU32 * 0.5 + %AU12AU25 + %AU16 * 0.40




