skia2/resources/sksl/intrinsics/Distance.sksl
John Stiles e1c2beb3be Implement compile-time optimization for distance().
float distance($genType p0, $genType p1);
half distance($genHType p0, $genHType p1);

Change-Id: I492a90c0fe5c950c878752d45c3b2dc6f2cd866e
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/412379
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-05-26 14:11:58 +00:00

18 lines
815 B
Plaintext

uniform half4 pos1, pos2;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const half4 constPos1 = half4(8, -3, 4, 14);
const half4 constPos2 = half4(5, -3, 0, 2);
half4 expected = half4(3, 3, 5, 13);
return (distance(pos1.x, pos2.x) == expected.x &&
distance(pos1.xy, pos2.xy) == expected.y &&
distance(pos1.xyz, pos2.xyz) == expected.z &&
distance(pos1.xyzw, pos2.xyzw) == expected.w &&
distance(constPos1.x, constPos2.x) == expected.x &&
distance(constPos1.xy, constPos2.xy) == expected.y &&
distance(constPos1.xyz, constPos2.xyz) == expected.z &&
distance(constPos1.xyzw, constPos2.xyzw) == expected.w) ? colorGreen : colorRed;
}