I am trying to follow this excellent Coding Adventure: https://www.youtube.com/watch?v=lctXaT9pxA0 in order to get a very simple mesh deformation on a mesh using a compute shader.
I'm getting an error that reads:
Compute shader (NewComputeShader): Property (vertices) at kernel index (0) is not set UnityEngine.ComputeShader:Dispatch(Int32, Int32, Int32, Int32) MoonShader:runShader() (at Assets/MoonShader.cs:27) MoonShader:Update() (at Assets/MoonShader.cs:15)
I'm calling runShader() in Update (maybe that's a terrible idea, but I don't think it's contributing to this specific problem yet).
Do I need to somehow pass my mesh's vertices into StructuredBuffer<float3> vertices;
? If so, how am I supposed to do that?
This is the call to the compute shader in my .cs file.
void runShader() {
int kernelHandle = computeShader.FindKernel("CSMain");
computeShader.Dispatch(kernelHandle, 512, 1, 1); //this is the line it appears to be complaining about
}
This is my .compute file.
#pragma kernel CSMain
StructuredBuffer<float3> vertices;
RWStructuredBuffer<float> heights;
uint numVertices;
float testValue = 20;
[numthreads(512,1,1)]
void CSMain (uint id : SV_DispatchThreadID) {
if(id >= numVertices) {
} else {
float3 vertexPosition = vertices[id];
heights[id] = 1 + sin(vertexPosition.y * testValue) * 0.05;
}
}
Link to repo if it's helpful: https://github.com/glenpierce/proceduralPlanets