#pragma kernel CSMain #include "UnityCG.cginc" #define WORK_GROUP_SIZE 1024 struct Vertex { float3 position; float3 normal; //float4 color; //float2 uv; //float2 uv2; float4 tangent; }; CBUFFER_START(Variables) int index; int count; float4x4 model_matrix; CBUFFER_END RWStructuredBuffer home_buffer; RWStructuredBuffer home_velocity_buffer; RWStructuredBuffer vertex_buffer; [numthreads(WORK_GROUP_SIZE, 1, 1)] void CSMain(uint3 id : SV_DispatchThreadID) { uint offset = (uint)index; if (id.x < offset || id.x >= offset + count) return; float4 pos = float4(vertex_buffer[id.x - offset].position, 1); pos = mul(model_matrix, pos); float3 last_pos = home_buffer[id.x].xyz; float3 vel = length(last_pos) == 0.0f ? float3(0, 0, 0) : pos.xyz - last_pos; home_velocity_buffer[id.x] = float4(vel, 1.0f); home_buffer[id.x] = pos; }