I copied over my MeshToSDF script from the demo project over to this one. Grabbing the MeshFilter from a separate script seems to be what fixed my SDF Baking. Or maybe it was grabbing the MeshFilter directly from the component. Who cares. I’ve moved on and it’s working now! I also reverted my VFX Graph package back to the original Unity version. Oh, and I changed the scene numbers, since Brightness Testing was a success and Metaballs is getting there. Things are getting cleaner.
I’ve been attempting to optimize the compute shader with ChatGPT’s help. I recalled learning in a YouTube video that using conditional logic in a compute shader is unoptimal due to GPU architecture, so I tried seeing if it would rewrite some condition-based functions for me.
int findIndex(Values edgeValue) {
int cubeIndex = 0;
if (edgeValue.edge0Val > threshold) {
cubeIndex += 1;
}
if (edgeValue.edge1Val > threshold) {
cubeIndex += 2;
}
if (edgeValue.edge2Val > threshold) {
cubeIndex += 4;
}
if (edgeValue.edge3Val > threshold) {
cubeIndex += 8;
}
if (edgeValue.edge4Val > threshold) {
cubeIndex += 16;
}
if (edgeValue.edge5Val > threshold) {
cubeIndex += 32;
}
if (edgeValue.edge6Val > threshold) {
cubeIndex += 64;
}
if (edgeValue.edge7Val > threshold) {
cubeIndex += 128;
}
return cubeIndex;
}
int findIndex(Values edgeValue) {
int cubeIndex = 0;
cubeIndex += (edgeValue.edge0Val > threshold) ? 1 : 0;
cubeIndex += (edgeValue.edge1Val > threshold) ? 2 : 0;
cubeIndex += (edgeValue.edge2Val > threshold) ? 4 : 0;
cubeIndex += (edgeValue.edge3Val > threshold) ? 8 : 0;
cubeIndex += (edgeValue.edge4Val > threshold) ? 16 : 0;
cubeIndex += (edgeValue.edge5Val > threshold) ? 32 : 0;
cubeIndex += (edgeValue.edge6Val > threshold) ? 64 : 0;
cubeIndex += (edgeValue.edge7Val > threshold) ? 128 : 0;
return cubeIndex;
}
Pretty cool huh?! Still, I doubt that fixes much in terms of speed optimization. Instead, I turned to Claude 3 for assistance with this warning:
After making an account, I explained my situation and attached the compute shader. I like that Claude lets me directly upload files. It didn’t output any code for me, but did recommend I optimize a specific function.
Since Claude didn’t write me any code, I pasted evaluateFieldFunction() into ChatGPT and sought its council. By this point, I was getting lazy. I find that when I rely too heavily on its answers while coding above my head, I stop thinking for myself. And, ChatGPT still makes mistakes. Look at this:
ChatGPT apologizing to me for “oversight”. I need to get back to the basics of research and figure out how to optimize my metaballs container for real.