#include in compute shader doesn't work

Hi,

I’m trying to #include a .compute in another .compute and it doesn’t work.

Here is a sample code of the issue:

Test0.compute

#include "Test1.compute"

#pragma kernel CSMain 
[numthreads(blockWidth,blockHeight,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
}

Test1.compute

#define blockWidth 32
#define blockHeight 16

I get the following error :
“Shader error in ‘Test0.compute’: Illegal character in shader file at line 1”

Could you please help me to solve this issue?
Thanks in advance.

Bump.

Bump

Bump.

Is anybody from Unity reading this forum? After paying more than 2k $ for my pro license, i would expect to get some support at some point… Unless i’m not in the correct forum. If that’s the case where should i post?

Thanks in advance.

Bump.

A complete shot in the dark but don’t all compute shaders need to start with “#pragma kernel”?

1 Like

You may have solved the original poster’s issue but there may be other problems with #include in compute shaders. For instance the directory search (#include folders) seems to work different for .compute shaders than .shader shaders. I’ve been trying to make a unified HLSL #include library for both and having a heck of a time. Had it working more or less by putting everything in the same folder in Unity 4, but in Unity 5 beta even that no longer works and that’s why I am here. :slight_smile:

Yup this still doesn’t work.

Its also worth noting that I tried as suggested elsewhere using a path relative to the unity project root for example …

#include “Assets/MyFolder/myinclude.compute”

then i figured it’s commonly accepted that cginc is a cg app inclusion that unity should be able to handle as documented in shader rendering threads so i thought i would rename the extension to see if if behaved differently …

#include “Assets/MyFolder/myinclude.cginc”

… maybe that’s part of the problem, are compute shaders not treated like normal shaders in the unity compilation pipeline?

I don’t expect a reply to this, but I hope someone at unity actually reads this and solves this problem as it seems to be a bug.

Sorry this has been unanswered so long, I will poke some top people far brighter than I to take a look! :smile:

Could you report this as a bug please. I’ve been told it possibly might be.

It’s already there but unable to vote on it because someone deemed it resolved …

I found backslashes work, instead of fwd slashes. why?

Not Assets/…/Myinclude.cginc
but
Assets.…\Myinclude.cginc.

…this thread is 5 years old.

Yikes, please don’t necro.