eidosmontreal / unreal-vdb

This repo is a non-official Unreal plugin that can read OpenVDB and NanoVDB files in Unreal.
Apache License 2.0
690 stars 109 forks source link

VdbFogVolume compile failures #93

Closed parnic-sks closed 1 year ago

parnic-sks commented 1 year ago

We are on UE 5.2.1 using release 0.6.10 (SparseVolumetrics_ue5.2.1_0.6.10.zip). Attempting to cook our project results in cook warnings due to materials that are failing to compile due to errors in VdbFogVolume. The full cook output is:

LogInit: Display: LogShaderCompilers: Warning: Failed to compile Material /SparseVolumetrics/Materials/M_VDB_Lit.M_VDB_Lit for platform PCD3D_SM5, Default Material will be used in game.
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(281,108-118):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(380,35-46):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(641,40-51):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(641,64-75):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(743,99-135):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(744,47-58):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(942,45-56):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(942,69-80):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(1136,37-160):  warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(449,17-24):  err0r X3511: unable to unroll loop, loop does not appear to terminate in a timely manner (26 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(208,5-12):  err0r X3511: forced to unroll loop, but unrolling failed.

LogInit: Display: LogShaderCompilers: Warning: Failed to compile Material /Engine/EngineSky/VolumetricClouds/m_SimpleVolumetricCloud.m_SimpleVolumetricCloud for platform PCD3D_SM5, Default Material will be used in game.
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(597,111-121):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(793,35-46):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(4730,31-42):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(4972,99-135):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(4973,47-58):  warning X3577: value cannot be NaN, isnan() may not be necessary.  /Gis may force isnan() to be performed
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(8479,38-162):  warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(1277,17-24):  err0r X3511: unable to unroll loop, loop does not appear to terminate in a timely manner (4 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number
  D:\Plugin\VdbVolume\Private\VdbFogVolume.usf.intermediate.hlsl(524,5-12):  err0r X3511: forced to unroll loop, but unrolling failed.

LogInit: Display: LogMaterial: Warning: Cooking a material resource (in M_VDB_Lit hierarchy) that doesn't have a valid ShaderMap! Shadermap pointer is null.
LogInit: Display: LogMaterial: Warning: Cooking a material resource (in m_SimpleVolumetricCloud hierarchy) that doesn't have a valid ShaderMap! Shadermap pointer is null.

Before I go diving much deeper into investigating this on our end, are the "unable to unroll loop" errors something that has been seen before that we're simply doing wrong or is this something unique to us in some way? This can be reproduced by using the Cook Content option in the editor and looking at the warning summary once it finishes.

We had the same problem with release 0.6.8 and were hoping that 0.6.10 would fix it, but it didn't. I realize this repo currently says it's archived, but thought I'd see if you could point us in the right direction.

thilamb commented 1 year ago

Hi there,

I've tried to fix this issue many times but it keeps coming back from time to time.

I'm concerned about this warning:

warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop

This breaks the unroll loop of the shader, creating the compilation error later. Is this shader the vanilla VDB Material ? Or are you using a custom Material ? If it is you should not have any gradient functions in it.

alexstachelek commented 1 year ago

Prefacing each for-loop in VdbFogVolume.usf with [loop] I've found will suppress the error, but I'm judging by your comment above that this may not be the correct way to address this. Tried to use [unroll(x)] first but need a compile-time constant to do so, and it looks like the number of iterations is dynamic.

parnic-sks commented 1 year ago

Is this shader the vanilla VDB Material ? Or are you using a custom Material ? If it is you should not have any gradient functions in it.

We haven't made any changes to the shaders or materials that come with the plugin, so it's vanilla.

thilamb commented 1 year ago

Yes, adding [loop] (or LOOP with Unreal's macros) before the two for loops usually helps.

I was convinced I had done it already but apparently I only did it in VdbPrincipled.usf (the shader equivalent of the other mode).

Can you try adding LOOP on line 121 and 300 ? Let us know if it helps.

thilamb commented 1 year ago

If it helps anybody, the USE_FORCE_TEXTURE_MIP 1 macro (added from CPP) is supposed to disable all gradient instruction from texture samples.

That's why I'm worried you're still getting a warning saying there are still gradient instructions. It should not happen.

Can you try also adding #define FORCED_TEXTURE_MIP 0.0f before #include "/Engine/Private/Common.ush" ?

alexstachelek commented 1 year ago

Will do, and thank you for following up so quickly with this help.

parnic-sks commented 1 year ago

Adding #define FORCED_TEXTURE_MIP 0.0f in the usf did not fix the problem. Adding the two [loop] prefaces on the for loops does fix the cook errors/warnings.

thilamb commented 1 year ago

Great ! Thanks for the feedback.

I've now updated the file.

Cheers