Material Clustering Benchmark
ClusteringTextures.cs
Go to the documentation of this file.
1using UnityEngine;
2
3/// <summary>
4/// Call <see cref="Dispose" /> after using.
5/// </summary>
6public class ClusteringTextures : System.IDisposable
7{
8 public readonly RenderTexture rtInput;
9 public readonly RenderTexture rtArr;
10
11 public int mipLevel
12 {
13 get
14 {
15 {
16 int mipLevel = 0;
17 int targetSize = 1;
18 while (targetSize != this.size)
19 {
20 mipLevel++;
21 targetSize *= 2;
22 }
23 return mipLevel;
24 }
25 }
26 }
27
28 private RenderTexture MakeRtArr(int textureSize)
29 {
30 var rtDesc = new RenderTextureDescriptor(
31 textureSize,
32 textureSize,
33 RenderTextureFormat.ARGBFloat,
34 0
35 )
36 {
37 dimension = UnityEngine.Rendering.TextureDimension.Tex2DArray,
38 volumeDepth = ClusteringTest.maxNumClusters,
39 useMipMap = true,
40 autoGenerateMips = false
41 };
42
43 return new RenderTexture(rtDesc) { enableRandomWrite = true };
44 }
45
47 {
48 this.rtInput = new RenderTexture(size, size, 0, RenderTextureFormat.ARGBFloat)
49 {
50 enableRandomWrite = true
51 };
52
53 this.rtArr = this.MakeRtArr(size);
54 }
55
56 public int size => this.rtInput.width;
57
58 public void Dispose()
59 {
60 this.rtInput.Release();
61 this.rtArr.Release();
62 }
63}
const int maxNumClusters
Must match the shader.
Call Dispose after using.
readonly RenderTexture rtArr
readonly RenderTexture rtInput