Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    186
    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:
    1
    Thanks, this helped a lot! I was searching somewhere completely different. ^^'
     
unityunity