Files
beyond/Assets/testy/ParticleSDFTest/MeshToSDF/computeTest.compute
2024-11-20 15:21:28 +01:00

35 lines
997 B
Plaintext

// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain
#pragma kernel DebugSphere
// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
//RWTexture2D<half4> Result;
RWTexture3D<float> Result;
int dispatchCubeSide;
[numthreads(8,8,8)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
// TODO: insert actual code here!
//Result[id.xy] = half4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0);
//Result[id.xy] = float4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0);
Result[id.xyz] = float(!(id.x & id.y & id.z));
}
[numthreads(8, 8, 8)]
void DebugSphere(uint3 id : SV_DispatchThreadID) {
float3 p = half3(id)/half3(dispatchCubeSide, dispatchCubeSide, dispatchCubeSide);
p *= 2; p -= 1;
float d = length(p) - 0.5;
if (abs(d) <= 0.05f) {
//Debug[id] = float4(1.0f, 1.0f, 1.0f, 1.0f);
Result[id] = 0.5f;
}
else {
//Debug[id] = float4(0.0f, 0.0f, 0.0f, 0.0f);
Result[id] = 0.5f;
}
}