Skip to content

Commit a271cfd

Browse files
authored
Merge pull request #284 from Jeka8833/master
Fix incorrect calculations for parameters
2 parents a09f31e + 1384e41 commit a271cfd

2 files changed

Lines changed: 49 additions & 35 deletions

File tree

VRCFaceTracking.Core/Params/Expressions/Legacy/Eye/EyeTrackingParams.cs

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static class EyeTrackingParams
3434
#region Dilation
3535

3636
new EParam("EyesDilation", exp => exp.Eye.Combined().PupilDiameter_MM),
37-
new EParam("EyesPupilDiameter", exp => (exp.Eye.Left.PupilDiameter_MM + exp.Eye.Left.PupilDiameter_MM) / 2.0f),
37+
new EParam("EyesPupilDiameter", exp => (exp.Eye.Left.PupilDiameter_MM + exp.Eye.Right.PupilDiameter_MM) * .5f),
3838

3939
#endregion
4040

@@ -50,8 +50,10 @@ public static class EyeTrackingParams
5050

5151
new EParam("LeftEyeLidExpanded", exp => exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight * 0.2f + exp.Eye.Left.Openness * 0.8f, 0.5f, true),
5252
new EParam("RightEyeLidExpanded", exp => exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight * 0.2f + exp.Eye.Right.Openness * 0.8f, 0.5f, true),
53-
new EParam("EyeLidExpanded", exp => ((exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight + exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight) / 2.0f) * 0.2f +
54-
(exp.Eye.Right.Openness + exp.Eye.Right.Openness) / 2.0f * 0.8f, 0.5f, true),
53+
new EParam("EyeLidExpanded", exp =>
54+
(exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight +
55+
exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight) * .1f +
56+
(exp.Eye.Left.Openness + exp.Eye.Right.Openness) * .4f, 0.5f, true),
5557

5658
#endregion
5759

@@ -64,9 +66,10 @@ public static class EyeTrackingParams
6466
exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight * .2f + exp.Eye.Right.Openness * .8f -
6567
Squeeze(exp, 1), 0.5f, true),
6668
new EParam("EyeLidExpandedSqueeze", exp =>
67-
(((exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight * .2f + exp.Eye.Left.Openness * .8f) +
68-
(exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight * .2f + exp.Eye.Left.Openness * .8f)) / 2.0f) -
69-
Squeeze(exp, 2), 0.5f, true),
69+
((exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight +
70+
exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight) * .2f +
71+
(exp.Eye.Left.Openness + exp.Eye.Right.Openness) * .8f -
72+
Squeeze(exp, 0) - Squeeze(exp, 1)) * .5f, 0.5f, true),
7073

7174
#endregion
7275

@@ -120,14 +123,19 @@ public static class EyeTrackingParams
120123

121124
new BinaryBaseParameter("CombinedEyeLidExpandedSqueeze", exp =>
122125
{
123-
var eyeLid = (((exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight * .2f + exp.Eye.Left.Openness * .8f) +
124-
(exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight * .2f + exp.Eye.Left.Openness * .8f)) / 2.0f) -
125-
Squeeze(exp, 2);
126-
if (eyeLid > .8f)
127-
return (exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight + exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight) / 2.0f;
128-
if (eyeLid >= 0)
129-
return exp.Eye.Combined().Openness;
130-
return Squeeze(exp, 1);
126+
var eyeLid = (
127+
(exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight +
128+
exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight) * .2f +
129+
(exp.Eye.Left.Openness + exp.Eye.Right.Openness) * .8f -
130+
Squeeze(exp, 0) - Squeeze(exp, 1)) * .5f;
131+
132+
return eyeLid switch
133+
{
134+
> .8f => (exp.Shapes[(int)UnifiedExpressions.EyeWideRight].Weight +
135+
exp.Shapes[(int)UnifiedExpressions.EyeWideLeft].Weight) * .5f,
136+
>= 0 => exp.Eye.Combined().Openness,
137+
_ => (Squeeze(exp, 0) + Squeeze(exp, 1)) * .5f
138+
};
131139
}),
132140

133141
#endregion
@@ -211,21 +219,20 @@ public static class EyeTrackingParams
211219
new EParam("NoseSneerLeft", exp => exp.Shapes[(int)UnifiedExpressions.NoseSneerLeft].Weight),
212220
new EParam("NoseSneerRight", exp => exp.Shapes[(int)UnifiedExpressions.NoseSneerRight].Weight),
213221

214-
new EParam("BrowDownLeft", exp => (exp.Shapes[(int)UnifiedExpressions.BrowPinchLeft].Weight + exp.Shapes[(int)UnifiedExpressions.BrowLowererLeft].Weight) / 2.0f),
215-
new EParam("BrowDownRight", exp => (exp.Shapes[(int)UnifiedExpressions.BrowPinchRight].Weight + exp.Shapes[(int)UnifiedExpressions.BrowLowererRight].Weight) / 2.0f)
216-
217222
#endregion
218223
};
219224

220-
// Brain Hurty
221-
private static float NormalizeFloat(float minInput, float maxInput, float minOutput, float maxOutput,
222-
float value) => (maxOutput - minOutput) / (maxInput - minInput) * (value - maxInput) + maxOutput;
225+
// eyeIndex: 0 == Left, 1 == Right
226+
private static float Squeeze(UnifiedTrackingData data, int eyeIndex)
227+
{
228+
if (eyeIndex == 0)
229+
{
230+
return (float)(1.0f - Math.Pow(data.Eye.Left.Openness, .15)) *
231+
data.Shapes[(int)UnifiedExpressions.EyeSquintLeft].Weight;
232+
}
223233

224-
// eyeIndex: 0 == Left, 1 == Right, 2 == avg Both
225-
private static float Squeeze(UnifiedTrackingData data, int eyeIndex) =>
226-
eyeIndex == 0 ? (float)(1.0f - Math.Pow(data.Eye.Left.Openness, .15)) * data.Shapes[(int)UnifiedExpressions.EyeSquintLeft].Weight
227-
: eyeIndex == 1 ? (float)(1.0f - Math.Pow(data.Eye.Right.Openness, .15)) * data.Shapes[(int)UnifiedExpressions.EyeSquintRight].Weight
228-
: eyeIndex == 2 ? (float)(1.0f - Math.Pow(data.Eye.Combined().Openness, .15)) * (data.Shapes[(int)UnifiedExpressions.EyeSquintLeft].Weight + data.Shapes[(int)UnifiedExpressions.EyeSquintRight].Weight) / 2.0f
229-
: 0.0f;
234+
return (float)(1.0f - Math.Pow(data.Eye.Right.Openness, .15)) *
235+
data.Shapes[(int)UnifiedExpressions.EyeSquintRight].Weight;
236+
}
230237
}
231238
}

VRCFaceTracking.Core/Params/Expressions/UnifiedExpressionsParameters.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static (string paramName, Parameter paramLiteral)[] IsEyeParameter(IPara
7878

7979
new EParam("v2/PupilDiameterLeft", exp => exp.Eye.Left.PupilDiameter_MM * 0.1f),
8080
new EParam("v2/PupilDiameterRight", exp => exp.Eye.Right.PupilDiameter_MM * 0.1f),
81-
new EParam("v2/PupilDiameter", exp => (exp.Eye.Left.PupilDiameter_MM * 0.1f + exp.Eye.Left.PupilDiameter_MM * 0.1f) / 2.0f),
81+
new EParam("v2/PupilDiameter", exp => (exp.Eye.Left.PupilDiameter_MM + exp.Eye.Right.PupilDiameter_MM) * .05f),
8282

8383
#endregion
8484

@@ -129,9 +129,11 @@ private static (string paramName, Parameter paramLiteral)[] IsEyeParameter(IPara
129129
#region Eyebrows Compacted
130130

131131
new EParam("v2/BrowUp", exp =>
132-
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowUpRight) + GetSimpleShape(exp, UnifiedSimpleExpressions.BrowUpLeft)),
133-
new EParam("v2/BrowDown", exp =>
134-
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownRight) + GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownLeft)),
132+
(GetSimpleShape(exp, UnifiedSimpleExpressions.BrowUpRight) +
133+
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowUpLeft)) * .5f),
134+
new EParam("v2/BrowDown", exp =>
135+
(GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownRight) +
136+
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownLeft)) * .5f),
135137

136138
new EParam("v2/BrowInnerUp", exp =>
137139
(exp.Shapes[(int)UnifiedExpressions.BrowInnerUpLeft].Weight + exp.Shapes[(int)UnifiedExpressions.BrowInnerUpRight].Weight) / 2.0f),
@@ -148,9 +150,12 @@ private static (string paramName, Parameter paramLiteral)[] IsEyeParameter(IPara
148150
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownLeft)),
149151

150152
new EParam("v2/BrowExpression", exp =>
151-
(Math.Min(1, exp.Shapes[(int)UnifiedExpressions.BrowInnerUpRight].Weight * .5f + exp.Shapes[(int)UnifiedExpressions.BrowOuterUpRight].Weight * .5f) -
152-
Math.Min(1, exp.Shapes[(int)UnifiedExpressions.BrowPinchRight].Weight * .5f + exp.Shapes[(int)UnifiedExpressions.BrowLowererRight].Weight * .5f)) +
153-
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownRight) * .5f - GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownLeft) * .5f),
153+
(Math.Min(1, (exp.Shapes[(int)UnifiedExpressions.BrowInnerUpRight].Weight +
154+
exp.Shapes[(int)UnifiedExpressions.BrowOuterUpRight].Weight) * .5f) -
155+
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownRight) +
156+
Math.Min(1, (exp.Shapes[(int)UnifiedExpressions.BrowInnerUpLeft].Weight +
157+
exp.Shapes[(int)UnifiedExpressions.BrowOuterUpLeft].Weight) * .5f) -
158+
GetSimpleShape(exp, UnifiedSimpleExpressions.BrowDownLeft)) * .5f),
154159

155160
#endregion
156161

@@ -257,8 +262,10 @@ private static (string paramName, Parameter paramLiteral)[] IsEyeParameter(IPara
257262
new EParam("v2/MouthCornerYRight", exp =>
258263
exp.Shapes[(int)UnifiedExpressions.MouthCornerSlantRight].Weight - exp.Shapes[(int)UnifiedExpressions.MouthFrownRight].Weight),
259264
new EParam("v2/MouthCornerY", exp =>
260-
exp.Shapes[(int)UnifiedExpressions.MouthCornerSlantRight].Weight * .5f + exp.Shapes[(int)UnifiedExpressions.MouthCornerSlantLeft].Weight * .5f -
261-
exp.Shapes[(int)UnifiedExpressions.MouthFrownLeft].Weight),
265+
(exp.Shapes[(int)UnifiedExpressions.MouthCornerSlantLeft].Weight -
266+
exp.Shapes[(int)UnifiedExpressions.MouthFrownLeft].Weight +
267+
exp.Shapes[(int)UnifiedExpressions.MouthCornerSlantRight].Weight -
268+
exp.Shapes[(int)UnifiedExpressions.MouthFrownRight].Weight) * .5f),
262269

263270
new EParam("v2/SmileFrownRight", exp =>
264271
GetSimpleShape(exp, UnifiedSimpleExpressions.MouthSmileRight) -

0 commit comments

Comments
 (0)