Linked Questions

Popular Questions

Unity Compute Shader Adding to Structured Buffer

Asked by At

I am trying to implement a Hough line transform using compute shaders in unity. I have successfully done it on CPU and am transferring it to the GPU. I am using a RWStructuredBuffer<uint> for the accumulator.

RWStructuredBuffer<uint> accumulator;

[numthreads (8, 8, 1)]
void AngleCalculator (uint3 id : SV_DispatchThreadID) {
    if (textureIn[id.xy].r > 0) { // Check if the pixel is not black
        for (uint angle = 180; angle < 360; angle++) {
            accumulator[(angle - 180) + 
                ((id.x * cos (angle * ((2.0 * 3.1415) / 360.0))) - 
                 (id.y * sin (angle * ((2.0 * 3.1415) / 360.0))) + offset) * 180]++;
    }
}

I dispatch the kernal with computeShader.Dispatch(angleKernal, width / 8, height / 8, 1); where width and height are a power of 2 (64).

It is supposed to store the result in the accumulator but it doesn't produce the same results as on CPU

Related Questions