Skip to content

Commit 2c07076

Browse files
ludovic-theobaldEvergreen
authored andcommitted
[VFX][Fix] Disable SDF Baker for GLES3
This PR prevents shaders used in the SDF Baker to compile on OpenGLES3. They were not supported nor tested on this platform. This avoid getting warnings like `Shader warning in 'GenSdfRayMap': HLSLcc: The resource 'rayMap' uses an unsupported type/format for read/write access at kernel RayMapScanX (on gles3)`. Warnings on **other platforms**, mentionned in this bug (https://jira.unity3d.com/browse/UUM-53994) are already fixed. Warnings on GLES3 about buffer count are not fixed, and will not be fixed.
1 parent 7bb7776 commit 2c07076

File tree

3 files changed

+74
-60
lines changed

3 files changed

+74
-60
lines changed

Packages/com.unity.visualeffectgraph/Editor/Utilities/SDF/BakeTool/SDFBakeTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ protected void OnGUI()
213213
}
214214
EditorGUIUtility.wideMode = prevWideMode;
215215

216-
if (mesh != null)
216+
using (new EditorGUI.DisabledScope(mesh == null))
217217
{
218218
EditorGUILayout.BeginHorizontal();
219219
EditorGUI.BeginChangeCheck();

Packages/com.unity.visualeffectgraph/Runtime/Utilities/SDF/MeshToSDFBaker.cs

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,12 @@ private GraphicsBuffer
6767

6868
internal VFXRuntimeResources m_RuntimeResources;
6969

70-
private struct Triangle
71-
{
72-
Vector3 a, b, c;
73-
}
74-
7570
/// <summary>
7671
/// Returns the texture containing the baked Signed Distance Field
7772
/// </summary>
7873
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)
8076
{
8177
int nMeshes = meshes.Count;
8278
if (nMeshes != transforms.Count)
@@ -94,9 +90,11 @@ private void InitMeshFromList(List<Mesh> meshes, List<Matrix4x4> transforms)
9490
combine.Add(comb);
9591
}
9692
}
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;
10098
}
10199

102100
private void InitCommandBuffer()
@@ -184,30 +182,23 @@ public Vector3 GetActualBoxSize()
184182
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
185183
/// <param name="sdfOffset">The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny.</param>
186184
/// <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)
188193
{
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();
204195
m_Mesh = mesh;
205-
m_maxResolution = maxRes;
206196
if (cmd != null)
207197
{
208198
m_Cmd = cmd;
209199
m_OwnsCommandBuffer = false;
210200
}
201+
SetParameters(sizeBox, center, maxRes, signPassesCount, threshold, sdfOffset);
211202
Init();
212203
}
213204

@@ -223,26 +214,17 @@ public MeshToSDFBaker(Vector3 sizeBox, Vector3 center, int maxRes, Mesh mesh, in
223214
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
224215
/// <param name="sdfOffset">The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny.</param>
225216
/// <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)
227227
{
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();
246228
}
247229

248230
/// <summary>
@@ -266,15 +248,16 @@ public MeshToSDFBaker(Vector3 sizeBox, Vector3 center, int maxRes, List<Mesh> me
266248
/// <param name="signPassesCount">The number of refinement passes on the sign of the SDF. This should stay below 20.</param>
267249
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
268250
/// <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)
270258
{
271259
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);
278261
Init();
279262
}
280263

@@ -289,16 +272,43 @@ public void Reinit(Vector3 sizeBox, Vector3 center, int maxRes, Mesh mesh, int s
289272
/// <param name="signPassesCount">The number of refinement passes on the sign of the SDF. This should stay below 20.</param>
290273
/// <param name="threshold">The threshold controlling which voxels will be considered inside or outside of the surface.</param>
291274
/// <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)
293283
{
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+
}
298293
m_SignPassesCount = signPassesCount;
299294
m_InOutThreshold = threshold;
300295
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+
}
302312
}
303313

304314
void InitTextures()
@@ -707,6 +717,10 @@ void SignPass()
707717
/// </summary>
708718
public void BakeSDF()
709719
{
720+
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3)
721+
{
722+
throw new NotSupportedException("MeshToSDFBaker compute shaders are not supported on OpenGLES3");
723+
}
710724
m_Cmd.BeginSample("BakeSDF");
711725
UpdateCameras();
712726
m_Cmd.SetComputeIntParams(m_computeShader, ShaderProperties.size, m_Dimensions);

Packages/com.unity.visualeffectgraph/Shaders/SDFBaker/GenSdfRayMap.compute

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#pragma kernel ChooseDirectionTriangleOnly
2121
#pragma kernel SurfaceClosing
2222

23-
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch glcore gles3 webgpu
23+
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch glcore webgpu
2424

2525
#include "Packages/com.unity.visualeffectgraph/Shaders/SDFBaker/SdfUtils.hlsl"
2626

0 commit comments

Comments
 (0)