@@ -67,16 +67,12 @@ private GraphicsBuffer
67
67
68
68
internal VFXRuntimeResources m_RuntimeResources ;
69
69
70
- private struct Triangle
71
- {
72
- Vector3 a , b , c ;
73
- }
74
-
75
70
/// <summary>
76
71
/// Returns the texture containing the baked Signed Distance Field
77
72
/// </summary>
78
73
public RenderTexture SdfTexture => m_DistanceTexture ;
79
- private void InitMeshFromList ( List < Mesh > meshes , List < Matrix4x4 > transforms )
74
+
75
+ private static Mesh InitMeshFromList ( List < Mesh > meshes , List < Matrix4x4 > transforms )
80
76
{
81
77
int nMeshes = meshes . Count ;
82
78
if ( nMeshes != transforms . Count )
@@ -94,9 +90,11 @@ private void InitMeshFromList(List<Mesh> meshes, List<Matrix4x4> transforms)
94
90
combine . Add ( comb ) ;
95
91
}
96
92
}
97
- m_Mesh = new Mesh ( ) ;
98
- m_Mesh . indexFormat = IndexFormat . UInt32 ;
99
- m_Mesh . CombineMeshes ( combine . ToArray ( ) ) ;
93
+
94
+ Mesh outMesh = new Mesh ( ) ;
95
+ outMesh . indexFormat = IndexFormat . UInt32 ;
96
+ outMesh . CombineMeshes ( combine . ToArray ( ) ) ;
97
+ return outMesh ;
100
98
}
101
99
102
100
private void InitCommandBuffer ( )
@@ -184,30 +182,23 @@ public Vector3 GetActualBoxSize()
184
182
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
185
183
/// <param name="sdfOffset">The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny.</param>
186
184
/// <param name="cmd">The CommandBuffer on which the baking process will be added.</param>
187
- public MeshToSDFBaker ( Vector3 sizeBox , Vector3 center , int maxRes , Mesh mesh , int signPassesCount = 1 , float threshold = 0.5f , float sdfOffset = 0.0f , CommandBuffer cmd = null )
185
+ public MeshToSDFBaker ( Vector3 sizeBox ,
186
+ Vector3 center ,
187
+ int maxRes ,
188
+ Mesh mesh ,
189
+ int signPassesCount = 1 ,
190
+ float threshold = 0.5f ,
191
+ float sdfOffset = 0.0f ,
192
+ CommandBuffer cmd = null )
188
193
{
189
- m_SignPassesCount = signPassesCount ;
190
- if ( m_SignPassesCount >= 20 )
191
- {
192
- throw new ArgumentException ( "The signPassCount argument should be smaller than 20." ) ;
193
- }
194
- m_InOutThreshold = threshold ;
195
- m_RuntimeResources = VFXRuntimeResources . runtimeResources ;
196
- if ( m_RuntimeResources == null )
197
- {
198
- throw new InvalidOperationException ( "VFX Runtime Resources could not be loaded." ) ;
199
- }
200
-
201
- m_SdfOffset = sdfOffset ;
202
- m_Center = center ;
203
- m_SizeBox = sizeBox ;
194
+ LoadRuntimeResources ( ) ;
204
195
m_Mesh = mesh ;
205
- m_maxResolution = maxRes ;
206
196
if ( cmd != null )
207
197
{
208
198
m_Cmd = cmd ;
209
199
m_OwnsCommandBuffer = false ;
210
200
}
201
+ SetParameters ( sizeBox , center , maxRes , signPassesCount , threshold , sdfOffset ) ;
211
202
Init ( ) ;
212
203
}
213
204
@@ -223,26 +214,17 @@ public MeshToSDFBaker(Vector3 sizeBox, Vector3 center, int maxRes, Mesh mesh, in
223
214
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
224
215
/// <param name="sdfOffset">The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny.</param>
225
216
/// <param name="cmd">The CommandBuffer on which the baking process will be added.</param>
226
- public MeshToSDFBaker ( Vector3 sizeBox , Vector3 center , int maxRes , List < Mesh > meshes , List < Matrix4x4 > transforms , int signPassesCount = 1 , float threshold = 0.5f , float sdfOffset = 0.0f , CommandBuffer cmd = null )
217
+ public MeshToSDFBaker ( Vector3 sizeBox ,
218
+ Vector3 center ,
219
+ int maxRes ,
220
+ List < Mesh > meshes ,
221
+ List < Matrix4x4 > transforms ,
222
+ int signPassesCount = 1 ,
223
+ float threshold = 0.5f ,
224
+ float sdfOffset = 0.0f ,
225
+ CommandBuffer cmd = null ) :
226
+ this ( sizeBox , center , maxRes , InitMeshFromList ( meshes , transforms ) , signPassesCount , threshold , sdfOffset , cmd )
227
227
{
228
- m_RuntimeResources = VFXRuntimeResources . runtimeResources ;
229
- if ( m_RuntimeResources == null )
230
- {
231
- throw new InvalidOperationException ( "VFX Runtime Resources could not be loaded." ) ;
232
- }
233
- InitMeshFromList ( meshes , transforms ) ;
234
- m_SdfOffset = sdfOffset ;
235
- m_Center = center ;
236
- m_SizeBox = sizeBox ;
237
- m_maxResolution = maxRes ;
238
- if ( cmd != null )
239
- {
240
- m_Cmd = cmd ;
241
- m_OwnsCommandBuffer = false ;
242
- }
243
- m_SignPassesCount = signPassesCount ;
244
- m_InOutThreshold = threshold ;
245
- Init ( ) ;
246
228
}
247
229
248
230
/// <summary>
@@ -266,15 +248,16 @@ public MeshToSDFBaker(Vector3 sizeBox, Vector3 center, int maxRes, List<Mesh> me
266
248
/// <param name="signPassesCount">The number of refinement passes on the sign of the SDF. This should stay below 20.</param>
267
249
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
268
250
/// <param name="sdfOffset">The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny.</param>
269
- public void Reinit ( Vector3 sizeBox , Vector3 center , int maxRes , Mesh mesh , int signPassesCount = 1 , float threshold = 0.5f , float sdfOffset = 0.0f )
251
+ public void Reinit ( Vector3 sizeBox ,
252
+ Vector3 center ,
253
+ int maxRes ,
254
+ Mesh mesh ,
255
+ int signPassesCount = 1 ,
256
+ float threshold = 0.5f ,
257
+ float sdfOffset = 0.0f )
270
258
{
271
259
m_Mesh = mesh ;
272
- m_Center = center ;
273
- m_SizeBox = sizeBox ;
274
- m_maxResolution = maxRes ;
275
- m_SignPassesCount = signPassesCount ;
276
- m_InOutThreshold = threshold ;
277
- m_SdfOffset = sdfOffset ;
260
+ SetParameters ( sizeBox , center , maxRes , signPassesCount , threshold , sdfOffset ) ;
278
261
Init ( ) ;
279
262
}
280
263
@@ -289,16 +272,43 @@ public void Reinit(Vector3 sizeBox, Vector3 center, int maxRes, Mesh mesh, int s
289
272
/// <param name="signPassesCount">The number of refinement passes on the sign of the SDF. This should stay below 20.</param>
290
273
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
291
274
/// <param name="sdfOffset">The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny.</param>
292
- public void Reinit ( Vector3 sizeBox , Vector3 center , int maxRes , List < Mesh > meshes , List < Matrix4x4 > transforms , int signPassesCount = 1 , float threshold = 0.5f , float sdfOffset = 0.0f )
275
+ public void Reinit ( Vector3 sizeBox ,
276
+ Vector3 center ,
277
+ int maxRes ,
278
+ List < Mesh > meshes ,
279
+ List < Matrix4x4 > transforms ,
280
+ int signPassesCount = 1 ,
281
+ float threshold = 0.5f ,
282
+ float sdfOffset = 0.0f )
293
283
{
294
- InitMeshFromList ( meshes , transforms ) ;
295
- m_Center = center ;
296
- m_SizeBox = sizeBox ;
297
- m_maxResolution = maxRes ;
284
+ Reinit ( sizeBox , center , maxRes , InitMeshFromList ( meshes , transforms ) , signPassesCount , threshold , sdfOffset ) ;
285
+ }
286
+
287
+ private void SetParameters ( Vector3 sizeBox , Vector3 center , int maxRes , int signPassesCount , float threshold , float sdfOffset )
288
+ {
289
+ if ( m_SignPassesCount >= 20 )
290
+ {
291
+ throw new ArgumentException ( "The signPassCount argument should be smaller than 20." ) ;
292
+ }
298
293
m_SignPassesCount = signPassesCount ;
299
294
m_InOutThreshold = threshold ;
300
295
m_SdfOffset = sdfOffset ;
301
- Init ( ) ;
296
+ m_Center = center ;
297
+ m_SizeBox = sizeBox ;
298
+ m_maxResolution = maxRes ;
299
+ }
300
+ private void LoadRuntimeResources ( )
301
+ {
302
+ if ( SystemInfo . graphicsDeviceType == GraphicsDeviceType . OpenGLES3 )
303
+ {
304
+ Debug . LogWarning ( "MeshToSDFBaker compute shaders are not supported on OpenGLES3" ) ;
305
+ }
306
+
307
+ m_RuntimeResources = VFXRuntimeResources . runtimeResources ;
308
+ if ( m_RuntimeResources == null )
309
+ {
310
+ throw new InvalidOperationException ( "VFX Runtime Resources could not be loaded." ) ;
311
+ }
302
312
}
303
313
304
314
void InitTextures ( )
@@ -707,6 +717,10 @@ void SignPass()
707
717
/// </summary>
708
718
public void BakeSDF ( )
709
719
{
720
+ if ( SystemInfo . graphicsDeviceType == GraphicsDeviceType . OpenGLES3 )
721
+ {
722
+ throw new NotSupportedException ( "MeshToSDFBaker compute shaders are not supported on OpenGLES3" ) ;
723
+ }
710
724
m_Cmd . BeginSample ( "BakeSDF" ) ;
711
725
UpdateCameras ( ) ;
712
726
m_Cmd . SetComputeIntParams ( m_computeShader , ShaderProperties . size , m_Dimensions ) ;
0 commit comments