@@ -9,7 +9,7 @@ namespace Genesis.Editor {
9
9
public static class DepthSkyboxPrefabUtility {
10
10
11
11
/// <summary>
12
- /// Imput given png fileb , generates depth and creates a prefab for a DepthSkybox.
12
+ /// Given an input png file , generates depth and creates a prefab for a DepthSkybox.
13
13
/// </summary>
14
14
public static void CreateSkyboxAsset ( string pngFilePath ) {
15
15
string name = Path . GetFileNameWithoutExtension ( pngFilePath ) ;
@@ -18,8 +18,8 @@ public static void CreateSkyboxAsset(string pngFilePath) {
18
18
19
19
string pngTargetPath = Path . Combine ( assetPath , $ "{ name } _rgb.png") ;
20
20
Texture2D skybox = ImportImageFile ( pngFilePath , pngTargetPath ) ;
21
- GenerateDepth ( assetPath , name , skybox ) ;
22
- CreateSkyboxPrefab ( assetPath , name ) ;
21
+ var range = GenerateDepth ( assetPath , name , skybox ) ;
22
+ CreateSkyboxPrefab ( assetPath , name , range ) ;
23
23
}
24
24
25
25
/// <summary>
@@ -31,27 +31,31 @@ public static async Task CreateSkyboxAsset(string id, string name) {
31
31
32
32
string imageFile = Path . Combine ( assetPath , $ "{ name } _rgb.png") ;
33
33
Texture2D skybox = await DownloadSkyboxById ( imageFile , id ) ;
34
- GenerateDepth ( assetPath , name , skybox ) ;
35
- CreateSkyboxPrefab ( assetPath , name ) ;
34
+ var range = GenerateDepth ( assetPath , name , skybox ) ;
35
+ CreateSkyboxPrefab ( assetPath , name , range ) ;
36
36
}
37
37
38
- private static void GenerateDepth ( string assetPath , string name , Texture2D skybox ) {
38
+ private static Vector2 GenerateDepth ( string assetPath , string name , Texture2D skybox ) {
39
39
int progressId = Progress . Start ( "Generating depth texture" , "Generating a depth texture from skybox..." ) ;
40
40
41
41
DepthEstimator depthEstimator = new DepthEstimator ( ) ;
42
42
depthEstimator . GenerateDepth ( skybox ) ;
43
- var depthTexture = depthEstimator . GetNormalizedDepth ( ) ;
43
+ var depthTexture = depthEstimator . PostProcessDepth ( ) ;
44
44
45
45
string depthTextureFile = Path . Combine ( assetPath , $ "{ name } _depth.asset") ;
46
46
CreateAsset ( depthTexture , depthTextureFile ) ;
47
- AssetDatabase . SaveAssets ( ) ;
48
- AssetDatabase . Refresh ( ) ;
49
47
50
- // for some reason, saving out as exr or png and reimporting produces
48
+ // for some reason, saving out as exr or png and reimporting produces what looks like precision artifacts
51
49
//byte[] bytes = depthTexture.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat);
52
50
53
51
depthEstimator . Dispose ( ) ;
52
+
53
+ AssetDatabase . SaveAssets ( ) ;
54
+ AssetDatabase . Refresh ( ) ;
55
+
54
56
Progress . Remove ( progressId ) ;
57
+
58
+ return new Vector2 ( depthEstimator . MinDepth , depthEstimator . MaxDepth ) ;
55
59
}
56
60
57
61
/// <summary>
@@ -66,7 +70,9 @@ private static void CreateAsset(Object obj, string path) {
66
70
AssetDatabase . CreateAsset ( obj , path ) ;
67
71
}
68
72
69
- public static void CreateSkyboxPrefab ( string assetPath , string name ) {
73
+ public static void CreateSkyboxPrefab ( string assetPath , string name , Vector2 range ) {
74
+ int progressId = Progress . Start ( "Creating skybox assets" , "Your skybox assets are being created..." ) ;
75
+
70
76
GameObject skyboxPrefab = ( GameObject ) Resources . Load ( "Prefabs/DepthSkybox" ) ;
71
77
72
78
GameObject instance = ( GameObject ) PrefabUtility . InstantiatePrefab ( skyboxPrefab ) ;
@@ -82,6 +88,8 @@ public static void CreateSkyboxPrefab(string assetPath, string name) {
82
88
renderer . sharedMaterial = m ;
83
89
m . SetTexture ( "_MainTex" , skybox ) ;
84
90
m . SetTexture ( "_Depth" , skyboxDepth ) ;
91
+ m . SetFloat ( "_Min" , range . x ) ;
92
+ m . SetFloat ( "_Max" , range . y ) ;
85
93
86
94
string materialPath = Path . Combine ( assetPath , $ "{ name } _material.mat") ;
87
95
CreateAsset ( m , materialPath ) ;
@@ -93,8 +101,12 @@ public static void CreateSkyboxPrefab(string assetPath, string name) {
93
101
}
94
102
GameObject variant = PrefabUtility . SaveAsPrefabAsset ( instance , prefabPath ) ;
95
103
Object . DestroyImmediate ( instance ) ;
96
-
97
104
PrefabUtility . InstantiatePrefab ( variant ) ;
105
+
106
+ AssetDatabase . SaveAssets ( ) ;
107
+ AssetDatabase . Refresh ( ) ;
108
+
109
+ Progress . Remove ( progressId ) ;
98
110
}
99
111
100
112
/// <summary>
0 commit comments