Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

"Property (influences) at kernel index (0) is not set"

Discussion in '2018.2 Beta' started by laurentlavigne, Jul 5, 2018.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,335
    Did something change regarding compute shader from 2017.3 to this new version of Unity? Maybe something now requires output to be initialized?
    Here is the code:

    Code (CSharp):
    1.  
    2. #pragma kernel CSMain
    3.  
    4. RWStructuredBuffer<float> influences;
    5.  
    6. StructuredBuffer<int> emitters;
    7. StructuredBuffer<int> obstacles;
    8.  
    9. [numthreads(8,8,1)]
    10. void CSMain (uint3 id : SV_DispatchThreadID)
    11. {
    12.     influences[id.x] = emitters[id.x] * float4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0);
    13. }
    14.  
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SimulationOnComputeShader : Simulation {
    6.     public ComputeShader cs;
    7.     public int size = 100;
    8.     void Update()
    9.     {
    10.         float[] values = new float[size * size];
    11.         Texture2D tex = new Texture2D(size, size);
    12.         ComputeBuffer buffer = new ComputeBuffer(values.Length, 4);
    13.         Vector2 pos;
    14.         foreach (var em in emitters)
    15.         {
    16.             pos = World2Grid(em.transform.position);
    17.             values[(int)pos.x + (int)pos.y*size] = em.value;
    18.         }
    19.         buffer.SetData(values);
    20.         int kernel = cs.FindKernel("CSMain");
    21.         cs.SetBuffer(kernel, "emitters", buffer);
    22.  
    23.         values = new float[size * size];
    24.         foreach (var ob in obstacles)
    25.         {
    26.             pos = World2Grid(ob.transform.position);
    27.             values[(int)pos.x + (int)pos.y * size] = 1;
    28.         }
    29.         buffer.SetData(values);
    30.         cs.SetBuffer(kernel, "obstacles", buffer);
    31.  
    32.         cs.Dispatch(kernel, size, size,1);
    33.  
    34.     }
    35.     public Vector2 World2Grid(Vector3 pos)
    36.     {
    37.         return new Vector2(gridBounds.max.x - pos.x, pos.z - gridBounds.min.z) * size / gridBounds.size.z;
    38.     }
    39. }
    40.