Search Unity

IndexOutOfRangeException: Invalid kernelIndex (0) passed, must be non-negative less than 0.

Discussion in 'Shaders' started by blane1257, May 18, 2020.

  1. blane1257

    blane1257

    Joined:
    Dec 5, 2019
    Posts:
    3
    I ran a google search for this error and got exactly 5 results, none of which were particularly helpful.

    I'm new to shaders, working through this tutorial on Unity 2019.3.5f1, and got the error when replacing this
    Code (CSharp):
    1. //Write some colors
    2. Result[id.xy] = float4(ray.direction * 0.5f + 0.5f, 1.0f);
    with this
    Code (CSharp):
    1. // Sample the skybox and write it
    2. float theta = acos(ray.direction.y) / -PI;
    3. float phi = atan2(ray.direction.x, -ray.direction.z) / -PI * 0.5f;
    4. Result[id.xy] = _SkyboxTexture.SampleLevel(sampler_SkyboxTexture, float2(phi, theta), 0);
    in the compute shader.

    One of the google results suggested that I could be indexing something with 0 elements, if that helps.
     
  2. Namey5

    Namey5

    Joined:
    Jul 5, 2013
    Posts:
    188
    This could be a number of things, although I would imagine that these lines are causing an error with the kernel, thus it cannot be 'found'. I would make sure you have defined PI and that you are actually passing the skybox texture into the shader as a start.
     
  3. JamesPElliman

    JamesPElliman

    Joined:
    Jan 8, 2020
    Posts:
    1
    I am assuming that you have fixed this issue now. For those that stubble upon the same error message as I did. Check the compute shader has compiled in the Unity editor. If not, the error may not appear in the console window but in the 'inspector' menu.

    I had a syntax error that stopped the shader from compiling leading to this message. There is no kernel at position '0' (shaders can have multiple kernels use an index to refer to them) in the shader specified because the shader has not been recognised in the first place.

    Hope this helps future readers.

    Thanks,
    James
     
  4. Crysaac

    Crysaac

    Joined:
    Nov 22, 2018
    Posts:
    2
    Thanks, this helped a lot! I was searching somewhere completely different. ^^'
     
  5. Wyndfall

    Wyndfall

    Joined:
    Dec 1, 2018
    Posts:
    2
    In relation to this tutorial, it probably just means that you have certain functions in the wrong order. Since HLSL requires you to define anything before using it, check that you aren't calling a function that hasn't yet been defined, causing the shader to not compile, and this error to appear.
     
  6. xXProtoXx

    xXProtoXx

    Joined:
    Nov 21, 2020
    Posts:
    2

    Where exactly was that syntax error? I know nothing about shader languages, and have run into the same issue as OP, on likely the same project (following a tutorial found here: http://blog.three-eyed-games.com/2018/05/03/gpu-ray-tracing-in-unity-part-1/). I haven't been able to figure out what you were talking about in your post, so this problem remains a problem for me until you elaborate. Thanks in advance for explaining.
     
    smortBlob likes this.
  7. MintTree117

    MintTree117

    Joined:
    Dec 2, 2018
    Posts:
    340
    Thanks.