2

I am trying to do a Sum of absolute difference within my shader and write back the single result back to a uniform float in a in unity. In the shader I have 2 geometries with the same number of vertices that map one to one.

            // substract vertices
            float norm = 10;
            float error=infereCrater.vertex.y-v.vertex.y;
            error = error*error*norm;
            o.debugColor = float3(error,1-error ,0.0f);
            //////
            o.posWorld =mul(_Object2World,v.vertex);
            o.normalWorld = normalize(mul(float4(v.normal,0.0),_World2Object).xyz);
            o.tangentWorld = normalize(mul(float4(v.tangent,0.0),_World2Object).xyz);
            o.binormalWorld = cross(o.normalWorld,o.tangentWorld);
            o.tex = v.texcoord;
            o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
            TRANSFER_VERTEX_TO_FRAGMENT(o);
            return o;
        }

I am available to calculate the error for each individual vertex and change the color of the surface based on the difference. I hit a road block where I don't know how to sync all the threads and start adding up the values.

Is there a way to call another vertex shader after the first one is done?

How can the vertex shader read the values of adjacent vertex to it? (don't think its possible because in local memory of thread)

Or its possible to have a global array, to store the difference values, copy this to the CPU (which I don't want because of latency) and add them in the CPU?

I don't want to use compute shader because I am not in Windows

Steven
  • 166,672
  • 24
  • 332
  • 435
Savashito
  • 29
  • 1

0 Answers0