| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using Unity.Burst; |
| | 6 | | using Unity.Collections; |
| | 7 | | using Unity.Jobs; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | namespace GDX.Jobs.ParallelFor |
| | 11 | | { |
| | 12 | | [BurstCompile] |
| | 13 | | public struct ColorCompareJob : IJobParallelFor |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// The left-hand side <see cref="Unity.Collections.NativeArray{T}" /> typed as <see cref="byte" />. |
| | 17 | | /// </summary> |
| | 18 | | [ReadOnly] public NativeArray<Color> A; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// The right-hand side <see cref="Unity.Collections.NativeArray{T}" /> typed as <see cref="byte" />. |
| | 22 | | /// </summary> |
| | 23 | | [ReadOnly] public NativeArray<Color> B; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// The percent difference between the two values. |
| | 27 | | /// </summary> |
| | 28 | | [WriteOnly] public NativeArray<float> Percentage; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Executable work for the provided index. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="index">The index of the Parallel for loop at which to perform work.</param> |
| | 34 | | public void Execute(int index) |
| 0 | 35 | | { |
| 0 | 36 | | if (A[index] == B[index]) |
| 0 | 37 | | { |
| 0 | 38 | | Percentage[index] = 1f; |
| 0 | 39 | | } |
| | 40 | | else |
| 0 | 41 | | { |
| 0 | 42 | | float rDiff = A[index].r - B[index].r; |
| 0 | 43 | | float gDiff = A[index].g - B[index].g; |
| 0 | 44 | | float bDiff = A[index].b - B[index].b; |
| 0 | 45 | | float aDiff = A[index].a - B[index].a; |
| | 46 | |
|
| 0 | 47 | | Percentage[index] = 1f - (rDiff + gDiff + bDiff + aDiff) / 4f; |
| 0 | 48 | | } |
| 0 | 49 | | } |
| | 50 | | } |
| | 51 | | } |