Material Clustering Benchmark
DispatcherKnecht.cs
Go to the documentation of this file.
1using UnityEngine;
2
4{
6 {
7 private const int randomInitEveryNiterations = 5;
8 private int frameCounter = 0;
9
11 ComputeShader computeShader,
14 )
15 : base(
16 new DispatcherKM(
17 computeShader,
18 1,
20 useFullResTexRef: false,
22 )
23 )
24 {
25 this.frameCounter = 0;
26 }
27
28 public override string name => "Knecht";
29
30 public override void RunClustering(ClusteringTextures clusteringTextures)
31 {
32 this.frameCounter++;
33
34 using (RunUntilConvergesResult result = this.RunUntilConverges(clusteringTextures))
35 {
36 if (result.converged == false || this.frameCounter == randomInitEveryNiterations)
37 {
38 this.DoExploration(clusteringTextures, result);
39 }
40
41 if (this.frameCounter == randomInitEveryNiterations)
42 {
43 this.frameCounter = 0;
44 }
45 }
46 }
47
48 private void DoExploration(
49 ClusteringTextures textures,
50 RunUntilConvergesResult currentResult
51 )
52 {
53 // alters (currentResult.clusterCenters) - same array is filled with new data and re-used
55
56 using (RunUntilConvergesResult newResult = this.RunUntilConverges(textures))
57 {
58 if (currentResult.clusterCenters.variance < newResult.clusterCenters.variance)
59 {
61 currentResult.clusterCenters.centers
62 );
63 }
64 }
65 }
66 }
67}
Call Allocate before using and Dispose after using.
void SetClusterCenters(Vector4[] clusterCentersBufferData)
Reads the cluster centers data from the array and loads it into the ComputeBuffer.
DispatcherKnecht(ComputeShader computeShader, bool doRandomizeEmptyClusters, ClusteringRTsAndBuffers clusteringRTsAndBuffers)
override void RunClustering(ClusteringTextures clusteringTextures)
RunUntilConvergesResult RunUntilConverges(ClusteringTextures clusteringTextures)
Call Dispose after using.