Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

#include in compute shader doesn't work

Discussion in 'Editor & General Support' started by Shorinji, Feb 6, 2014.

Thread Status:
Not open for further replies.
  1. Shorinji

    Shorinji

    Joined:
    Oct 8, 2012
    Posts:
    21
    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
    Code (csharp):
    1. #include "Test1.compute"
    2.  
    3. #pragma kernel CSMain
    4. [numthreads(blockWidth,blockHeight,1)]
    5. void CSMain (uint3 id : SV_DispatchThreadID)
    6. {
    7. }
    8.  
    Test1.compute
    Code (csharp):
    1. #define blockWidth 32
    2. #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.
     
  2. Shorinji

    Shorinji

    Joined:
    Oct 8, 2012
    Posts:
    21
    Bump.
     
  3. Shorinji

    Shorinji

    Joined:
    Oct 8, 2012
    Posts:
    21
  4. Shorinji

    Shorinji

    Joined:
    Oct 8, 2012
    Posts:
    21
    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.
     
  5. surtweig

    surtweig

    Joined:
    Mar 23, 2013
    Posts:
    1
  6. kpo

    kpo

    Joined:
    Jun 8, 2014
    Posts:
    1
    A complete shot in the dark but don't all compute shaders need to start with "#pragma kernel"?
     
    spalmer likes this.
  7. spalmer

    spalmer

    Joined:
    Jun 3, 2014
    Posts:
    6
    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. :)
     
  8. TehWardy

    TehWardy

    Joined:
    Mar 20, 2013
    Posts:
    38
    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.
     
  9. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sorry this has been unanswered so long, I will poke some top people far brighter than I to take a look! :D
     
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Could you report this as a bug please. I've been told it possibly might be.
     
  11. TehWardy

    TehWardy

    Joined:
    Mar 20, 2013
    Posts:
    38
  12. UnrealTati

    UnrealTati

    Joined:
    Aug 18, 2017
    Posts:
    5
    I found backslashes work, instead of fwd slashes. why?

    Not Assets/..../Myinclude.cginc

    but

    Assets\....\Myinclude.cginc.
     
  13. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    611
    ...this thread is 5 years old.
     
  14. UnityMaru

    UnityMaru

    Community Engagement Manager Unity Technologies

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Yikes, please don't necro.
     
Thread Status:
Not open for further replies.