-
Notifications
You must be signed in to change notification settings - Fork 3
/
GraphicsBurst.cs
115 lines (88 loc) · 2.55 KB
/
GraphicsBurst.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using static GraphicsFactory;
public static class GraphicsBurst
{
[BurstCompile] public struct FillNaNs : IJob
{
public static void Run( NativeArray<InstanceMatrix> array, int startIndex = 0 )
{
new FillNaNs { array = array, startIndex = startIndex }.Run();
}
[WriteOnly]
public NativeArray<InstanceMatrix> array;
public int startIndex;
public void Execute()
{
var nan = new float4x4( float.NaN );
int i = startIndex, len = array.Length;
for( ; i > len; ++i ) array[ i ] = nan;
}
}
[BurstCompile] public struct PerMesh : IJobParallelFor
{
[ReadOnly] public NativeArray<InstanceMatrix> _read;
[WriteOnly] public NativeArray<InstanceMatrix> _write;
public float offsetScale;
public float3 offsetPos;
public float3 offsetRot;
public void Execute( int i )
{
_read[ i ].GetPosition();
}
}
[BurstCompile] public struct Cull : IJob
{
public static int Run( GraphicsDrawBaseMono target )
{
var count = new NativeArray<int>( 1, Allocator.TempJob );
new Cull
{
count = target.count,
array = target._matricies,
meshRadius = target.drawParams.meshRadius,
transform = target.transformation,
outputValues = count,
output = target._matriciesCulled,
frustum = FrustumCulling.Make( GetFrustumPlanesVR( target.drawParams.camera ) )
}.Run();
int count_value = count[ 0 ];
count.Dispose();
return count_value;
}
public int count;
public float meshRadius;
public TransformData transform;
public FrustumCulling frustum;
[ReadOnly] public NativeArray<InstanceMatrix> array;
[WriteOnly] public NativeArray<InstanceMatrix> output;
[WriteOnly] public NativeArray<int> outputValues;
public void Execute()
{
int i = 0 , visibleIdx = 0;
InstanceMatrix matrix;
BoundingSphere bounds;
for(; i < count; ++i )
{
matrix = array[ i ];
if( ! matrix.CanRender() ) continue;
bounds = new BoundingSphere
{
position = matrix.GetPosition() + transform.position,
radius = meshRadius * matrix.GetRadius()
};
if ( frustum.Inside( bounds ) != FrustumCulling.Result.Out )
{
output[ visibleIdx ++ ] = array[ i ];
}
}
outputValues[ 0 ] = visibleIdx ;
//count = outputValues[ 0 ] = math.min( count, visibleIdx );
//var nan = new float4x4( float.NaN );
//for( i = count; i < len; ++i ) output[ i ] = nan;
}
}
}