skia2/tests/sksl/intrinsics/FaceForward.glsl
John Stiles 7cfa1ce9db Implement compile-time optimization for faceforward().
This implementation leans heavily into DSL. I also reworked the
`normalize` intrinsic to use more DSL to shrink the implementation.

$genType faceforward($genType N, $genType I, $genType Nref);
$genHType faceforward($genHType N, $genHType I, $genHType Nref);

Change-Id: I73ab11d3fe449d2f2c0ae0d745fc39824fc64771
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/412637
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-05-26 16:28:48 +00:00

13 lines
638 B
GLSL

out vec4 sk_FragColor;
uniform vec4 N;
uniform vec4 I;
uniform vec4 NRef;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 expectedPos = vec4(1.0, 2.0, 3.0, 4.0);
vec4 expectedNeg = vec4(-1.0, -2.0, -3.0, -4.0);
return ((((((faceforward(N.x, I.x, NRef.x) == expectedNeg.x && faceforward(N.xy, I.xy, NRef.xy) == expectedNeg.xy) && faceforward(N.xyz, I.xyz, NRef.xyz) == expectedPos.xyz) && faceforward(N, I, NRef) == expectedPos) && -1.0 == expectedNeg.x) && vec2(-1.0, -2.0) == expectedNeg.xy) && vec3(1.0, 2.0, 3.0) == expectedPos.xyz) && vec4(1.0, 2.0, 3.0, 4.0) == expectedPos ? colorGreen : colorRed;
}