Skip to content

Commit d02ed86

Browse files
authored
Merge pull request #8053 from Unity-Technologies/internal/master
Internal/master
2 parents 7edae7b + 5e10a43 commit d02ed86

File tree

210 files changed

+9599
-3416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+9599
-3416
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using UnityEngine;
5+
using UnityEngine.Analytics;
6+
7+
namespace UnityEditor.Rendering.Analytics
8+
{
9+
// schema = com.unity3d.data.schemas.editor.analytics.uRenderGraphViewerLifetimeAnalytic_v1
10+
// taxonomy = editor.analytics.uRenderGraphViewerLifetimeAnalytic.v1
11+
internal class RenderGraphViewerLifetimeAnalytic
12+
{
13+
static bool IsInternalAssembly(Type type)
14+
{
15+
var assemblyName = type.Assembly.FullName;
16+
if (assemblyName.StartsWith("UnityEditor.", StringComparison.InvariantCultureIgnoreCase) ||
17+
assemblyName.StartsWith("Unity.", StringComparison.InvariantCultureIgnoreCase))
18+
return true;
19+
return false;
20+
}
21+
22+
static List<string> GatherCurrentlyOpenWindowNames()
23+
{
24+
var openWindows = Resources.FindObjectsOfTypeAll(typeof(EditorWindow));
25+
var openWindowNames = new List<string>(openWindows.Length);
26+
foreach (var w in openWindows)
27+
{
28+
if (IsInternalAssembly(w.GetType()) && w is not RenderGraphViewer)
29+
{
30+
openWindowNames.Add((w as EditorWindow).titleContent.text);
31+
}
32+
}
33+
return openWindowNames;
34+
}
35+
36+
static string[] UnionWithoutLinq(List<string> a, List<string> b)
37+
{
38+
HashSet<string> aAndB = new HashSet<string>(a);
39+
aAndB.UnionWith(b);
40+
String[] aAndBArray = new String[aAndB.Count];
41+
aAndB.CopyTo(aAndBArray);
42+
return aAndBArray;
43+
}
44+
45+
[AnalyticInfo(eventName: "uRenderGraphViewerLifetimeAnalytic", vendorKey: "unity.srp", maxEventsPerHour: 100, maxNumberOfElements: 1000)]
46+
internal class Analytic : IAnalytic
47+
{
48+
public Analytic(WindowOpenedMetadata windowOpenedMetadata)
49+
{
50+
List<string> currentlyOpenEditorWindows = GatherCurrentlyOpenWindowNames();
51+
var elapsed = DateTime.Now - windowOpenedMetadata.openedTime;
52+
using (UnityEngine.Pool.GenericPool<Data>.Get(out var data))
53+
{
54+
data.seconds_opened = elapsed.Seconds;
55+
data.other_open_windows = UnionWithoutLinq(currentlyOpenEditorWindows, windowOpenedMetadata.openEditorWindows);
56+
57+
m_Data = data;
58+
}
59+
}
60+
61+
[DebuggerDisplay("{seconds_opened} - {other_open_windows.Length}")]
62+
[Serializable]
63+
class Data : IAnalytic.IData
64+
{
65+
// Naming convention for analytics data
66+
public int seconds_opened;
67+
public string[] other_open_windows;
68+
}
69+
70+
public bool TryGatherData(out IAnalytic.IData data, out Exception error)
71+
{
72+
data = m_Data;
73+
error = null;
74+
return true;
75+
}
76+
77+
Data m_Data;
78+
}
79+
80+
internal struct WindowOpenedMetadata
81+
{
82+
public List<string> openEditorWindows;
83+
public DateTime openedTime;
84+
}
85+
86+
static WindowOpenedMetadata? s_WindowOpenedMetadata = null;
87+
88+
public static void WindowOpened()
89+
{
90+
s_WindowOpenedMetadata = new WindowOpenedMetadata
91+
{
92+
openEditorWindows = GatherCurrentlyOpenWindowNames(),
93+
openedTime = DateTime.Now
94+
};
95+
}
96+
97+
public static void WindowClosed()
98+
{
99+
if (s_WindowOpenedMetadata.HasValue)
100+
{
101+
Analytic analytic = new Analytic(s_WindowOpenedMetadata.Value);
102+
EditorAnalytics.SendAnalytic(analytic);
103+
s_WindowOpenedMetadata = null;
104+
}
105+
}
106+
}
107+
}

Packages/com.unity.render-pipelines.core/Editor/Analytics/RenderGraphViewerLifetimeAnalytic.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.core/Editor/Lighting/IESEngine.cs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using Unity.Collections;
4+
using Unity.Collections.LowLevel.Unsafe;
45
using UnityEditor;
56
#if UNITY_2020_2_OR_NEWER
67
using UnityEditor.AssetImporters;
@@ -118,7 +119,7 @@ public string GetPhotometricType()
118119
int width = 2 * textureSize;
119120
int height = 2 * textureSize;
120121

121-
NativeArray<Color32> colorBuffer;
122+
NativeArray<Color> colorBuffer;
122123

123124
switch (m_iesReader.PhotometricType)
124125
{
@@ -148,7 +149,7 @@ public string GetPhotometricType()
148149
/// <returns>A Generated 2D texture doing the projection of the IES using the Gnomonic projection of the bottom half hemisphere with the given 'cone angle'</returns>
149150
public (string, Texture) Generate2DCookie(TextureImporterCompression compression, float coneAngle, int textureSize, bool applyLightAttenuation)
150151
{
151-
NativeArray<Color32> colorBuffer;
152+
NativeArray<Color> colorBuffer;
152153

153154
switch (m_iesReader.PhotometricType)
154155
{
@@ -171,7 +172,7 @@ public string GetPhotometricType()
171172
int width = 2 * textureSize;
172173
int height = textureSize;
173174

174-
NativeArray<Color32> colorBuffer;
175+
NativeArray<Color> colorBuffer;
175176

176177
switch (m_iesReader.PhotometricType)
177178
{
@@ -189,7 +190,7 @@ public string GetPhotometricType()
189190
return GenerateTexture(TextureImporterType.Default, TextureImporterShape.Texture2D, compression, width, height, colorBuffer);
190191
}
191192

192-
(string, Texture) GenerateTexture(TextureImporterType type, TextureImporterShape shape, TextureImporterCompression compression, int width, int height, NativeArray<Color32> colorBuffer)
193+
(string, Texture) GenerateTexture(TextureImporterType type, TextureImporterShape shape, TextureImporterCompression compression, int width, int height, NativeArray<Color> colorBuffer)
193194
{
194195
// Default values set by the TextureGenerationSettings constructor can be found in this file on GitHub:
195196
// https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/AssetPipeline/TextureGenerator.bindings.cs
@@ -218,6 +219,7 @@ public string GetPhotometricType()
218219
platformSettings.maxTextureSize = 2048;
219220
platformSettings.resizeAlgorithm = TextureResizeAlgorithm.Bilinear;
220221
platformSettings.textureCompression = compression;
222+
platformSettings.format = TextureImporterFormat.RGB9E5;
221223

222224
TextureGenerationOutput output = TextureGenerator.GenerateTexture(settings, colorBuffer);
223225

@@ -229,21 +231,22 @@ public string GetPhotometricType()
229231
return (output.importInspectorWarnings, output.output);
230232
}
231233

232-
private static byte PackIESValue(float value)
234+
Color ComputePixelColor(float horizontalAnglePosition, float verticalAnglePosition, float attenuation = 1.0f)
233235
{
234-
return (byte)Math.Clamp(value * 255, 0, 255);
236+
float value = m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * attenuation);
237+
return new Color(value, value, value, value);
235238
}
236239

237-
NativeArray<Color32> BuildTypeACylindricalTexture(int width, int height)
240+
NativeArray<Color> BuildTypeACylindricalTexture(int width, int height)
238241
{
239242
float stepU = 360f / (width - 1);
240243
float stepV = 180f / (height - 1);
241244

242-
var textureBuffer = new NativeArray<Color32>(width * height, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
245+
var textureBuffer = new NativeArray<Color>(width * height, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
243246

244247
for (int y = 0; y < height; y++)
245248
{
246-
var slice = new NativeSlice<Color32>(textureBuffer, y * width, width);
249+
var slice = new NativeSlice<Color>(textureBuffer, y * width, width);
247250

248251
float latitude = y * stepV - 90f; // in range [-90..+90] degrees
249252

@@ -255,24 +258,23 @@ NativeArray<Color32> BuildTypeACylindricalTexture(int width, int height)
255258

256259
float horizontalAnglePosition = m_iesReader.ComputeTypeAorBHorizontalAnglePosition(longitude);
257260

258-
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas);
259-
slice[x] = new Color32(value, value, value, value);
261+
slice[x] = ComputePixelColor(horizontalAnglePosition, verticalAnglePosition);
260262
}
261263
}
262264

263265
return textureBuffer;
264266
}
265267

266-
NativeArray<Color32> BuildTypeBCylindricalTexture(int width, int height)
268+
NativeArray<Color> BuildTypeBCylindricalTexture(int width, int height)
267269
{
268270
float stepU = k_TwoPi / (width - 1);
269271
float stepV = Mathf.PI / (height - 1);
270272

271-
var textureBuffer = new NativeArray<Color32>(width * height, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
273+
var textureBuffer = new NativeArray<Color>(width * height, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
272274

273275
for (int y = 0; y < height; y++)
274276
{
275-
var slice = new NativeSlice<Color32>(textureBuffer, y * width, width);
277+
var slice = new NativeSlice<Color>(textureBuffer, y * width, width);
276278

277279
float v = y * stepV - k_HalfPi; // in range [-90..+90] degrees
278280

@@ -293,24 +295,23 @@ NativeArray<Color32> BuildTypeBCylindricalTexture(int width, int height)
293295
float horizontalAnglePosition = m_iesReader.ComputeTypeAorBHorizontalAnglePosition(longitude);
294296
float verticalAnglePosition = m_iesReader.ComputeVerticalAnglePosition(latitude);
295297

296-
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas);
297-
slice[x] = new Color32(value, value, value, value);
298+
slice[x] = ComputePixelColor(horizontalAnglePosition, verticalAnglePosition);
298299
}
299300
}
300301

301302
return textureBuffer;
302303
}
303304

304-
NativeArray<Color32> BuildTypeCCylindricalTexture(int width, int height)
305+
NativeArray<Color> BuildTypeCCylindricalTexture(int width, int height)
305306
{
306307
float stepU = k_TwoPi / (width - 1);
307308
float stepV = Mathf.PI / (height - 1);
308309

309-
var textureBuffer = new NativeArray<Color32>(width * height, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
310+
var textureBuffer = new NativeArray<Color>(width * height, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
310311

311312
for (int y = 0; y < height; y++)
312313
{
313-
var slice = new NativeSlice<Color32>(textureBuffer, y * width, width);
314+
var slice = new NativeSlice<Color>(textureBuffer, y * width, width);
314315

315316
float v = y * stepV - k_HalfPi; // in range [-90..+90] degrees
316317

@@ -331,25 +332,24 @@ NativeArray<Color32> BuildTypeCCylindricalTexture(int width, int height)
331332
float horizontalAnglePosition = m_iesReader.ComputeTypeCHorizontalAnglePosition(longitude);
332333
float verticalAnglePosition = m_iesReader.ComputeVerticalAnglePosition(latitude);
333334

334-
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas);
335-
slice[x] = new Color32(value, value, value, value);
335+
slice[x] = ComputePixelColor(horizontalAnglePosition, verticalAnglePosition);
336336
}
337337
}
338338

339339
return textureBuffer;
340340
}
341341

342-
NativeArray<Color32> BuildTypeAGnomonicTexture(float coneAngle, int size, bool applyLightAttenuation)
342+
NativeArray<Color> BuildTypeAGnomonicTexture(float coneAngle, int size, bool applyLightAttenuation)
343343
{
344344
float limitUV = Mathf.Tan(0.5f * coneAngle * Mathf.Deg2Rad);
345345
float stepUV = (2 * limitUV) / (size - 3);
346346

347-
var textureBuffer = new NativeArray<Color32>(size * size, Allocator.Temp, NativeArrayOptions.ClearMemory);
347+
var textureBuffer = new NativeArray<Color>(size * size, Allocator.Temp, NativeArrayOptions.ClearMemory);
348348

349349
// Leave a one-pixel black border around the texture to avoid cookie spilling.
350350
for (int y = 1; y < size - 1; y++)
351351
{
352-
var slice = new NativeSlice<Color32>(textureBuffer, y * size, size);
352+
var slice = new NativeSlice<Color>(textureBuffer, y * size, size);
353353

354354
float v = (y - 1) * stepUV - limitUV;
355355

@@ -368,25 +368,24 @@ NativeArray<Color32> BuildTypeAGnomonicTexture(float coneAngle, int size, bool a
368368
// Factor in the light attenuation further from the texture center.
369369
float lightAttenuation = applyLightAttenuation ? rayLengthSquared : 1f;
370370

371-
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation));
372-
slice[x] = new Color32(value, value, value, value);
371+
slice[x] = ComputePixelColor(horizontalAnglePosition, verticalAnglePosition, lightAttenuation);
373372
}
374373
}
375374

376375
return textureBuffer;
377376
}
378377

379-
NativeArray<Color32> BuildTypeBGnomonicTexture(float coneAngle, int size, bool applyLightAttenuation)
378+
NativeArray<Color> BuildTypeBGnomonicTexture(float coneAngle, int size, bool applyLightAttenuation)
380379
{
381380
float limitUV = Mathf.Tan(0.5f * coneAngle * Mathf.Deg2Rad);
382381
float stepUV = (2 * limitUV) / (size - 3);
383382

384-
var textureBuffer = new NativeArray<Color32>(size * size, Allocator.Temp, NativeArrayOptions.ClearMemory);
383+
var textureBuffer = new NativeArray<Color>(size * size, Allocator.Temp, NativeArrayOptions.ClearMemory);
385384

386385
// Leave a one-pixel black border around the texture to avoid cookie spilling.
387386
for (int y = 1; y < size - 1; y++)
388387
{
389-
var slice = new NativeSlice<Color32>(textureBuffer, y * size, size);
388+
var slice = new NativeSlice<Color>(textureBuffer, y * size, size);
390389

391390
float v = (y - 1) * stepUV - limitUV;
392391

@@ -406,25 +405,24 @@ NativeArray<Color32> BuildTypeBGnomonicTexture(float coneAngle, int size, bool a
406405
// Factor in the light attenuation further from the texture center.
407406
float lightAttenuation = applyLightAttenuation ? rayLengthSquared : 1f;
408407

409-
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation));
410-
slice[x] = new Color32(value, value, value, value);
408+
slice[x] = ComputePixelColor(horizontalAnglePosition, verticalAnglePosition, lightAttenuation);
411409
}
412410
}
413411

414412
return textureBuffer;
415413
}
416414

417-
NativeArray<Color32> BuildTypeCGnomonicTexture(float coneAngle, int size, bool applyLightAttenuation)
415+
NativeArray<Color> BuildTypeCGnomonicTexture(float coneAngle, int size, bool applyLightAttenuation)
418416
{
419417
float limitUV = Mathf.Tan(0.5f * coneAngle * Mathf.Deg2Rad);
420418
float stepUV = (2 * limitUV) / (size - 3);
421419

422-
var textureBuffer = new NativeArray<Color32>(size * size, Allocator.Temp, NativeArrayOptions.ClearMemory);
420+
var textureBuffer = new NativeArray<Color>(size * size, Allocator.Temp, NativeArrayOptions.ClearMemory);
423421

424422
// Leave a one-pixel black border around the texture to avoid cookie spilling.
425423
for (int y = 1; y < size - 1; y++)
426424
{
427-
var slice = new NativeSlice<Color32>(textureBuffer, y * size, size);
425+
var slice = new NativeSlice<Color>(textureBuffer, y * size, size);
428426

429427
float v = (y - 1) * stepUV - limitUV;
430428

@@ -443,8 +441,7 @@ NativeArray<Color32> BuildTypeCGnomonicTexture(float coneAngle, int size, bool a
443441
// Factor in the light attenuation further from the texture center.
444442
float lightAttenuation = applyLightAttenuation ? (uvLength * uvLength + 1) : 1f;
445443

446-
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation));
447-
slice[x] = new Color32(value, value, value, value);
444+
slice[x] = ComputePixelColor(horizontalAnglePosition, verticalAnglePosition, lightAttenuation);
448445
}
449446
}
450447

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
area: Post-processing and UI Features

0 commit comments

Comments
 (0)