xref: /aosp_15_r20/external/skia/resources/sksl/intrinsics/Normalize.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 inputVal;
2uniform half4 colorGreen, colorRed;
3
4half4 main(float2 coords) {
5    // Ensure that normalizing zero doesn't trigger a UBSAN divide-by-zero report.
6    float normalizeZero = normalize(0);
7    // Ensure that it is harmless to normalize a gigantic value.
8    float normalizeHuge = normalize(1E34);
9
10    const half4 constVec = half4(20, 0, 0, 0);
11    half4 expectedVec = half4(1, 0, 0, 0);
12
13    return (normalize(inputVal.x)    == expectedVec.x       &&
14            normalize(inputVal.xy)   == expectedVec.xy      &&
15            normalize(inputVal.xyz)  == expectedVec.xyz     &&
16            normalize(inputVal.xyzw) == expectedVec.xyzw    &&
17            normalize(constVec.x)    == expectedVec.x       &&
18            normalize(constVec.yx)   == expectedVec.yx      &&
19            normalize(constVec.zxy)  == expectedVec.zxy     &&
20            normalize(constVec.xyzw) == expectedVec.xyzw) ? colorGreen : colorRed;
21}
22